From: Matthew Brost <matthew.brost@intel.com>
To: "Christian König" <christian.koenig@amd.com>
Cc: "Daniel Colascione" <dancol@dancol.org>,
dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
"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>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] Limit reclaim to avoid TTM desktop stutter under mem pressure
Date: Tue, 7 Apr 2026 10:34:22 -0700 [thread overview]
Message-ID: <adVAHkA4gERWOszt@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <d8e8f290-c2bd-483f-ba0f-735c503e269a@amd.com>
On Tue, Apr 07, 2026 at 09:43:30AM +0200, Christian König wrote:
> On 4/6/26 23:02, Matthew Brost wrote:
> > On Tue, Mar 31, 2026 at 10:08:58PM -0400, Daniel Colascione wrote:
> ...
> >> -
> >> - /*
> >> - * 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 (beneficial_order && order > beneficial_order)
> >> + gfp_flags &= ~__GFP_DIRECT_RECLAIM;
> >> + if (order > max_reclaim_order)
> >> + gfp_flags &= ~__GFP_RECLAIM;
> >
> > I’m not very familiar with this code, but at first glance it doesn’t
> > seem quite right.
> >
> > Would setting Xe’s beneficial to 9, similar to AMD’s, along with this
> > diff, help?
>
> No, not really. The problem is that giving 9 as beneficial order only saves us avoiding direct reclaim for 10 (>=11 is usually not used in a x86 linux kernel anyway).
>
Yes, the first snippet was a bit incomplete. I adjusted it in a
self-reply, but that likely still isn’t exactly right either. I’ll also
take a look at how reclaim works at higher orders and how kswapd behaves
there—I’m shooting from the hip a bit at the moment.
> >
> > If I’m understanding this correctly, we would try a single allocation
> > attempt with __GFP_DIRECT_RECLAIM cleared for the size we care about,
> > still attempt allocations from the pools, and then finally fall back to
> > allocating single pages one at a time.
>
> Well the code is a bit broken, but the general idea is not so bad.
>
> What we could do is to use beneficial_order as sweet spot and set __GFP_DIRECT_RECLAIM only for the allocations with that order.
>
That’s roughly what my follow-up snippet did, but with
__GFP_DIRECT_RECLAIM replaced by __GFP_KSWAPD_RECLAIM. I’m really not
sure what the correct policy should be here. But in general I agree
beneficial_order should be the sweet spot where we trigger some sort of
reclaim.
> This would skip setting it for order 1..8, which are nice to have as well but not so necessary that we always need to trigger reclaim for them.
>
This has made me think a bit further. I’m not really sure the current
approach of TTM setting policy is actually the right choice—it might be
better to give drivers more control so they can tune this themselves.
Rough idea...
struct ttm_pool_order_policy {
bool enable; /* Should I call ttm_pool_alloc_page for an order */
gfp_t reclaim_mask; /* Used in ttm_pool_alloc_page &= ~reclaim_mask; */
};
Then, in ttm_pool_init, we could optionally pass in a table (0 →
MAX_PAGE_ORDER) that controls the allocation pipeline in
__ttm_pool_alloc.
This may be overkill, and it still wouldn’t provide per-BO control,
which might be desirable for cases like compositors versus compute
workloads, etc.
What do you think?
Matt
> Regards,
> Christian.
>
> >
> > Matt
> >
> > diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
> > index aa41099c5ecf..f1f430aba0c1 100644
> > --- a/drivers/gpu/drm/ttm/ttm_pool.c
> > +++ b/drivers/gpu/drm/ttm/ttm_pool.c
> > @@ -714,6 +714,7 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
> > struct ttm_pool_alloc_state *alloc,
> > struct ttm_pool_tt_restore *restore)
> > {
> > + const unsigned int beneficial_order = ttm_pool_beneficial_order(pool);
> > enum ttm_caching page_caching;
> > gfp_t gfp_flags = GFP_USER;
> > pgoff_t caching_divide;
> > @@ -757,7 +758,8 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
> > if (!p) {
> > page_caching = ttm_cached;
> > allow_pools = false;
> > - p = ttm_pool_alloc_page(pool, gfp_flags, order);
> > + if (!order || order >= beneficial_order)
> > + p = ttm_pool_alloc_page(pool, gfp_flags, order);
> > }
> > /* If that fails, lower the order if possible and retry. */
> > if (!p) {
> >
> >
> >> + }
> >>
> >> if (!ttm_pool_uses_dma_alloc(pool)) {
> >> p = alloc_pages_node(pool->nid, gfp_flags, order);
>
next prev parent reply other threads:[~2026-04-07 17:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-01 2:08 [RFC PATCH] Limit reclaim to avoid TTM desktop stutter under mem pressure Daniel Colascione
2026-04-01 7:35 ` Thomas Hellström
2026-04-01 10:16 ` Christian König
2026-04-03 15:12 ` ✗ LGCI.VerificationFailed: failure for " Patchwork
2026-04-06 21:02 ` [RFC PATCH] " Matthew Brost
2026-04-06 21:53 ` Matthew Brost
2026-04-07 7:43 ` Christian König
2026-04-07 17:34 ` Matthew Brost [this message]
2026-04-08 8:00 ` Christian König
2026-04-09 5:12 ` Matthew Brost
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=adVAHkA4gERWOszt@gsse-cloud1.jf.intel.com \
--to=matthew.brost@intel.com \
--cc=airlied@gmail.com \
--cc=christian.koenig@amd.com \
--cc=dancol@dancol.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matthew.auld@intel.com \
--cc=mripard@kernel.org \
--cc=ray.huang@amd.com \
--cc=simona@ffwll.ch \
--cc=thomas.hellstrom@linux.intel.com \
--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