The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Suren Baghdasaryan <surenb@google.com>,
	Zhenhua Huang <quic_zhenhuah@quicinc.com>
Cc: cl@linux.com, rientjes@google.com, roman.gushchin@linux.dev,
	harry.yoo@oracle.com, pasha.tatashin@soleen.com,
	akpm@linux-foundation.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, quic_tingweiz@quicinc.com,
	stable@vger.kernel.org
Subject: Re: [PATCH v2] mm, slab: clean up slab->obj_exts always
Date: Tue, 22 Apr 2025 09:10:54 +0200	[thread overview]
Message-ID: <6a2b474c-764e-434c-be23-2f366b81c839@suse.cz> (raw)
In-Reply-To: <CAJuCfpGwspnceQ5oq_ovViHnawcVCkM1pKawJGckfKsvK1s_Aw@mail.gmail.com>

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
>>


  reply	other threads:[~2025-04-22  7:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6a2b474c-764e-434c-be23-2f366b81c839@suse.cz \
    --to=vbabka@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=harry.yoo@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=quic_tingweiz@quicinc.com \
    --cc=quic_zhenhuah@quicinc.com \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=surenb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox