linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mm, slab: clean up slab->obj_exts always
@ 2025-04-21  7:52 Zhenhua Huang
  2025-04-21 16:02 ` Suren Baghdasaryan
  2025-04-24 16:34 ` Andy Shevchenko
  0 siblings, 2 replies; 8+ messages in thread
From: Zhenhua Huang @ 2025-04-21  7:52 UTC (permalink / raw)
  To: cl, rientjes, vbabka, roman.gushchin, harry.yoo, surenb,
	pasha.tatashin, akpm
  Cc: linux-mm, linux-kernel, quic_tingweiz, Zhenhua Huang, stable

When memory allocation profiling is disabled at runtime or due to an
error, shutdown_mem_profiling() is called: slab->obj_exts which
previously allocated remains.
It won't be cleared by unaccount_slab() because of
mem_alloc_profiling_enabled() not true. It's incorrect, slab->obj_exts
should always be cleaned up in unaccount_slab() to avoid following error:

[...]BUG: Bad page state in process...
..
[...]page dumped because: page still charged to cgroup

Cc: stable@vger.kernel.org
Fixes: 21c690a349ba ("mm: introduce slabobj_ext to support slab object extensions")
Signed-off-by: Zhenhua Huang <quic_zhenhuah@quicinc.com>
Acked-by: David Rientjes <rientjes@google.com>
Acked-by: Harry Yoo <harry.yoo@oracle.com>
Tested-by: Harry Yoo <harry.yoo@oracle.com>
---
 mm/slub.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index 566eb8b8282d..a98ce1426076 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2028,8 +2028,8 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
 	return 0;
 }
 
