From: "David Hildenbrand (Arm)" <david@kernel.org>
To: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Christian König" <christian.koenig@amd.com>,
intel-xe@lists.freedesktop.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
Lorenzo Stoakes <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Hugh Dickins <hughd@google.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Brendan Jackman <jackmanb@google.com>,
Johannes Weiner <hannes@cmpxchg.org>, Zi Yan <ziy@nvidia.com>,
Huang Rui <ray.huang@amd.com>,
Matthew Auld <matthew.auld@intel.com>,
Matthew Brost <matthew.brost@intel.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
dri-devel@lists.freedesktop.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] mm/shmem: add shmem_insert_folio()
Date: Wed, 13 May 2026 13:36:43 +0200 [thread overview]
Message-ID: <d7cc273b-17a2-4b5f-af6a-0dc708c8cabf@kernel.org> (raw)
In-Reply-To: <c0b5b94dfb4d04a1319bfb110f326afd2c29d48b.camel@linux.intel.com>
On 5/13/26 12:37, Thomas Hellström wrote:
> On Wed, 2026-05-13 at 12:03 +0200, David Hildenbrand (Arm) wrote:
>> On 5/13/26 10:51, Thomas Hellström wrote:
>>>
>>> FWIW, the i915 driver which uses shmem "natively" uses a special
>>> mount
>>> here that gives back THPs.
>>>
>>>
>>> Currently the drivers that use shmem in this way use
>>> "mapping_set_unevictable()" as long as the object is bound to the
>>> GPU.
>>> Then shrinkers can unbind from GPU and revert that setting.
>>
>> Right, but mapping_set_unevictable() only affects folio_evictable() -
>> -reclaim
>> behavior. Not other properties (such as folio migration).
>
> Interesting. Does that imply that a shmem folio can be replaced
> underneath without additional measures? It looks like most DRM
> call sites imply that mapping_set_unevictable() pins underlying shmem
> folios
I don't think there is anything preventing folio migration. shmem implement the
migrate_folio() callback simply by wiring up migrate_folio().
However, any raised reference on a shmem folio would prevent migration. However,
taking longterm references on folios that are allocated as being movable (shmem
default) breaks CMA, memory hotunplug, compaction...
drm_gem_get_pages()/drm_gem_put_pages() seem to handle some part of that ... by
grabbing/putting references.
So if DRM actually might hold these references for a longer time, I suspect this
breaks CMA etc..
We have the memfd_pin_folios() interface that takes care of handling that
properly by only allowing longterm references if longterm references are
actually allowed -- and otherwise migrates pages to physical memory areas where
longterm pinning is allowed.
[...]
> x86 implementation is here:
> https://elixir.bootlin.com/linux/v7.1-rc3/source/arch/x86/mm/pat/set_memory.c#L2556
>
> TTM calls it here:
> https://elixir.bootlin.com/linux/v7.1-rc3/source/drivers/gpu/drm/ttm/ttm_pool.c#L249
>
Ah, the calls to set_pages_array_wc/set_pages_array_uc.
> And there are actually shmem helpers that do this as well, without
> pooling.
> https://elixir.bootlin.com/linux/v7.1-rc3/source/drivers/gpu/drm/drm_gem_shmem_helper.c#L212
Thanks for pointing me at them.
Right, after grabbing a reference, the folio is unmovable and we can modify the
directmap.
>
>
>>
>>> That's an
>>> extremely costly operation so TTM needs to pool such allocations.
>>> That's where using shmem natively becomes very ugly, because you
>>> can't
>>> really use a 1:1 mapping between shmem objects and DRM objects
>>> anymore.
>>
>> So you would require different caching attributes within a DRM
>> object?
>
> The way the TTM pools work are that there are separate pools for each
> allocation order and caching modes. That would essentially mean
> allocations from a single shmem object would be spread out across
> different pools, and we'd loose the 1:1 mapping between DRM objects and
> shmem objects.
Right.
>
> One alternative would be a single large sparse shmem object common for
> all DRM objects, with a range allocator, but that also got pretty ugly
> when I tried to implement that.
Does not sound too crazy, though.
>
> Finally, (and I think that might be what Christian was getting at as
> well) Without CONFIG_TRANSPARENT_HUGEPAGE, we'd only see order 0 shmem
> folios, right?
Right. Because large folios do not exist in such a world. So this is expected.
If you don't set CONFIG_TRANSPARENT_HUGEPAGE, expect the system to have bad
performance.
--
Cheers,
David
next prev parent reply other threads:[~2026-05-13 11:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 11:03 [PATCH 0/2] Insert instead of copy pages into shmem when shrinking Thomas Hellström
2026-05-12 11:03 ` [PATCH 1/2] mm/shmem: add shmem_insert_folio() Thomas Hellström
2026-05-12 11:07 ` David Hildenbrand (Arm)
2026-05-12 11:31 ` Thomas Hellström
2026-05-12 20:03 ` David Hildenbrand (Arm)
2026-05-13 7:47 ` Christian König
2026-05-13 8:31 ` Thomas Hellström
2026-05-13 9:30 ` David Hildenbrand (Arm)
2026-05-13 8:37 ` David Hildenbrand (Arm)
2026-05-13 8:51 ` Thomas Hellström
2026-05-13 10:03 ` David Hildenbrand (Arm)
2026-05-13 10:37 ` Thomas Hellström
2026-05-13 11:36 ` David Hildenbrand (Arm) [this message]
2026-05-13 11:54 ` Christian König
2026-05-12 11:03 ` [PATCH 2/2] drm/ttm: Use ttm_backup_insert_folio() for zero-copy swapout Thomas Hellström
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d7cc273b-17a2-4b5f-af6a-0dc708c8cabf@kernel.org \
--to=david@kernel.org \
--cc=airlied@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=jackmanb@google.com \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matthew.auld@intel.com \
--cc=matthew.brost@intel.com \
--cc=mhocko@suse.com \
--cc=mripard@kernel.org \
--cc=ray.huang@amd.com \
--cc=rppt@kernel.org \
--cc=simona@ffwll.ch \
--cc=surenb@google.com \
--cc=thomas.hellstrom@linux.intel.com \
--cc=tzimmermann@suse.de \
--cc=vbabka@kernel.org \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox