From: "Christian König" <christian.koenig@amd.com>
To: Matthew Brost <matthew.brost@intel.com>
Cc: "Tvrtko Ursulin" <tursulin@ursulin.net>,
intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Carlos Santa" <carlos.santa@intel.com>,
"Huang Rui" <ray.huang@amd.com>,
"Matthew Auld" <matthew.auld@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>,
"Daniel Colascione" <dancol@dancol.org>
Subject: Re: [PATCH 1/3] drm/ttm: Issue direct reclaim at beneficial_order
Date: Thu, 23 Apr 2026 10:44:36 +0200 [thread overview]
Message-ID: <697436d1-5720-4b12-9cd7-2d76759d63f5@amd.com> (raw)
In-Reply-To: <aekygVvRz7mu+elE@gsse-cloud1.jf.intel.com>
On 4/22/26 22:41, Matthew Brost wrote:
> On Wed, Apr 22, 2026 at 09:41:54AM +0200, Christian König wrote:
>> On 4/22/26 09:32, Tvrtko Ursulin wrote:
>>>
>>> On 21/04/2026 02:26, Matthew Brost wrote:
>>>> Triggering kswap at an order higher than beneficial_order makes little
>>>> sense, as the driver has already indicated the optimal order at which
>>>> reclaim is effective. Similarly, issuing direct reclaim or triggering
>>>> kswap at a lower order than beneficial_order is ineffective, since the
>>>> driver does not benefit from reclaiming lower-order pages.
>>>>
>>>> As a result, direct reclaim should only be issued with __GFP_NORETRY at
>>>> exactly beneficial_order, or as a fallback, direct reclaim without
>>>> __GFP_NORETRY at order 0 when failure is not an option.
>>>>
>>>> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
>>>> Cc: Carlos Santa <carlos.santa@intel.com>
>>>> Cc: Christian Koenig <christian.koenig@amd.com>
>>>> Cc: Huang Rui <ray.huang@amd.com>
>>>> Cc: Matthew Auld <matthew.auld@intel.com>
>>>> Cc: Matthew Brost <matthew.brost@intel.com>
>>>> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
>>>> Cc: Maxime Ripard <mripard@kernel.org>
>>>> Cc: Thomas Zimmermann <tzimmermann@suse.de>
>>>> Cc: David Airlie <airlied@gmail.com>
>>>> Cc: Simona Vetter <simona@ffwll.ch>
>>>> CC: dri-devel@lists.freedesktop.org
>>>> Cc: Daniel Colascione <dancol@dancol.org>
>>>> Signed-off-by: Matthew Brost <matthew.brost@intel.com>
>>>> ---
>>>> drivers/gpu/drm/ttm/ttm_pool.c | 4 ++--
>>>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
>>>> index 26a3689e5fd9..8425dbcc6c68 100644
>>>> --- a/drivers/gpu/drm/ttm/ttm_pool.c
>>>> +++ b/drivers/gpu/drm/ttm/ttm_pool.c
>>>> @@ -165,8 +165,8 @@ static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t gfp_flags,
>>>> * Do not add latency to the allocation path for allocations orders
>>>> * device tolds us do not bring them additional performance gains.
>>>> */
>>>> - if (beneficial_order && order > beneficial_order)
>>>> - gfp_flags &= ~__GFP_DIRECT_RECLAIM;
>>>> + if (order && beneficial_order && order != beneficial_order)
>>>> + gfp_flags &= ~__GFP_RECLAIM;
>>>> if (!ttm_pool_uses_dma_alloc(pool)) {
>>>> p = alloc_pages_node(pool->nid, gfp_flags, order);
>>>
>>> I missed this conversation so don't know if this was discussed -
>
> I meant to CC you here, but missed including you.
>
>>> having less of 64k pages is not a concern? I mean slightly higher TLB pressure etc on hardware which supports this PTE size.
>>
>> At least for AMD GPUs 64k doesn't matter at all.
>>
>
> Same on Intel GPUs for system memory mappings - it is either 4k or 2M
> GPU pages. VRAM can we 64k pages but that isn't involved here.
>
>> There was a large push from the Windows side to use that size, but we have more than enough evidence to prove that this size is actually completely nonsense for almost all use cases.
>>
>> I have no idea how we ended up with that in the first place.
>>
>> It could be that there is still HW out there which can only handle that size, but in that case such HW should just set beneficial_order to 64k.
>>
>
> Or we move to a table config if we find drivers have multiple
> beneficial_orders.
>
>>> Also, does clearing __GFP_RECLAIM disable compaction completely and is that wanted?
>>
>> Oh good point, most likely not.
>>
>
> Without completely reverse engineering the core MM, I'm not sure here.
IIRC (and I'm seriously not an expert for all the details here):
__GFP_DIRECT_RECLAIM is throwing things out which we can trivially reload from file system, e.g. memory backing mapped files.
__GFP_KSWAPD_RECLAIM unmaps anonymous pages and eventually queues them up to be written into the swap. And the hope is that when those are faulted in again they eat up only single 4k pages instead of blocking a larger order.
If I'm not completely mistaken pages actually don't need to reach the swap for this to work, it's mostly just defragmentation of the pages into larger orders.
__GFP_RECLAIM is both of the above together.
> I just read the kernel doc for __GFP_KSWAPD_RECLAIM [1] and this to
> indicate if this is clear compaction won't be entered.
I think we want to avoid only direct reclaim, because __GFP_KSWAPD_RECLAIM just eats up idle CPU cycles (you need to be OOM before it starts to actually use swap) but I'm not 100% sure either.
Regards,
Christian.
>
> Matt
>
> [1] https://elixir.bootlin.com/linux/v7.0/source/include/linux/gfp_types.h#L198
>
>> Regards,
>> Christian.
>>
>>>
>>> Regards,
>>>
>>> Tvrtko
>>>
>>
next prev parent reply other threads:[~2026-04-23 8:44 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 1:26 [PATCH 0/3] drm/ttm, drm/xe: Avoid reclaim/eviction loops under fragmentation Matthew Brost
2026-04-21 1:26 ` [PATCH 1/3] drm/ttm: Issue direct reclaim at beneficial_order Matthew Brost
2026-04-21 6:11 ` Christian König
2026-04-22 4:12 ` Matthew Brost
2026-04-22 6:41 ` Christian König
2026-04-22 7:32 ` Tvrtko Ursulin
2026-04-22 7:41 ` Christian König
2026-04-22 20:41 ` Matthew Brost
2026-04-23 8:44 ` Christian König [this message]
2026-04-28 13:45 ` Tvrtko Ursulin
2026-04-29 22:52 ` Daniel Colascione
2026-04-30 0:11 ` Dave Airlie
2026-04-30 7:59 ` Thomas Hellström
2026-04-30 8:14 ` Christian König
2026-04-30 7:34 ` Christian König
2026-04-30 3:00 ` Matthew Brost
2026-05-01 20:04 ` Thadeu Lima de Souza Cascardo
2026-04-21 1:26 ` [PATCH 2/3] drm/xe: Set TTM device beneficial_order to 9 (2M) Matthew Brost
2026-04-21 1:26 ` [PATCH 3/3] drm/xe: Avoid shrinker reclaim from kswapd under fragmentation Matthew Brost
2026-04-22 8:22 ` Thomas Hellström
2026-04-22 20:27 ` Matthew Brost
2026-04-21 5:56 ` ✓ CI.KUnit: success for drm/ttm, drm/xe: Avoid reclaim/eviction loops " Patchwork
2026-04-21 6:43 ` ✓ Xe.CI.BAT: " Patchwork
2026-04-21 8:29 ` ✗ Xe.CI.FULL: failure " Patchwork
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=697436d1-5720-4b12-9cd7-2d76759d63f5@amd.com \
--to=christian.koenig@amd.com \
--cc=airlied@gmail.com \
--cc=carlos.santa@intel.com \
--cc=dancol@dancol.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matthew.auld@intel.com \
--cc=matthew.brost@intel.com \
--cc=mripard@kernel.org \
--cc=ray.huang@amd.com \
--cc=simona@ffwll.ch \
--cc=thomas.hellstrom@linux.intel.com \
--cc=tursulin@ursulin.net \
--cc=tzimmermann@suse.de \
/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