mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] mm/page_alloc: apply per-task GFP context in bulk allocator
@ 2026-09-14  8:04 Qiqi Liu
  2026-09-14 13:01 ` Vlastimil Babka (SUSE)
  0 siblings, 1 reply; 3+ messages in thread
From: Qiqi Liu @ 2026-09-14  8:04 UTC (permalink / raw)
  To: akpm, vbabka
  Cc: surenb, mhocko, brendan.jackman, hannes, ziy, linux-mm,
	linux-kernel, Qiqi Liu, stable

alloc_pages_bulk_noprof() does not call current_gfp_context(), so
per-task scoped allocation constraints (PF_MEMALLOC_NOIO,
PF_MEMALLOC_NOFS, PF_MEMALLOC_PIN) are not applied on the bulk fast
path.

The most direct consequence is PF_MEMALLOC_PIN: without clearing
__GFP_MOVABLE, prepare_alloc_pages() selects MIGRATE_MOVABLE for
the PCP list, and a task with PF_MEMALLOC_PIN set receives movable
pages from the bulk allocator.  Once pinned, these pages can no
longer be migrated but remain in MOVABLE pageblocks, violating the
mobility contract.  This can increase fragmentation and interfere
with compaction or contiguous-memory allocations, eventually
surfacing as higher allocation latency or allocation failures under
memory pressure.

Found via review of the bulk allocation tracepoint hooks [1].

[1] https://lore.kernel.org/all/20260907120949.418450-1-liuqiqi@kylinos.cn/
Link: https://sashiko.dev/#/patchset/20260907120949.418450-1-liuqiqi%40kylinos.cn
Fixes: 387ba26fb1cb ("mm/page_alloc: add a bulk page allocator")
Cc: stable@vger.kernel.org
Signed-off-by: Qiqi Liu <liuqiqi@kylinos.cn>
---
 mm/page_alloc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 12fac9084c48..3be7288a1aa7 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5207,6 +5207,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid,
 
 	/* May set ALLOC_NOFRAGMENT, fragmentation will return 1 page. */
 	gfp &= gfp_allowed_mask;
+	gfp = current_gfp_context(gfp);
 	if (!prepare_alloc_pages(gfp, 0, preferred_nid, nodemask, &ac, &gfp, &alloc_flags))
 		goto out;
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] mm/page_alloc: apply per-task GFP context in bulk allocator
  2026-09-14  8:04 [PATCH v2] mm/page_alloc: apply per-task GFP context in bulk allocator Qiqi Liu
@ 2026-09-14 13:01 ` Vlastimil Babka (SUSE)
  2026-09-15  7:42   ` Qiqi Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-09-14 13:01 UTC (permalink / raw)
  To: Qiqi Liu, akpm
  Cc: surenb, mhocko, brendan.jackman, hannes, ziy, linux-mm,
	linux-kernel, stable

On 9/14/26 10:04, Qiqi Liu wrote:
> alloc_pages_bulk_noprof() does not call current_gfp_context(), so
> per-task scoped allocation constraints (PF_MEMALLOC_NOIO,
> PF_MEMALLOC_NOFS, PF_MEMALLOC_PIN) are not applied on the bulk fast
> path.
> 
> The most direct consequence is PF_MEMALLOC_PIN: without clearing

I'd say ignoring PF_MEMALLOC_NOFS/PF_MEMALLOC_NOIO also can have a direct
consequence?

Let's replace the line above with:

By ignoring PF_MEMALLOC_NOIO and PF_MEMALLOC_NOFS, the allocation can
theoretically result in a deadlock.

Ignoring PF_MEMALLOC_PIN also has consequences: without clearing ...

> __GFP_MOVABLE, prepare_alloc_pages() selects MIGRATE_MOVABLE for
> the PCP list, and a task with PF_MEMALLOC_PIN set receives movable
> pages from the bulk allocator.  Once pinned, these pages can no
> longer be migrated but remain in MOVABLE pageblocks, violating the
> mobility contract.  This can increase fragmentation and interfere
> with compaction or contiguous-memory allocations, eventually
> surfacing as higher allocation latency or allocation failures under
> memory pressure.
> 
> Found via review of the bulk allocation tracepoint hooks [1].
> 
> [1] https://lore.kernel.org/all/20260907120949.418450-1-liuqiqi@kylinos.cn/
> Link: https://sashiko.dev/#/patchset/20260907120949.418450-1-liuqiqi%40kylinos.cn
> Fixes: 387ba26fb1cb ("mm/page_alloc: add a bulk page allocator")
> Cc: stable@vger.kernel.org
> Signed-off-by: Qiqi Liu <liuqiqi@kylinos.cn>

LGTM.

Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>

> ---
>  mm/page_alloc.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 12fac9084c48..3be7288a1aa7 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -5207,6 +5207,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid,
>  
>  	/* May set ALLOC_NOFRAGMENT, fragmentation will return 1 page. */
>  	gfp &= gfp_allowed_mask;
> +	gfp = current_gfp_context(gfp);
>  	if (!prepare_alloc_pages(gfp, 0, preferred_nid, nodemask, &ac, &gfp, &alloc_flags))
>  		goto out;
>  


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] mm/page_alloc: apply per-task GFP context in bulk allocator
  2026-09-14 13:01 ` Vlastimil Babka (SUSE)
