* [PATCH linux-next] mm/page_alloc: avoid overcounting bulk alloc in watermark check
@ 2026-01-29 14:38 shengminghu512
2026-01-29 22:10 ` Andrew Morton
2026-02-12 15:57 ` [PATCH linux-next] mm/page_alloc: avoid overcounting bulk alloc in " Vlastimil Babka
0 siblings, 2 replies; 4+ messages in thread
From: shengminghu512 @ 2026-01-29 14:38 UTC (permalink / raw)
To: akpm, vbabka, surenb, mhocko, jackmanb, hannes
Cc: ziy, inux-mm, linux-kernel, hu.shengming, zhang.run
From: Shengming Hu <hu.shengming@zte.com.cn>
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.
Signed-off-by: Shengming Hu <hu.shengming@zte.com.cn>
---
mm/page_alloc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 5fd9e4a03..90b978802 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5130,7 +5130,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)) {
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH linux-next] mm/page_alloc: avoid overcounting bulk alloc in watermark check
2026-01-29 14:38 [PATCH linux-next] mm/page_alloc: avoid overcounting bulk alloc in watermark check shengminghu512
@ 2026-01-29 22:10 ` Andrew Morton
2026-01-30 0:29 ` [PATCH linux-next] mm/page_alloc: avoid overcounting bulk allocin " shengminghu512
2026-02-12 15:57 ` [PATCH linux-next] mm/page_alloc: avoid overcounting bulk alloc in " Vlastimil Babka
1 sibling, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2026-01-29 22:10 UTC (permalink / raw)
To: shengminghu512
Cc: vbabka, surenb, mhocko, jackmanb, hannes, ziy, inux-mm,
linux-kernel, hu.shengming, zhang.run
On Thu, 29 Jan 2026 22:38:14 +0800 "shengminghu512" <shengminghu512@qq.com> wrote:
> From: Shengming Hu <hu.shengming@zte.com.cn>
>
> 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.
Thanks.
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -5130,7 +5130,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)) {
So that little optimization hasn't been working for four years?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH linux-next] mm/page_alloc: avoid overcounting bulk allocin watermark check
2026-01-29 22:10 ` Andrew Morton
@ 2026-01-30 0:29 ` shengminghu512
0 siblings, 0 replies; 4+ messages in thread
From: shengminghu512 @ 2026-01-30 0:29 UTC (permalink / raw)
To: Andrew Morton
Cc: vbabka, surenb, mhocko, jackmanb, hannes, ziy, linux-mm,
linux-kernel, hu.shengming, zhang.run
> On Thu, 29 Jan 2026 22:38:14 +0800 "shengminghu512" <shengminghu512@qq.com> wrote:
>
> > From: Shengming Hu <hu.shengming@zte.com.cn>
> >
> > 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.
>
> Thanks.
>
> > --- a/mm/page_alloc.c
> > +++ b/mm/page_alloc.c
> > @@ -5130,7 +5130,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)) {
>
> So that little optimization hasn't been working for four years?
Yeah, looks like it’s been conservative for a long time :)
It didn’t break correctness, but it likely made the fast watermark check
less effective by overestimating demand (counting already-populated entries
again), so we’d drop out of `zone_watermark_fast()` earlier and hit the
slow path more often.
--
With Best Regards,
Shengming
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH linux-next] mm/page_alloc: avoid overcounting bulk alloc in watermark check
2026-01-29 14:38 [PATCH linux-next] mm/page_alloc: avoid overcounting bulk alloc in watermark check shengminghu512
2026-01-29 22:10 ` Andrew Morton
@ 2026-02-12 15:57 ` Vlastimil Babka
1 sibling, 0 replies; 4+ messages in thread
From: Vlastimil Babka @ 2026-02-12 15:57 UTC (permalink / raw)
To: shengminghu512, akpm, surenb, mhocko, jackmanb, hannes
Cc: ziy, inux-mm, linux-kernel, hu.shengming, zhang.run
On 1/29/26 15:38, shengminghu512 wrote:
> From: Shengming Hu <hu.shengming@zte.com.cn>
>
> 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.
>
> Signed-off-by: Shengming Hu <hu.shengming@zte.com.cn>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
> ---
> mm/page_alloc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 5fd9e4a03..90b978802 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -5130,7 +5130,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)) {
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-02-12 15:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-29 14:38 [PATCH linux-next] mm/page_alloc: avoid overcounting bulk alloc in watermark check shengminghu512
2026-01-29 22:10 ` Andrew Morton
2026-01-30 0:29 ` [PATCH linux-next] mm/page_alloc: avoid overcounting bulk allocin " shengminghu512
2026-02-12 15:57 ` [PATCH linux-next] mm/page_alloc: avoid overcounting bulk alloc in " Vlastimil Babka
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®