-/* Should be called only if mem_alloc_profiling_enabled() */
-static noinline void free_slab_obj_exts(struct slab *slab)
+/* Free only if slab_obj_exts(slab) */
+static inline void free_slab_obj_exts(struct slab *slab)
 {
 	struct slabobj_ext *obj_exts;
 
@@ -2601,8 +2601,12 @@ static __always_inline void account_slab(struct slab *slab, int order,
 static __always_inline void unaccount_slab(struct slab *slab, int order,
 					   struct kmem_cache *s)
 {
-	if (memcg_kmem_online() || need_slab_obj_ext())
-		free_slab_obj_exts(slab);
+	/*
+	 * The slab object extensions should now be freed regardless of
+	 * whether mem_alloc_profiling_enabled() or not because profiling
+	 * might have been disabled after slab->obj_exts got allocated.
+	 */
+	free_slab_obj_exts(slab);
 
 	mod_node_page_state(slab_pgdat(slab), cache_vmstat_idx(s),
 			    -(PAGE_SIZE << order));
-- 
2.34.1



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

* Re: [PATCH v2] mm, slab: clean up slab->obj_exts always
  2025-04-21  7:52 [PATCH v2] mm, slab: clean up slab->obj_exts always Zhenhua Huang
@ 2025-04-21 16:02 ` Suren Baghdasaryan
  2025-04-22  7:10   ` Vlastimil Babka
  2025-04-24 16:34 ` Andy Shevchenko
  1 sibling, 1 reply; 8+ messages in thread
From: Suren Baghdasaryan @ 2025-04-21 16:02 UTC (permalink / raw)
  To: Zhenhua Huang
  Cc: cl, rientjes, vbabka, roman.gushchin, harry.yoo, pasha.tatashin,
	akpm, linux-mm, linux-kernel, quic_tingweiz, stable

On Mon, Apr 21, 2025 at 12:52 AM Zhenhua Huang
<quic_zhenhuah@quicinc.com> wrote:
>
> When memory allocation profiling is disabled at runtime or due to an
> error, shutdown_mem_profiling() is called: slab->obj_exts which
> previously allocated remains.
> It won't be cleared by unaccount_slab() because of
> mem_alloc_profiling_enabled() not true. It's incorrect, slab->obj_exts
> should always be cleaned up in unaccount_slab() to avoid following error:
>
> [...]BUG: Bad page state in process...
> ..
> [...]page dumped because: page still charged to cgroup
>
> Cc: stable@vger.kernel.org
> Fixes: 21c690a349ba ("mm: introduce slabobj_ext to support slab object extensions")
> Signed-off-by: Zhenhua Huang <quic_zhenhuah@quicinc.com>
> Acked-by: David Rientjes <rientjes@google.com>
> Acked-by: Harry Yoo <harry.yoo@oracle.com>
> Tested-by: Harry Yoo <harry.yoo@oracle.com>

Acked-by: Suren Baghdasaryan <surenb@google.com>

> ---
>  mm/slub.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index 566eb8b8282d..a98ce1426076 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -2028,8 +2028,8 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
>         return 0;
>  }
>
> -/* Should be called only if mem_alloc_profiling_enabled() */
> -static noinline void free_slab_obj_exts(struct slab *slab)
> +/* Free only if slab_obj_exts(slab) */

nit: the above comment is unnecessary. It's quite obvious from the code.

> +static inline void free_slab_obj_exts(struct slab *slab)
>  {
>         struct slabobj_ext *obj_exts;
>
> @@ -2601,8 +2601,12 @@ static __always_inline void account_slab(struct slab *slab, int order,
>  static __always_inline void unaccount_slab(struct slab *slab, int order,
>                                            struct kmem_cache *s)
>  {
> -       if (memcg_kmem_online() || need_slab_obj_ext())
> -               free_slab_obj_exts(slab);
> +       /*
> +        * The slab object extensions should now be freed regardless of
> +        * whether mem_alloc_profiling_enabled() or not because profiling
> +        * might have been disabled after slab->obj_exts got allocated.
> +        */
> +       free_slab_obj_exts(slab);
>
>         mod_node_page_state(slab_pgdat(slab), cache_vmstat_idx(s),
>                             -(PAGE_SIZE << order));
> --
> 2.34.1
>


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

* Re: [PATCH v2] mm, slab: clean up slab->obj_exts always
  2025-04-21 16:02 ` Suren Baghdasaryan
@ 2025-04-22  7:10   ` Vlastimil Babka
  2025-04-22  7:22     ` Zhenhua Huang
  0 siblings, 1 reply; 8+ messages in thread
From: Vlastimil Babka @ 2025-04-22  7:10 UTC (permalink / raw)
  To: Suren Baghdasaryan, Zhenhua Huang
  Cc: cl, rientjes, roman.gushchin, harry.yoo, pasha.tatashin, akpm,
	linux-mm, linux-kernel, quic_tingweiz, stable

On 4/21/25 18:02, Suren Baghdasaryan wrote:
> On Mon, Apr 21, 2025 at 12:52 AM Zhenhua Huang
> <quic_zhenhuah@quicinc.com> wrote:
>>
>> When memory allocation profiling is disabled at runtime or due to an
>> error, shutdown_mem_profiling() is called: slab->obj_exts which
>> previously allocated remains.
>> It won't be cleared by unaccount_slab() because of
>> mem_alloc_profiling_enabled() not true. It's incorrect, slab->obj_exts
>> should always be cleaned up in unaccount_slab() to avoid following error:
>>
>> [...]BUG: Bad page state in process...
>> ..
>> [...]page dumped because: page still charged to cgroup
>>
>> Cc: stable@vger.kernel.org
>> Fixes: 21c690a349ba ("mm: introduce slabobj_ext to support slab object extensions")
>> Signed-off-by: Zhenhua Huang <quic_zhenhuah@quicinc.com>
>> Acked-by: David Rientjes <rientjes@google.com>
>> Acked-by: Harry Yoo <harry.yoo@oracle.com>
>> Tested-by: Harry Yoo <harry.yoo@oracle.com>
> 
> Acked-by: Suren Baghdasaryan <surenb@google.com>
> 
>> ---
>>  mm/slub.c | 12 ++++++++----
>>  1 file changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/mm/slub.c b/mm/slub.c
>> index 566eb8b8282d..a98ce1426076 100644
>> --- a/mm/slub.c
>> +++ b/mm/slub.c
>> @@ -2028,8 +2028,8 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
>>         return 0;
>>  }
>>
>> -/* Should be called only if mem_alloc_profiling_enabled() */
>> -static noinline void free_slab_obj_exts(struct slab *slab)
>> +/* Free only if slab_obj_exts(slab) */
> 
> nit: the above comment is unnecessary. It's quite obvious from the code.

Agreed, I've removed it locally and added the patch to slab/for-next-fixes
Thanks!

>> +static inline void free_slab_obj_exts(struct slab *slab)
>>  {
>>         struct slabobj_ext *obj_exts;
>>
>> @@ -2601,8 +2601,12 @@ static __always_inline void account_slab(struct slab *slab, int order,
>>  static __always_inline void unaccount_slab(struct slab *slab, int order,
>>                                            struct kmem_cache *s)
>>  {
>> -       if (memcg_kmem_online() || need_slab_obj_ext())
>> -               free_slab_obj_exts(slab);
>> +       /*
>> +        * The slab object extensions should now be freed regardless of
>> +        * whether mem_alloc_profiling_enabled() or not because profiling
>> +        * might have been disabled after slab->obj_exts got allocated.
>> +        */
>> +       free_slab_obj_exts(slab);
>>
>>         mod_node_page_state(slab_pgdat(slab), cache_vmstat_idx(s),
>>                             -(PAGE_SIZE << order));
>> --
>> 2.34.1
>>



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

* Re: [PATCH v2] mm, slab: clean up slab->obj_exts always
  2025-04-22  7:10   ` Vlastimil Babka
@ 2025-04-22  7:22     ` Zhenhua Huang
  0 siblings, 0 replies; 8+ messages in thread
From: Zhenhua Huang @ 2025-04-22  7:22 UTC (permalink / raw)
  To: Vlastimil Babka, Suren Baghdasaryan
  Cc: cl, rientjes, roman.gushchin, harry.yoo, pasha.tatashin, akpm,
	linux-mm, linux-kernel, quic_tingweiz, stable



On 2025/4/22 15:10, Vlastimil Babka wrote:
>> nit: the above comment is unnecessary. It's quite obvious from the code.
> Agreed, I've removed it locally and added the patch to slab/for-next-fixes
> Thanks!

Thanks Vlastimil.



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

* Re: [PATCH v2] mm, slab: clean up slab->obj_exts always
  2025-04-21  7:52 [PATCH v2] mm, slab: clean up slab->obj_exts always Zhenhua Huang
  2025-04-21 16:02 ` Suren Baghdasaryan
@ 2025-04-24 16:34 ` Andy Shevchenko
  2025-04-24 16:48   ` Andy Shevchenko
  2025-04-24 16:48   ` Vlastimil Babka
  1 sibling, 2 replies; 8+ messages in thread
From: Andy Shevchenko @ 2025-04-24 16:34 UTC (permalink / raw)
  To: Zhenhua Huang
  Cc: cl, rientjes, vbabka, roman.gushchin, harry.yoo, surenb,
	pasha.tatashin, akpm, linux-mm, linux-kernel, quic_tingweiz,
	stable

On Mon, Apr 21, 2025 at 03:52:32PM +0800, Zhenhua Huang wrote:
> When memory allocation profiling is disabled at runtime or due to an
> error, shutdown_mem_profiling() is called: slab->obj_exts which
> previously allocated remains.
> It won't be cleared by unaccount_slab() because of
> mem_alloc_profiling_enabled() not true. It's incorrect, slab->obj_exts
> should always be cleaned up in unaccount_slab() to avoid following error:
> 
> [...]BUG: Bad page state in process...
> ..
> [...]page dumped because: page still charged to cgroup

Please, always compile test with `make W=1`. Since CONFIG_WERROR=y this
effectively breaks the build with Clang.

-- 
With Best Regards,
Andy Shevchenko




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

* Re: [PATCH v2] mm, slab: clean up slab->obj_exts always
  2025-04-24 16:34 ` Andy Shevchenko
@ 2025-04-24 16:48   ` Andy Shevchenko
  2025-04-24 16:48   ` Vlastimil Babka
  1 sibling, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2025-04-24 16:48 UTC (permalink / raw)
  To: Zhenhua Huang
  Cc: cl, rientjes, vbabka, roman.gushchin, harry.yoo, surenb,
	pasha.tatashin, akpm, linux-mm, linux-kernel, quic_tingweiz,
	stable

On Thu, Apr 24, 2025 at 07:34:29PM +0300, Andy Shevchenko wrote:
> On Mon, Apr 21, 2025 at 03:52:32PM +0800, Zhenhua Huang wrote:
> > When memory allocation profiling is disabled at runtime or due to an
> > error, shutdown_mem_profiling() is called: slab->obj_exts which
> > previously allocated remains.
> > It won't be cleared by unaccount_slab() because of
> > mem_alloc_profiling_enabled() not true. It's incorrect, slab->obj_exts
> > should always be cleaned up in unaccount_slab() to avoid following error:
> > 
> > [...]BUG: Bad page state in process...
> > ..
> > [...]page dumped because: page still charged to cgroup
> 
> Please, always compile test with `make W=1`. Since CONFIG_WERROR=y this
> effectively breaks the build with Clang.

FWIW, fix has just been sent:
20250424164800.2658961-1-andriy.shevchenko@linux.intel.com

-- 
With Best Regards,
Andy Shevchenko




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

* Re: [PATCH v2] mm, slab: clean up slab->obj_exts always
  2025-04-24 16:34 ` Andy Shevchenko
  2025-04-24 16:48   ` Andy Shevchenko
@ 2025-04-24 16:48   ` Vlastimil Babka
  2025-04-24 17:19     ` Andy Shevchenko
  1 sibling, 1 reply; 8+ messages in thread
From: Vlastimil Babka @ 2025-04-24 16:48 UTC (permalink / raw)
  To: Andy Shevchenko, Zhenhua Huang
  Cc: cl, rientjes, roman.gushchin, harry.yoo, surenb, pasha.tatashin,
	akpm, linux-mm, linux-kernel, quic_tingweiz, stable

On 4/24/25 18:34, Andy Shevchenko wrote:
> On Mon, Apr 21, 2025 at 03:52:32PM +0800, Zhenhua Huang wrote:
>> When memory allocation profiling is disabled at runtime or due to an
>> error, shutdown_mem_profiling() is called: slab->obj_exts which
>> previously allocated remains.
>> It won't be cleared by unaccount_slab() because of
>> mem_alloc_profiling_enabled() not true. It's incorrect, slab->obj_exts
>> should always be cleaned up in unaccount_slab() to avoid following error:
>> 
>> [...]BUG: Bad page state in process...
>> ..
>> [...]page dumped because: page still charged to cgroup
> 
> Please, always compile test with `make W=1`. Since CONFIG_WERROR=y this
> effectively breaks the build with Clang.

I don't see why, nor observe any W=1 warnings, can you be more specific? Thanks.


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

* Re: [PATCH v2] mm, slab: clean up slab->obj_exts always
  2025-04-24 16:48   ` Vlastimil Babka
@ 2025-04-24 17:19     ` Andy Shevchenko
  0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2025-04-24 17:19 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: Zhenhua Huang, cl, rientjes, roman.gushchin, harry.yoo, surenb,
	pasha.tatashin, akpm, linux-mm, linux-kernel, quic_tingweiz,
	stable

On Thu, Apr 24, 2025 at 06:48:46PM +0200, Vlastimil Babka wrote:
> On 4/24/25 18:34, Andy Shevchenko wrote:
> > On Mon, Apr 21, 2025 at 03:52:32PM +0800, Zhenhua Huang wrote:
> >> When memory allocation profiling is disabled at runtime or due to an
> >> error, shutdown_mem_profiling() is called: slab->obj_exts which
> >> previously allocated remains.
> >> It won't be cleared by unaccount_slab() because of
> >> mem_alloc_profiling_enabled() not true. It's incorrect, slab->obj_exts
> >> should always be cleaned up in unaccount_slab() to avoid following error:
> >> 
> >> [...]BUG: Bad page state in process...
> >> ..
> >> [...]page dumped because: page still charged to cgroup
> > 
> > Please, always compile test with `make W=1`. Since CONFIG_WERROR=y this
> > effectively breaks the build with Clang.
> 
> I don't see why, nor observe any W=1 warnings, can you be more specific? Thanks.

Specifics are in the fix I sent. Just a relatively new Clang and
relatively recent enabling of warning for unused static inline functions
in the C code. If you are insisting in seeing the exact kernel
configuration I have, tell me where to send, I'll send it privately
to avoid noise here.

-- 
With Best Regards,
Andy Shevchenko




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

end of thread, other threads:[~2025-04-24 17:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-21  7:52 [PATCH v2] mm, slab: clean up slab->obj_exts always Zhenhua Huang
2025-04-21 16:02 ` Suren Baghdasaryan
2025-04-22  7:10   ` Vlastimil Babka
2025-04-22  7:22     ` Zhenhua Huang
2025-04-24 16:34 ` Andy Shevchenko
2025-04-24 16:48   ` Andy Shevchenko
2025-04-24 16:48   ` Vlastimil Babka
2025-04-24 17:19     ` Andy Shevchenko

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