@ 2026-09-15  7:42   ` Qiqi Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Qiqi Liu @ 2026-09-15  7:42 UTC (permalink / raw)
  To: Vlastimil Babka (SUSE), Andrew Morton
  Cc: surenb, mhocko, brendan.jackman, hannes, ziy, linux-mm,
	linux-kernel, stable

Thanks for the suggestion. I'll fold this into the commit message and send v3.

Best regards,
Qiqi

On Mon, Sep 14, 2026 at 03:01:14PM +0200, Vlastimil Babka (SUSE) wrote:
> On 9/14/26 10:04, Qiqi Liu wrote:
> > alloc_pages_bulk_noprof() does not call current_gfp_context(), so
> > per-task scoped allocation constraints (PF_MEMALLOC_NOIO,
> > PF_MEMALLOC_NOFS, PF_MEMALLOC_PIN) are not applied on the bulk fast
> > path.
> > 
> > The most direct consequence is PF_MEMALLOC_PIN: without clearing
> 
> I'd say ignoring PF_MEMALLOC_NOFS/PF_MEMALLOC_NOIO also can have a direct
> consequence?
> 
> Let's replace the line above with:
> 
> By ignoring PF_MEMALLOC_NOIO and PF_MEMALLOC_NOFS, the allocation can
> theoretically result in a deadlock.
> 
> Ignoring PF_MEMALLOC_PIN also has consequences: without clearing ...
> 
> > __GFP_MOVABLE, prepare_alloc_pages() selects MIGRATE_MOVABLE for
> > the PCP list, and a task with PF_MEMALLOC_PIN set receives movable
> > pages from the bulk allocator.  Once pinned, these pages can no
> > longer be migrated but remain in MOVABLE pageblocks, violating the
> > mobility contract.  This can increase fragmentation and interfere
> > with compaction or contiguous-memory allocations, eventually
> > surfacing as higher allocation latency or allocation failures under
> > memory pressure.
> > 
> > Found via review of the bulk allocation tracepoint hooks [1].
> > 
> > [1] https://lore.kernel.org/all/20260907120949.418450-1-liuqiqi@kylinos.cn/
> > Link: https://sashiko.dev/#/patchset/20260907120949.418450-1-liuqiqi%40kylinos.cn
> > Fixes: 387ba26fb1cb ("mm/page_alloc: add a bulk page allocator")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Qiqi Liu <liuqiqi@kylinos.cn>
> 
> LGTM.
> 
> Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
> 
> > ---
> >  mm/page_alloc.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> > index 12fac9084c48..3be7288a1aa7 100644
> > --- a/mm/page_alloc.c
> > +++ b/mm/page_alloc.c
> > @@ -5207,6 +5207,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid,
> >  
> >  	/* May set ALLOC_NOFRAGMENT, fragmentation will return 1 page. */
> >  	gfp &= gfp_allowed_mask;
> > +	gfp = current_gfp_context(gfp);
> >  	if (!prepare_alloc_pages(gfp, 0, preferred_nid, nodemask, &ac, &gfp, &alloc_flags))
> >  		goto out;
> >

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-15  7:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-14  8:04 [PATCH v2] mm/page_alloc: apply per-task GFP context in bulk allocator Qiqi Liu
2026-09-14 13:01 ` Vlastimil Babka (SUSE)
2026-09-15  7:42   ` Qiqi Liu

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®