linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/page_alloc: Fix try_alloc_pages
@ 2025-04-01  3:23 Alexei Starovoitov
  2025-04-01  3:41 ` Harry Yoo
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Alexei Starovoitov @ 2025-04-01  3:23 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: bpf, daniel, andrii, martin.lau, akpm, peterz, vbabka, bigeasy,
	rostedt, shakeel.butt, mhocko, linux-mm, linux-kernel

From: Alexei Starovoitov <ast@kernel.org>

Fix an obvious bug. try_alloc_pages() should set_page_refcounted.

Fixes: 97769a53f117 ("mm, bpf: Introduce try_alloc_pages() for opportunistic page allocation")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---

As soon as I fast forwarded and rerun the tests the bug was
seen immediately.
I'm completely baffled how I managed to lose this hunk.
I'm pretty sure I manually tested various code paths of
trylock logic with CONFIG_DEBUG_VM=y.
Pure incompetence :(
Shame.
---
 mm/page_alloc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index ffbb5678bc2f..c0bcfe9d0dd9 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -7248,6 +7248,9 @@ struct page *try_alloc_pages_noprof(int nid, unsigned int order)
 
 	/* Unlike regular alloc_pages() there is no __alloc_pages_slowpath(). */
 
+	if (page)
+		set_page_refcounted(page);
+
 	if (memcg_kmem_online() && page &&
 	    unlikely(__memcg_kmem_charge_page(page, alloc_gfp, order) != 0)) {
 		free_pages_nolock(page, order);
-- 
2.47.1



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

* Re: [PATCH] mm/page_alloc: Fix try_alloc_pages
  2025-04-01  3:23 [PATCH] mm/page_alloc: Fix try_alloc_pages Alexei Starovoitov
@ 2025-04-01  3:41 ` Harry Yoo
  2025-04-01  7:53 ` Vlastimil Babka
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Harry Yoo @ 2025-04-01  3:41 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Linus Torvalds, bpf, daniel, andrii, martin.lau, akpm, peterz,
	vbabka, bigeasy, rostedt, shakeel.butt, mhocko, linux-mm,
	linux-kernel

On Mon, Mar 31, 2025 at 08:23:36PM -0700, Alexei Starovoitov wrote:
> From: Alexei Starovoitov <ast@kernel.org>
> 
> Fix an obvious bug. try_alloc_pages() should set_page_refcounted.
> 
> Fixes: 97769a53f117 ("mm, bpf: Introduce try_alloc_pages() for opportunistic page allocation")
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> ---
> 
> As soon as I fast forwarded and rerun the tests the bug was
> seen immediately.
> I'm completely baffled how I managed to lose this hunk.
> I'm pretty sure I manually tested various code paths of
> trylock logic with CONFIG_DEBUG_VM=y.
> Pure incompetence :(
> Shame.

Better now than later... :)

Looks good to me,
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>

> ---
>  mm/page_alloc.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index ffbb5678bc2f..c0bcfe9d0dd9 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7248,6 +7248,9 @@ struct page *try_alloc_pages_noprof(int nid, unsigned int order)
>  
>  	/* Unlike regular alloc_pages() there is no __alloc_pages_slowpath(). */
>  
> +	if (page)
> +		set_page_refcounted(page);
> +
>  	if (memcg_kmem_online() && page &&
>  	    unlikely(__memcg_kmem_charge_page(page, alloc_gfp, order) != 0)) {
>  		free_pages_nolock(page, order);
> -- 
> 2.47.1

-- 
Cheers,
Harry (formerly known as Hyeonggon)


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

* Re: [PATCH] mm/page_alloc: Fix try_alloc_pages
  2025-04-01  3:23 [PATCH] mm/page_alloc: Fix try_alloc_pages Alexei Starovoitov
  2025-04-01  3:41 ` Harry Yoo
