* [PATCH] mm, slab: clean up slab->obj_exts always
@ 2025-04-18 6:14 Zhenhua Huang
2025-04-18 15:17 ` Harry Yoo
2025-04-20 2:46 ` David Rientjes
0 siblings, 2 replies; 6+ messages in thread
From: Zhenhua Huang @ 2025-04-18 6:14 UTC (permalink / raw)
To: cl, rientjes, vbabka, roman.gushchin, harry.yoo, surenb,
pasha.tatashin, akpm
Cc: linux-mm, linux-kernel, quic_tingweiz, Zhenhua Huang
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
Fixes: 21c690a349baa ("mm: introduce slabobj_ext to support slab object extensions")
Signed-off-by: Zhenhua Huang <quic_zhenhuah@quicinc.com>
---
mm/slub.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/mm/slub.c b/mm/slub.c
index dac149df1be1..b42ce3a88806 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2023,7 +2023,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
return 0;
}
-/* Should be called only if mem_alloc_profiling_enabled() */
+/* Should be called if slab_obj_exts(slab) */
static noinline void free_slab_obj_exts(struct slab *slab)
{
struct slabobj_ext *obj_exts;
@@ -2592,7 +2592,11 @@ 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())
+ /*
+ * The slab object extensions should now be freed regardless of
+ * whether mem_alloc_profiling_enabled() or not now.
+ */
+ if (memcg_kmem_online() || slab_obj_exts(slab))
free_slab_obj_exts(slab);
mod_node_page_state(slab_pgdat(slab), cache_vmstat_idx(s),
--
2.25.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mm, slab: clean up slab->obj_exts always
2025-04-18 6:14 [PATCH] mm, slab: clean up slab->obj_exts always Zhenhua Huang
@ 2025-04-18 15:17 ` Harry Yoo
2025-04-18 23:09 ` Suren Baghdasaryan
2025-04-21 7:42 ` Zhenhua Huang
2025-04-20 2:46 ` David Rientjes
1 sibling, 2 replies; 6+ messages in thread
From: Harry Yoo @ 2025-04-18 15:17 UTC (permalink / raw)
To: Zhenhua Huang
Cc: cl, rientjes, vbabka, roman.gushchin, surenb, pasha.tatashin,
akpm, linux-mm, linux-kernel, quic_tingweiz
On Fri, Apr 18, 2025 at 02:14:59PM +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
>
> Fixes: 21c690a349baa ("mm: introduce slabobj_ext to support slab object extensions")
> Signed-off-by: Zhenhua Huang <quic_zhenhuah@quicinc.com>
> ---
Acked-by: Harry Yoo <harry.yoo@oracle.com>
I reproduced the issue locally and confirmed that this patch fixes
the issue.
Tested-by: Harry Yoo <harry.yoo@oracle.com>
By the way, I think this should probably be backported to -stable?
--
Cheers,
Harry / Hyeonggon
> mm/slub.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index dac149df1be1..b42ce3a88806 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -2023,7 +2023,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
> return 0;
> }
>
> -/* Should be called only if mem_alloc_profiling_enabled() */
> +/* Should be called if slab_obj_exts(slab) */
> static noinline void free_slab_obj_exts(struct slab *slab)
> {
> struct slabobj_ext *obj_exts;
> @@ -2592,7 +2592,11 @@ 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())
> + /*
> + * The slab object extensions should now be freed regardless of
> + * whether mem_alloc_profiling_enabled() or not now.
> + */
> + if (memcg_kmem_online() || slab_obj_exts(slab))
> free_slab_obj_exts(slab);
>
> mod_node_page_state(slab_pgdat(slab), cache_vmstat_idx(s),
> --
> 2.25.1
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mm, slab: clean up slab->obj_exts always
2025-04-18 15:17 ` Harry Yoo
@ 2025-04-18 23:09 ` Suren Baghdasaryan
2025-04-21 7:45 ` Zhenhua Huang
2025-04-21 7:42 ` Zhenhua Huang
1 sibling, 1 reply; 6+ messages in thread
From: Suren Baghdasaryan @ 2025-04-18 23:09 UTC (permalink / raw)
To: Harry Yoo
Cc: Zhenhua Huang, cl, rientjes, vbabka, roman.gushchin,
pasha.tatashin, akpm, linux-mm, linux-kernel, quic_tingweiz
On Fri, Apr 18, 2025 at 8:17 AM Harry Yoo <harry.yoo@oracle.com> wrote:
>
> On Fri, Apr 18, 2025 at 02:14:59PM +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
> >
> > Fixes: 21c690a349baa ("mm: introduce slabobj_ext to support slab object extensions")
> > Signed-off-by: Zhenhua Huang <quic_zhenhuah@quicinc.com>
Thanks for reporting and fixing the issue!
> > ---
>
> Acked-by: Harry Yoo <harry.yoo@oracle.com>
>
> I reproduced the issue locally and confirmed that this patch fixes
> the issue.
>
> Tested-by: Harry Yoo <harry.yoo@oracle.com>
>
> By the way, I think this should probably be backported to -stable?
>
> --
> Cheers,
> Harry / Hyeonggon
>
> > mm/slub.c | 8 ++++++--
> > 1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/mm/slub.c b/mm/slub.c
> > index dac149df1be1..b42ce3a88806 100644
> > --- a/mm/slub.c
> > +++ b/mm/slub.c
> > @@ -2023,7 +2023,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
> > return 0;
> > }
> >
> > -/* Should be called only if mem_alloc_profiling_enabled() */
> > +/* Should be called if slab_obj_exts(slab) */
> > static noinline void free_slab_obj_exts(struct slab *slab)
> > {
> > struct slabobj_ext *obj_exts;
> > @@ -2592,7 +2592,11 @@ 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())
> > + /*
> > + * The slab object extensions should now be freed regardless of
> > + * whether mem_alloc_profiling_enabled() or not now.
This comment does not explain why. I amended it in my suggestion below.
> > + */
> > + if (memcg_kmem_online() || slab_obj_exts(slab))
> > free_slab_obj_exts(slab);
free_slab_obj_exts() will be checking again that for
slab_obj_exts(slab) != NULL. Since this change effectively removes the
static key check (mem_alloc_profiling_enabled() call inside
need_slab_obj_ext()), I think we can simply make free_slab_obj_exts()
inline function and remove the above condition completely. IOW:
static inline void free_slab_obj_exts(struct slab *slab)
{
struct slabobj_ext *obj_exts;
obj_exts = slab_obj_exts(slab);
if (!obj_exts)
return;
...
slab->obj_exts = 0;
}
static __always_inline void unaccount_slab(...)
{
/*
* The slab object extensions should 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),
> > --
> > 2.25.1
> >
> >
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mm, slab: clean up slab->obj_exts always
2025-04-18 6:14 [PATCH] mm, slab: clean up slab->obj_exts always Zhenhua Huang
2025-04-18 15:17 ` Harry Yoo
@ 2025-04-20 2:46 ` David Rientjes
1 sibling, 0 replies; 6+ messages in thread
From: David Rientjes @ 2025-04-20 2:46 UTC (permalink / raw)
To: Zhenhua Huang
Cc: cl, vbabka, roman.gushchin, harry.yoo, surenb, pasha.tatashin,
akpm, linux-mm, linux-kernel, quic_tingweiz
On Fri, 18 Apr 2025, 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
>
> Fixes: 21c690a349baa ("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>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mm, slab: clean up slab->obj_exts always
2025-04-18 15:17 ` Harry Yoo
2025-04-18 23:09 ` Suren Baghdasaryan
@ 2025-04-21 7:42 ` Zhenhua Huang
1 sibling, 0 replies; 6+ messages in thread
From: Zhenhua Huang @ 2025-04-21 7:42 UTC (permalink / raw)
To: Harry Yoo
Cc: cl, rientjes, vbabka, roman.gushchin, surenb, pasha.tatashin,
akpm, linux-mm, linux-kernel, quic_tingweiz
On 2025/4/18 23:17, Harry Yoo wrote:
> On Fri, Apr 18, 2025 at 02:14:59PM +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
>>
>> Fixes: 21c690a349baa ("mm: introduce slabobj_ext to support slab object extensions")
>> Signed-off-by: Zhenhua Huang<quic_zhenhuah@quicinc.com>
>> ---
> Acked-by: Harry Yoo<harry.yoo@oracle.com>
>
> I reproduced the issue locally and confirmed that this patch fixes
> the issue.
>
> Tested-by: Harry Yoo<harry.yoo@oracle.com>
>
> By the way, I think this should probably be backported to -stable?
Thanks Harry, I'll send another patch that incorporates Suren's
suggestion as well.
>
> -- Cheers, Harry / Hyeonggon
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mm, slab: clean up slab->obj_exts always
2025-04-18 23:09 ` Suren Baghdasaryan
@ 2025-04-21 7:45 ` Zhenhua Huang
0 siblings, 0 replies; 6+ messages in thread
From: Zhenhua Huang @ 2025-04-21 7:45 UTC (permalink / raw)
To: Suren Baghdasaryan, Harry Yoo
Cc: cl, rientjes, vbabka, roman.gushchin, pasha.tatashin, akpm,
linux-mm, linux-kernel, quic_tingweiz
Thanks Suren.
On 2025/4/19 7:09, Suren Baghdasaryan wrote:
> On Fri, Apr 18, 2025 at 8:17 AM Harry Yoo <harry.yoo@oracle.com> wrote:
>>
>> On Fri, Apr 18, 2025 at 02:14:59PM +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
>>>
>>> Fixes: 21c690a349baa ("mm: introduce slabobj_ext to support slab object extensions")
>>> Signed-off-by: Zhenhua Huang <quic_zhenhuah@quicinc.com>
>
> Thanks for reporting and fixing the issue!
>
>>> ---
>>
>> Acked-by: Harry Yoo <harry.yoo@oracle.com>
>>
>> I reproduced the issue locally and confirmed that this patch fixes
>> the issue.
>>
>> Tested-by: Harry Yoo <harry.yoo@oracle.com>
>>
>> By the way, I think this should probably be backported to -stable?
>>
>> --
>> Cheers,
>> Harry / Hyeonggon
>>
>>> mm/slub.c | 8 ++++++--
>>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/mm/slub.c b/mm/slub.c
>>> index dac149df1be1..b42ce3a88806 100644
>>> --- a/mm/slub.c
>>> +++ b/mm/slub.c
>>> @@ -2023,7 +2023,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
>>> return 0;
>>> }
>>>
>>> -/* Should be called only if mem_alloc_profiling_enabled() */
>>> +/* Should be called if slab_obj_exts(slab) */
>>> static noinline void free_slab_obj_exts(struct slab *slab)
>>> {
>>> struct slabobj_ext *obj_exts;
>>> @@ -2592,7 +2592,11 @@ 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())
>>> + /*
>>> + * The slab object extensions should now be freed regardless of
>>> + * whether mem_alloc_profiling_enabled() or not now.
>
> This comment does not explain why. I amended it in my suggestion below.
I will follow your suggestion.
>
>>> + */
>>> + if (memcg_kmem_online() || slab_obj_exts(slab))
>>> free_slab_obj_exts(slab);
>
> free_slab_obj_exts() will be checking again that for
> slab_obj_exts(slab) != NULL. Since this change effectively removes the
> static key check (mem_alloc_profiling_enabled() call inside
> need_slab_obj_ext()), I think we can simply make free_slab_obj_exts()
> inline function and remove the above condition completely. IOW:
>
Got it. I'll send another version that includes these changes.
> static inline void free_slab_obj_exts(struct slab *slab)
> {
> struct slabobj_ext *obj_exts;
>
> obj_exts = slab_obj_exts(slab);
> if (!obj_exts)
> return;
> ...
> slab->obj_exts = 0;
> }
>
> static __always_inline void unaccount_slab(...)
> {
> /*
> * The slab object extensions should 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),
>>> --
>>> 2.25.1
>>>
>>>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-04-21 7:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-18 6:14 [PATCH] mm, slab: clean up slab->obj_exts always Zhenhua Huang
2025-04-18 15:17 ` Harry Yoo
2025-04-18 23:09 ` Suren Baghdasaryan
2025-04-21 7:45 ` Zhenhua Huang
2025-04-21 7:42 ` Zhenhua Huang
2025-04-20 2:46 ` David Rientjes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox