]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mm/page_alloc: avoid overcounting bulk alloc in watermark check
authorShengming Hu <hu.shengming@zte.com.cn>
Thu, 29 Jan 2026 14:38:14 +0000 (22:38 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 24 Mar 2026 21:38:25 +0000 (14:38 -0700)
alloc_pages_bulk_noprof() only fills NULL slots and already tracks how
many entries are pre-populated via nr_populated.

The fast watermark check was adding nr_pages unconditionally, which can
overestimate the demand.  Use (nr_pages - nr_populated) instead, as an
upper bound on the remaining pages this call can still allocate without
scanning the whole array.

Link: https://lkml.kernel.org/r/tencent_F36C5B5FB4DED98C79D9BDEE1210CD338C06@qq.com
Signed-off-by: Shengming Hu <hu.shengming@zte.com.cn>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Brendan Jackman <jackmanb@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/page_alloc.c

index 2d4b6f1a554ed21e0f169cd85b5e1ef8190bdf02..d88c8c67ac0b71cf0c6c5fe1d9cab5f2ac462787 100644 (file)
@@ -5136,7 +5136,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid,
 
                cond_accept_memory(zone, 0, alloc_flags);
 retry_this_zone:
-               mark = wmark_pages(zone, alloc_flags & ALLOC_WMARK_MASK) + nr_pages;
+               mark = wmark_pages(zone, alloc_flags & ALLOC_WMARK_MASK) + nr_pages - nr_populated;
                if (zone_watermark_fast(zone, 0,  mark,
                                zonelist_zone_idx(ac.preferred_zoneref),
                                alloc_flags, gfp)) {