@ 2025-04-01  7:53 ` Vlastimil Babka
  2025-04-01 17:56   ` Alexei Starovoitov
  2025-04-01  8:42 ` Michal Hocko
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Vlastimil Babka @ 2025-04-01  7:53 UTC (permalink / raw)
  To: Alexei Starovoitov, Linus Torvalds
  Cc: bpf, daniel, andrii, martin.lau, akpm, peterz, bigeasy, rostedt,
	shakeel.butt, mhocko, linux-mm, linux-kernel

On 4/1/25 05:23, Alexei Starovoitov wrote:
> From: Alexei Starovoitov <ast@kernel.org>
> 
> Fix an obvious bug. try_alloc_pages() should set_page_refcounted.
> 
> Fixes: 97769a53f117 ("mm, bpf: Introduce try_alloc_pages() for opportunistic page allocation")
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Acked-by: Vlastimil BAbka <vbabka@suse.cz>

> ---
> 
> As soon as I fast forwarded and rerun the tests the bug was
> seen immediately.
> I'm completely baffled how I managed to lose this hunk.

I think the earlier versions were done on older base than v6.14-rc1 which
acquired efabfe1420f5 ("mm/page_alloc: move set_page_refcounted() to callers
of get_page_from_freelist()")

> I'm pretty sure I manually tested various code paths of
> trylock logic with CONFIG_DEBUG_VM=y.
> Pure incompetence :(
> Shame.
> ---
>  mm/page_alloc.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index ffbb5678bc2f..c0bcfe9d0dd9 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7248,6 +7248,9 @@ struct page *try_alloc_pages_noprof(int nid, unsigned int order)
>  
>  	/* Unlike regular alloc_pages() there is no __alloc_pages_slowpath(). */
>  
> +	if (page)
> +		set_page_refcounted(page);

Note for the later try-kmalloc integration, slab uses frozen pages now, so
we'll need to split out a frozen variant of this API.

But this is ok as a bugfix for now.

> +
>  	if (memcg_kmem_online() && page &&
>  	    unlikely(__memcg_kmem_charge_page(page, alloc_gfp, order) != 0)) {
>  		free_pages_nolock(page, order);



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

* Re: [PATCH] mm/page_alloc: Fix try_alloc_pages
  2025-04-01  3:23 [PATCH] mm/page_alloc: Fix try_alloc_pages Alexei Starovoitov
  2025-04-01  3:41 ` Harry Yoo
  2025-04-01  7:53 ` Vlastimil Babka
@ 2025-04-01  8:42 ` Michal Hocko
  2025-04-02  4:30 ` Shakeel Butt
  2025-04-02 22:01 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 7+ messages in thread
From: Michal Hocko @ 2025-04-01  8:42 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Linus Torvalds, bpf, daniel, andrii, martin.lau, akpm, peterz,
	vbabka, bigeasy, rostedt, shakeel.butt, linux-mm, linux-kernel

On Mon 31-03-25 20:23:36, Alexei Starovoitov wrote:
> From: Alexei Starovoitov <ast@kernel.org>
> 
> Fix an obvious bug. try_alloc_pages() should set_page_refcounted.
> 
> Fixes: 97769a53f117 ("mm, bpf: Introduce try_alloc_pages() for opportunistic page allocation")
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
> 
> As soon as I fast forwarded and rerun the tests the bug was
> seen immediately.
> I'm completely baffled how I managed to lose this hunk.
> I'm pretty sure I manually tested various code paths of
> trylock logic with CONFIG_DEBUG_VM=y.
> Pure incompetence :(

I believe Vlastimil is right. This seems to be an unfortunate mismatch
in the final tree when this got merged.
-- 
Michal Hocko
SUSE Labs


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

* Re: [PATCH] mm/page_alloc: Fix try_alloc_pages
  2025-04-01  7:53 ` Vlastimil Babka
