Re: [PATCH v2 1/5] mm: Introduce zone_appears_fragmented()

From: Matthew Brost

Date: Wed Apr 29 2026 - 22:37:56 EST


On Tue, Apr 28, 2026 at 11:51:34AM +0200, Andi Shyti wrote:
> Hi Matt,
>
> On Wed, Apr 22, 2026 at 10:56:52PM -0700, Matthew Brost wrote:
> > Introduce zone_appears_fragmented() 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@xxxxxxxxxxxxxxx>
> > Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> > Cc: David Hildenbrand <david@xxxxxxxxxx>
> > Cc: Lorenzo Stoakes <ljs@xxxxxxxxxx>
> > Cc: "Liam R. Howlett" <Liam.Howlett@xxxxxxxxxx>
> > Cc: Vlastimil Babka <vbabka@xxxxxxxxxx>
> > Cc: Mike Rapoport <rppt@xxxxxxxxxx>
> > Cc: Suren Baghdasaryan <surenb@xxxxxxxxxx>
> > Cc: Michal Hocko <mhocko@xxxxxxxx>
> > Cc: linux-mm@xxxxxxxxx
> > Cc: linux-kernel@xxxxxxxxxxxxxxx
> > Signed-off-by: Matthew Brost <matthew.brost@xxxxxxxxx>
> > ---
> > include/linux/vmstat.h | 13 +++++++++++++
> > 1 file changed, 13 insertions(+)
> >
> > diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
> > index 3c9c266cf782..568d9f4f1a1f 100644
> > --- a/include/linux/vmstat.h
> > +++ b/include/linux/vmstat.h
> > @@ -483,6 +483,19 @@ static inline const char *zone_stat_name(enum zone_stat_item item)
> > return vmstat_text[item];
> > }
> >
> > +static inline bool zone_appears_fragmented(struct zone *zone)
>
> this is a bit of a strong statement and the function name might
> be misleading. You received some suggestions from David and I
> would rename this function to something like
> "zone_maybe_fragmented()".
>

+1

> > +{
> > + /*
> > + * Simple heuristic: if the number of free pages is more than twice the
> > + * high watermark, this strongly suggests that the zone is heavily
> > + * fragmented when called from a shrinker.
> > + */
>
> The commit log explains it a bit better. The heuristic statement
> here is too strong and it still sounds stronger than it should.
>

Can reword.

Matt

> Andi
>
> > + if (zone_page_state(zone, NR_FREE_PAGES) > high_wmark_pages(zone) * 2)
> > + return true;
> > +
> > + return false;
> > +}
> > +
> > #ifdef CONFIG_NUMA
> > static inline const char *numa_stat_name(enum numa_stat_item item)
> > {
> > --
> > 2.34.1
> >