From: "Santa, Carlos" <carlos.santa@intel.com>
To: "intel-xe@lists.freedesktop.org" <intel-xe@lists.freedesktop.org>,
"Brost, Matthew" <matthew.brost@intel.com>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Liam.Howlett@oracle.com" <Liam.Howlett@oracle.com>,
"david@kernel.org" <david@kernel.org>,
"surenb@google.com" <surenb@google.com>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
"thomas.hellstrom@linux.intel.com"
<thomas.hellstrom@linux.intel.com>,
"ljs@kernel.org" <ljs@kernel.org>,
"vbabka@kernel.org" <vbabka@kernel.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"rppt@kernel.org" <rppt@kernel.org>,
"mhocko@suse.com" <mhocko@suse.com>
Subject: Re: [PATCH v4 2/6] mm: Introduce zone_maybe_fragmented_in_shrinker()
Date: Fri, 1 May 2026 00:50:58 +0000 [thread overview]
Message-ID: <63cfdaec94fdbc6620846d98a47c18c0dfe3bc3e.camel@intel.com> (raw)
In-Reply-To: <20260430191809.2142544-3-matthew.brost@intel.com>
On Thu, 2026-04-30 at 12:18 -0700, Matthew Brost wrote:
> Introduce zone_maybe_fragmented_in_shrinker() as a lightweight helper
> to
> allow subsystems to make coarse decisions about reclaim behavior in
> the
> presence of likely fragmentation.
>
> The helper implements a simple heuristic: if the number of free pages
> in a zone exceeds twice the high watermark, the zone is considered to
> have ample free memory and allocation failures are more likely due to
> fragmentation than overall memory pressure.
>
> This is intentionally imprecise and is not meant to replace the core
> MM compaction or fragmentation accounting logic. Instead, it provides
> a cheap signal for callers (e.g., shrinkers) that wish to avoid
> overly aggressive reclaim when sufficient free memory exists but
> high-order allocations may still fail.
>
> No functional changes; this is a preparatory helper for future users.
>
> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: David Hildenbrand <david@kernel.org>
> Cc: Lorenzo Stoakes <ljs@kernel.org>
> Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>
> Cc: Vlastimil Babka <vbabka@kernel.org>
> Cc: Mike Rapoport <rppt@kernel.org>
> Cc: Suren Baghdasaryan <surenb@google.com>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Matthew Brost <matthew.brost@intel.com>
>
> ---
>
> v3: s/zone_appear_fragmented/zone_maybe_fragmented_in_shrinker (David
> Hildenbrand)
> ---
> include/linux/vmstat.h | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
> index 3c9c266cf782..1ad48f70c9d9 100644
> --- a/include/linux/vmstat.h
> +++ b/include/linux/vmstat.h
> @@ -483,6 +483,18 @@ static inline const char *zone_stat_name(enum
> zone_stat_item item)
> return vmstat_text[item];
> }
>
on the below heuristic, I was thinking of the following case: a large
memory system (say 16G, 32G), heavily fragmented (for whatever reason)
but constraint by the IOMMU requiring large pages due to hw alignment,
if I am not mistaken the below check will cause the shrinker to bail
out too 'early' since the there's plenty of available memory but none
of that is contiguous, then end result should be giving back small
pages which should reduce performance, right?
below are some made up numbers:
Metric | 8GB | 16GB
----------------|-------------------|-------------------
High Wmark | ~45MB (11k pgs) | ~90MB (23k pgs)
Bail Gate (2x) | ~90MB (22k pgs) | ~180MB (46k pgs)
Free RAM | 120MB | 7100MB (7.1GB)
Shrinker | RUNS (Free<Gate) | BAILS (Free>Gate)
Outcome | Merges 2MB blocks | 4KB pages
In other words, replacing the check with numbers:
System | Free RAM (Pages) | Gate (Pages) | Free < Gate? | Result
-------------|------------------|--------------|--------------|-------
8GB | 20,480 (80MB) | 22,946 | 20480 < 22946| RUNS
16GB | 1,832,740 (7.1G) | 45,894 | 1.8M < 45k? | BAILS
Carlos
> +static inline bool zone_maybe_fragmented_in_shrinker(struct zone
> *zone)
> +{
> + /*
> + * Simple heuristic: if the number of free pages is more
> than twice the
> + * high watermark, this may suggest that the zone is heavily
> fragmented.
> + * When called from a shrinker, aggressively evicting memory
> in this case
> + * may do more harm to overall system performance than good.
> + */
> + return zone_page_state(zone, NR_FREE_PAGES) >
> + high_wmark_pages(zone) * 2;
> +}
> +
> #ifdef CONFIG_NUMA
> static inline const char *numa_stat_name(enum numa_stat_item item)
> {
next prev parent reply other threads:[~2026-05-01 0:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-30 19:18 [PATCH v4 0/6] mm, drm/ttm, drm/xe: Avoid reclaim/eviction loops under fragmentation Matthew Brost
2026-04-30 19:18 ` [PATCH v4 1/6] mm: Wire up order in shrink_control Matthew Brost
2026-04-30 19:18 ` [PATCH v4 2/6] mm: Introduce zone_maybe_fragmented_in_shrinker() Matthew Brost
2026-05-01 0:50 ` Santa, Carlos [this message]
2026-05-01 19:08 ` PATCH v4 0/6] mm, drm/ttm, drm/xe: Avoid reclaim/eviction loops under fragmentation Kenneth Crudup
2026-05-01 20:00 ` Matthew Brost
2026-05-01 20:05 ` Kenneth Crudup
2026-05-01 21:10 ` Matthew Brost
2026-05-01 22:33 ` Matthew Brost
2026-04-30 23:01 ` [PATCH " Andrew Morton
2026-05-01 6:28 ` Matthew Brost
2026-05-01 12:51 ` Andrew Morton
2026-05-01 1:42 ` Dave Chinner
2026-05-01 7:09 ` 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=63cfdaec94fdbc6620846d98a47c18c0dfe3bc3e.camel@intel.com \
--to=carlos.santa@intel.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=matthew.brost@intel.com \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=thomas.hellstrom@linux.intel.com \
--cc=vbabka@kernel.org \
/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