Re: [PATCH v2 1/3] mm: page_alloc: add a watermark check that knows the migratetype

From: Kiryl Shutsemau (Meta)

Date: Mon Nov 16 2026 - 05:41:37 EST


On Fri, Nov 13, 2026 at 05:51:52PM +0100, Vlastimil Babka (SUSE) wrote:
> On 11/2/26 10:39, Kiryl Shutsemau (Meta) wrote:
> > The high-order check in __zone_watermark_ok() accepts a free page of any
> > migratetype. Under ALLOC_NOFRAGMENT, a request below pageblock_order can
> > only take a page of its own migratetype or claim a whole free block, so
> > the check can pass when the allocation cannot succeed.
> >
> > Telling those apart needs the request's migratetype, but not every check
> > wants them told apart. A check whether an allocation can be served now
> > has to count only the pages it can take.
> >
> > A check whether there is enough free memory counts every migratetype:
> > kswapd and kcompactd balancing a zone, order-0 thresholds, the
> > slowpath's forecast whether reclaim and compaction can still make
> > progress. Reclaim and compaction work across migratetypes to free whole
> > pageblocks.
> >
> > Move the body of __zone_watermark_ok() into __zone_watermark_ok_mt(),
> > which takes the migratetype as well, and make __zone_watermark_ok() a
> > wrapper around it for the second kind of check. These use the new
> > function:
> >
> > - the allocator fast path, zone_watermark_fast();
> > - its recheck after node reclaim in get_page_from_freelist();
> > - compaction's up-front check, compaction_suit_allocation_order().
> >
> > Declare both in mm/internal.h: nothing outside mm uses them.
>
> Why not mm/page_alloc.h instead, now that it exists.

Ack. Will change.

> > @@ -3665,6 +3666,21 @@ bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark,
> > return false;
> > }
> >
> > +/*
> > + * For checks that are not about serving one allocation now: kswapd and
> > + * kcompactd balancing a zone, order-0 thresholds, forecasts whether
> > + * reclaim and compaction can still make progress. They count free pages
> > + * of every migratetype: reclaim and compaction work across migratetypes
> > + * to free whole pageblocks.
> > + */
>
> What a slop comment, sigh. Can you rewrite it normally?

/*
* Return true if free base pages in the zone are above 'mark' regardless
* of migratetype. Use it to check whether the zone as a whole has enough
* free memory. Use __zone_watermark_ok_mt() instead to check whether a
* particular allocation can be served.
*/

Okay?

--
Kiryl Shutsemau / Kirill A. Shutemov