All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Cc: <intel-xe@lists.freedesktop.org>,
	<dri-devel@lists.freedesktop.org>,
	Carlos Santa <carlos.santa@intel.com>,
	Matthew Auld <matthew.auld@intel.com>
Subject: Re: [PATCH 3/3] drm/xe: Avoid shrinker reclaim from kswapd under fragmentation
Date: Wed, 22 Apr 2026 13:27:53 -0700	[thread overview]
Message-ID: <aekvSVIuRwRuHcXI@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <432e5ce12ab767bc88b2a0cec49de4fc48694b24.camel@linux.intel.com>

On Wed, Apr 22, 2026 at 10:22:56AM +0200, Thomas Hellström wrote:
> Hi,
> 
> On Mon, 2026-04-20 at 18:26 -0700, Matthew Brost wrote:
> > When the Xe shrinker is invoked from kswapd, a large amount of free
> > memory in ZONE_NORMAL relative to the high watermark is a strong
> > signal
> > that reclaim is being driven by fragmentation rather than true memory
> > pressure.
> > 
> > In this case, shrinking Xe memory is unlikely to help kswapd make
> > forward progress. Instead it can evict active GPU memory despite the
> > system still having substantial free memory, increasing residency
> > churn
> > and reducing GPU forward progress.
> > 
> > Detect this case and bail out early from the Xe shrinker when running
> > in
> > kswapd and ZONE_NORMAL has more than 2x its high watermark free.
> > 
> > Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> > Cc: Carlos Santa <carlos.santa@intel.com>
> > Cc: Matthew Auld <matthew.auld@intel.com>
> > Signed-off-by: Matthew Brost <matthew.brost@intel.com>
> > ---
> >  drivers/gpu/drm/xe/xe_shrinker.c | 13 +++++++++++++
> >  1 file changed, 13 insertions(+)
> > 
> > diff --git a/drivers/gpu/drm/xe/xe_shrinker.c
> > b/drivers/gpu/drm/xe/xe_shrinker.c
> > index 83374cd57660..e56afde83de6 100644
> > --- a/drivers/gpu/drm/xe/xe_shrinker.c
> > +++ b/drivers/gpu/drm/xe/xe_shrinker.c
> > @@ -236,6 +236,19 @@ static unsigned long xe_shrinker_scan(struct
> > shrinker *shrink, struct shrink_con
> >  	if (nr_scanned >= nr_to_scan || !can_backup)
> >  		goto out;
> >  
> > +	if (current_is_kswapd()) {
> > +		struct zone *zone = &NODE_DATA(sc->nid)-
> > >node_zones[ZONE_NORMAL];
> > +		unsigned long free_pages = zone_page_state(zone,
> > NR_FREE_PAGES);
> > +		unsigned long high_wmark = high_wmark_pages(zone);
> > +
> > +		/*
> > +		 * If we have 2x the high watermark free, this is
> > definitely
> > +		 * fragmentation
> > +		 */
> > +		if (free_pages > (high_wmark * 2))
> > +			goto out;
> > +	}
> > +
> 
> While this or a similar check might make sense, That should ideally be
> in the TTM shrinker helpers. And probably we should ask core mm for a
> proper indication whether this is indeed fragmentation-driven.
> 

Yes, moving this to a TTM shrinker helper—or even a core MM helper—makes
more sense. This is the best heuristic I could come up with based on
what is available in the core MM today. However, this is still not 100%
correct, as I don’t think ZONE_NORMAL is used on systems with less than
4GB of memory; instead, ZONE_DMA32 is used. This might get even worse
when considering Kconfig combonations. Asking the core MM via a helper
whether memory is fragmented is likely the best solution.

Matt

> Thanks,
> Thomas
> 
> 
> 
> >  	/* If we didn't wake before, try to do it now if needed. */
> >  	if (!runtime_pm)
> >  		runtime_pm = xe_shrinker_runtime_pm_get(shrinker,
> > true, 0, can_backup);

  reply	other threads:[~2026-04-22 20:28 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
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 [this message]
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=aekvSVIuRwRuHcXI@gsse-cloud1.jf.intel.com \
    --to=matthew.brost@intel.com \
    --cc=carlos.santa@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.auld@intel.com \
    --cc=thomas.hellstrom@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.