From: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
To: Shakeel Butt <shakeel.butt@linux.dev>, Harry Yoo <harry@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Hao Li <hao.li@linux.dev>, Christoph Lameter <cl@gentwo.org>,
David Rientjes <rientjes@google.com>,
Suren Baghdasaryan <surenb@google.com>,
Usama Arif <usama.arif@linux.dev>,
Meta kernel team <kernel-team@meta.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Danielle Costantino <dcostantino@meta.com>
Subject: Re: [PATCH] mm/slub: serve slabobj_ext array from a strictly larger kmalloc cache
Date: Fri, 26 Jun 2026 19:11:33 +0200 [thread overview]
Message-ID: <09267187-6c85-438f-8791-4cce8d07892a@kernel.org> (raw)
In-Reply-To: <aj6re83IC84lkFL0@linux.dev>
On 6/26/26 18:49, Shakeel Butt wrote:
> On Fri, Jun 26, 2026 at 01:22:09PM +0900, Harry Yoo wrote:
>>
>> Hi Shakeel,
>>
>
> [...]
>
>> > What happened: a KMALLOC_NORMAL slab's obj_exts array (used by allocation
>> > profiling / memcg accounting) is itself kmalloc()'d from a KMALLOC_NORMAL
>> > cache,
>>
>> Usually KMALLOC_NORMAL caches don't need obj_exts array, but yes,
>> this could happen if memory allocation profiling is enabled.
>
> Yes, we have enabled memory allocation profiling fleet wide.
>
> [...]
>
>>
>> > Fix it structurally by removing cycles of every shape: serve the array
>> > from a cache strictly larger than the one it describes whenever it would
>> > otherwise come from the same or a smaller cache. Every reference edge
>> > then points from a smaller to a larger cache (here kmalloc-1k's array
>> > moves to kmalloc-2k), so the relation is a DAG and cannot contain a cycle.
>>
>> This will fix the problem.
>>
>> But this will waste memory as we need smaller obj_exts array
>> as the size gets larger.
>>
>> We should probably create a new kmalloc type to avoid cycles instead?
>> (needed only when memory profiling is enabled, though)
>>
>> That would also prevent recursion even further.
>
> Yes but I assume that would add kmem caches even for users not using memory
> profiling. Anyways, I think that is a separate discussion. Am I understanding
> correctly that you don't have any concerns with this approach?
Umm, the memory waste is a concern?
Minimally I'd now want to only do that size bumping when allocation
profiling is enabled. Ideally that means both configured in and not booted
with "never".
We probably should have done that already in 280ea9c3154b2. Because AFAIU
memcg-only obj_exts array don't have this issue (or maybe they do have the
[1] issue? Harry?). But if memcg-only should keep avoiding the same size
bucket, it can keep what it was doing and only memalloc profiling would do
the strictly larger thing.
Suren's input would be also nice to have.
Thanks!
[1] https://lore.kernel.org/oe-lkp/202601231457.f7b31e09-lkp@intel.com
>>
>> > No slab can be self- or cross-pinned, the tear-down recursion is bounded
>> > by the number of kmalloc size classes (it terminates at the large-kmalloc
>> > path, which carries no obj_exts), and profiling/accounting coverage is
>> > unchanged - the array is still allocated, only relocated.
>> >
>> > Reproduced on next-20260623 at the same geometry: churning
>> > kmalloc-512/kmalloc-1k under vm.mem_profiling and then shrinking leaves
>> > kmalloc-512 with thousands of unreclaimable objects without this patch
>> > (8056) and at baseline with it (847).
>> >
>> > Fixes: 4b8736964640 ("mm/slab: add allocation accounting into slab allocation and free paths")
>>
>> Perhaps Cc: stable? v6.12 and v6.18 are affected.
>
> Ack.
>
> [...]
>
>> > - if (s->object_size == obj_exts_cache->object_size)
>> > - return obj_exts_cache->object_size + 1;
>> > + /* compare object_size, not the cache pointer (partitioned kmalloc caches) */
>>
>> This comment is no longer relevant, by the way.
>>
>> "compare object_size instead of cache pointers because there can be
>> multiple caches of the same size" doesn't apply anymore.
>>
>
> I will remove the comment in next version.
>
> Thanks for the review.
>
>> > + if (obj_exts_cache->object_size <= s->object_size)
>> > + return s->object_size + 1;
>> >
>> > return sz;
>> > }
>>
>> --
>> Cheers,
>> Harry / Hyeonggon
>
>
>
next prev parent reply other threads:[~2026-06-26 17:11 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-25 23:00 [PATCH] mm/slub: serve slabobj_ext array from a strictly larger kmalloc cache Shakeel Butt
2026-06-26 4:22 ` Harry Yoo
2026-06-26 16:49 ` Shakeel Butt
2026-06-26 17:11 ` Vlastimil Babka (SUSE) [this message]
2026-06-28 2:58 ` Shakeel Butt
2026-06-28 3:23 ` Shakeel Butt
2026-06-28 7:47 ` Vlastimil Babka (SUSE)
2026-06-28 9:22 ` Harry Yoo
2026-06-28 23:37 ` Suren Baghdasaryan
2026-06-29 3:57 ` Harry Yoo
2026-06-29 4:28 ` Suren Baghdasaryan
2026-06-29 19:52 ` Shakeel Butt
2026-06-30 2:03 ` Harry Yoo
2026-06-30 2:30 ` Harry Yoo
2026-06-30 4:38 ` Suren Baghdasaryan
2026-06-30 4:39 ` Suren Baghdasaryan
2026-06-30 4:42 ` Harry Yoo
2026-06-30 5:29 ` Suren Baghdasaryan
2026-06-30 6:12 ` Vlastimil Babka (SUSE)
2026-06-30 7:03 ` Harry Yoo
2026-06-30 14:35 ` Shakeel Butt
2026-06-30 14:52 ` Suren Baghdasaryan
2026-06-30 15:27 ` Harry Yoo
2026-06-30 23:55 ` Suren Baghdasaryan
2026-07-01 4:30 ` Harry Yoo
2026-07-01 4:53 ` Harry Yoo
2026-07-01 7:42 ` Harry Yoo
2026-07-01 8:43 ` Harry Yoo
2026-07-01 10:31 ` Harry Yoo
2026-07-01 11:37 ` Suren Baghdasaryan
2026-06-28 8:10 ` Harry Yoo
2026-06-28 8:36 ` Harry Yoo
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=09267187-6c85-438f-8791-4cce8d07892a@kernel.org \
--to=vbabka@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=cl@gentwo.org \
--cc=dcostantino@meta.com \
--cc=hao.li@linux.dev \
--cc=harry@kernel.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=surenb@google.com \
--cc=usama.arif@linux.dev \
/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