Re: [PATCH v2 1/3] mm: page_alloc: add a watermark check that knows the migratetype
From: Harry Yoo
Date: Thu Nov 05 2026 - 12:14:15 EST
On Mon, Nov 02, 2026 at 09:39:34AM +0000, 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.
nit: perhaps we could make the changelog above bit more concise.
I think the necessary bit here is "With defrag_mode, allocations cannot
steal a page from pageblocks of other migrate type, thus
__zone_watermark_ok() needs to take that into account."
... and maybe
- "Ignoring the allocation's migrate type leads to
stopping direct compaction and reclamation prematurely".
- "Indirect compaction and reclamation are not affected as they do not
serve specific allocations"
> 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.
>
> Nothing reads the migratetype yet: no functional change.
>
> Tested-by: Dev Jain <dev.jain@xxxxxxx>
> Signed-off-by: Kiryl Shutsemau (Meta) <kas@xxxxxxxxxx>
> ---
otherwise looks good to me,
Reviewed-by: Harry Yoo (Meta) <harry@xxxxxxxxxx>
with a nit below.
> include/linux/mmzone.h | 3 ---
> mm/compaction.c | 11 ++++++-----
> mm/internal.h | 7 +++++++
> mm/page_alloc.c | 37 ++++++++++++++++++++++++++++---------
> 4 files changed, 41 insertions(+), 17 deletions(-)
>
> diff --git a/mm/compaction.c b/mm/compaction.c
> index f1b2060eb201..6c553d0e90f8 100644
> --- a/mm/compaction.c
> +++ b/mm/compaction.c
> @@ -3116,7 +3117,7 @@ static void kcompactd_do_work(pg_data_t *pgdat)
>
> ret = compaction_suit_allocation_order(zone,
> cc.order, zoneid, cc.alloc_flags,
> - false, true);
> + MIGRATE_MOVABLE, false, true);
nit: maybe let's set cc.migratetype and pass it?
> @@ -3665,6 +3666,21 @@ bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark,
> return false;
> }
>
--
Cheers,
Harry / Hyeonggon