@ 2025-04-01 17:56   ` Alexei Starovoitov
  0 siblings, 0 replies; 7+ messages in thread
From: Alexei Starovoitov @ 2025-04-01 17:56 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: Linus Torvalds, bpf, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Andrew Morton, Peter Zijlstra,
	Sebastian Sewior, Steven Rostedt, Shakeel Butt, Michal Hocko,
	linux-mm, LKML

On Tue, Apr 1, 2025 at 12:53 AM Vlastimil Babka <vbabka@suse.cz> wrote:
>
> On 4/1/25 05:23, Alexei Starovoitov wrote:
> > From: Alexei Starovoitov <ast@kernel.org>
> >
> > Fix an obvious bug. try_alloc_pages() should set_page_refcounted.
> >
> > Fixes: 97769a53f117 ("mm, bpf: Introduce try_alloc_pages() for opportunistic page allocation")
> > Signed-off-by: Alexei Starovoitov <ast@kernel.org>
>
> Acked-by: Vlastimil BAbka <vbabka@suse.cz>
>
> > ---
> >
> > As soon as I fast forwarded and rerun the tests the bug was
> > seen immediately.
> > I'm completely baffled how I managed to lose this hunk.
>
> I think the earlier versions were done on older base than v6.14-rc1 which
> acquired efabfe1420f5 ("mm/page_alloc: move set_page_refcounted() to callers
> of get_page_from_freelist()")

ohh. Thanks.
Still, I have no excuse for not doing full integration testing.
I will learn this hard lesson.

> > I'm pretty sure I manually tested various code paths of
> > trylock logic with CONFIG_DEBUG_VM=y.
> > Pure incompetence :(
> > Shame.
> > ---
> >  mm/page_alloc.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> > index ffbb5678bc2f..c0bcfe9d0dd9 100644
> > --- a/mm/page_alloc.c
> > +++ b/mm/page_alloc.c
> > @@ -7248,6 +7248,9 @@ struct page *try_alloc_pages_noprof(int nid, unsigned int order)
> >
> >       /* Unlike regular alloc_pages() there is no __alloc_pages_slowpath(). */
> >
> > +     if (page)
> > +             set_page_refcounted(page);
>
> Note for the later try-kmalloc integration, slab uses frozen pages now, so
> we'll need to split out a frozen variant of this API.

Thanks for the heads up.

> But this is ok as a bugfix for now.
>
> > +
> >       if (memcg_kmem_online() && page &&
> >           unlikely(__memcg_kmem_charge_page(page, alloc_gfp, order) != 0)) {
> >               free_pages_nolock(page, order);
>


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

* Re: [PATCH] mm/page_alloc: Fix try_alloc_pages
  2025-04-01  3:23 [PATCH] mm/page_alloc: Fix try_alloc_pages Alexei Starovoitov
                   ` (2 preceding siblings ...)
  2025-04-01  8:42 ` Michal Hocko
@ 2025-04-02  4:30 ` Shakeel Butt
  2025-04-02 22:01 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 7+ messages in thread
From: Shakeel Butt @ 2025-04-02  4:30 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Linus Torvalds, bpf, daniel, andrii, martin.lau, akpm, peterz,
	vbabka, bigeasy, rostedt, mhocko, linux-mm, linux-kernel

On Mon, Mar 31, 2025 at 08:23:36PM -0700, Alexei Starovoitov wrote:
> From: Alexei Starovoitov <ast@kernel.org>
> 
> Fix an obvious bug. try_alloc_pages() should set_page_refcounted.
> 
> Fixes: 97769a53f117 ("mm, bpf: Introduce try_alloc_pages() for opportunistic page allocation")
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>


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

* Re: [PATCH] mm/page_alloc: Fix try_alloc_pages
  2025-04-01  3:23 [PATCH] mm/page_alloc: Fix try_alloc_pages Alexei Starovoitov
                   ` (3 preceding siblings ...)
  2025-04-02  4:30 ` Shakeel Butt
@ 2025-04-02 22:01 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-04-02 22:01 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: torvalds, bpf, daniel, andrii, martin.lau, akpm, peterz, vbabka,
	bigeasy, rostedt, shakeel.butt, mhocko, linux-mm, linux-kernel

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Linus Torvalds <torvalds@linux-foundation.org>:

On Mon, 31 Mar 2025 20:23:36 -0700 you wrote:
> From: Alexei Starovoitov <ast@kernel.org>
> 
> Fix an obvious bug. try_alloc_pages() should set_page_refcounted.
> 
> Fixes: 97769a53f117 ("mm, bpf: Introduce try_alloc_pages() for opportunistic page allocation")
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> 
> [...]

Here is the summary with links:
  - mm/page_alloc: Fix try_alloc_pages
    https://git.kernel.org/bpf/bpf-next/c/2985dae1e521

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html




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

end of thread, other threads:[~2025-04-02 22:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-01  3:23 [PATCH] mm/page_alloc: Fix try_alloc_pages Alexei Starovoitov
2025-04-01  3:41 ` Harry Yoo
2025-04-01  7:53 ` Vlastimil Babka
2025-04-01 17:56   ` Alexei Starovoitov
2025-04-01  8:42 ` Michal Hocko
2025-04-02  4:30 ` Shakeel Butt
2025-04-02 22:01 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox