mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Harry Yoo <harry@kernel.org>
To: Suren Baghdasaryan <surenb@google.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>,
	"Vlastimil Babka (SUSE)" <vbabka@kernel.org>,
	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>,
	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>,
	Kees Cook <kees@kernel.org>
Subject: Re: [PATCH] mm/slub: serve slabobj_ext array from a strictly larger kmalloc cache
Date: Wed, 1 Jul 2026 13:30:56 +0900	[thread overview]
Message-ID: <9a139365-28e6-4f1e-b35b-7f6091e9aa14@kernel.org> (raw)
In-Reply-To: <CAJuCfpE6WSWPyZMheF4b=2mrwx7bPP3JUe9Pwp6QAswSMF4GyQ@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 3540 bytes --]



On 7/1/26 8:55 AM, Suren Baghdasaryan wrote:
> On Tue, Jun 30, 2026 at 8:27 AM Harry Yoo <harry@kernel.org> wrote:
>>> I'll also give it some thought to see if there is maybe a different
>>> way to fix this that would be easy to backport.
>>
>> Thanks, let's discuss!
> 
> So, below patch is based on stable linux-7.1.y branch and I think it's
> the simplest backportable way to fix this issue. Build-tested only, so
> use just as a prototype.

Thanks!

> Not sure if making buckets parameter
> unconditional from CONFIG_SLAB_BUCKETS has side-effects...

Increased binary size and register pressure IIRC
https://lore.kernel.org/linux-mm/d0fe363c-2e8f-44a4-9b64-3fa3ba9a5773@kernel.org

> Attaching the patch as well since I'm sure gmail will butcher the tabs.
> 
> The fix for 7.2 should be much simpler using a new flag in
> kmalloc_flags() for obj_ext vector allocations and serving these from
> a dedicated cache.

...which means, in 7.2, it will have a new KMALLOC_TYPE and now
kmalloc_type() and kmalloc_slab() will select the cache based on GFP
flags AND slab's alloc_flags (based on SLAB_ALLOC_NO_RECURSE, this is
new)

Hmm, wait.

We can do that in pre-7.2 kernels, by teaching kmalloc_type() and
kmalloc_slab() select the new KMALLOC_TYPE based on __GFP_NO_OBJ_EXT?

e.g.) Select the new KMALLOC_TYPE when KMALLOC_NOT_NORMAL_BITS is not
set AND __GFP_NO_OBJ_EXT is set.

This doesn't require kmem_buckets and should be much simpler.

> Please let me know what you think:

So I think we don't need kmem_buckets for minimal fixes?

> ---
>  include/linux/slab.h | 42 +++++++++++++++++++++---------
>  mm/slub.c            | 61 +++++++++++---------------------------------
>  2 files changed, 45 insertions(+), 58 deletions(-)
> 
> diff --git a/include/linux/slab.h b/include/linux/slab.h
> index 2b5ab488e96b..2d4a6e3064a3 100644
> --- a/include/linux/slab.h
> +++ b/include/linux/slab.h
> @@ -618,6 +618,10 @@ static inline unsigned int arch_slab_minalign(void)
>  #define RANDOM_KMALLOC_CACHES_NR        0
>  #endif
> 
> +#if defined(CONFIG_MEM_ALLOC_PROFILING) && defined(CONFIG_SLUB_TINY)
> +#define OBJ_EXT_VEC_CACHE
> +#endif

Should be || instead of &&

>  /*
>   * Whenever changing this, take care of that kmalloc_type() and
>   * create_kmalloc_caches() still work as intended.
> @@ -646,6 +650,9 @@ enum kmalloc_cache_type {
>  #endif
>  #ifdef CONFIG_MEMCG
>          KMALLOC_CGROUP,
> +#endif
> +#ifdef OBJ_EXT_VEC_CACHE
> +        KMALLOC_OBJ_EXT_VEC,
>  #endif
>          NR_KMALLOC_TYPES
>  };
> @@ -654,6 +661,18 @@ typedef struct kmem_cache *
> kmem_buckets[KMALLOC_SHIFT_HIGH + 1];
> 
>  extern kmem_buckets kmalloc_caches[NR_KMALLOC_TYPES];
> 
> +#ifdef OBJ_EXT_VEC_CACHE
> +static inline kmem_buckets *obj_ext_vec_buckets(void)
> +{
> +        return &kmalloc_caches[KMALLOC_OBJ_EXT_VEC];
> +}
> +#else
> +static inline kmem_buckets *obj_ext_vec_buckets(void)
> +{
> +        return NULL;
> +}
> +#endif

This is bit weird because it creates a new kmalloc type while using
kmem_buckets. Conceptually, a kmem_buckets can be thought as
a KMALLOC_TYPE, but created by kmem_buckets_create().

Security folks introduced this to isolate some kmalloc allocations from
of varying size (e.g., memdup_user, msg_msg where users can control the
size of allocation) from the rest of kmalloc caches.

>  /*
>   * Define gfp bits that should not be set for KMALLOC_NORMAL.
>   */

-- 
Cheers,
Harry / Hyeonggon


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2026-07-01  4:31 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-25 23:00 Shakeel Butt
2026-06-26  4:22 ` Harry Yoo
2026-06-26 16:49   ` Shakeel Butt
2026-06-26 17:11     ` Vlastimil Babka (SUSE)
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 [this message]
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-07-02  5:14                                                   ` Harry Yoo
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=9a139365-28e6-4f1e-b35b-7f6091e9aa14@kernel.org \
    --to=harry@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=cl@gentwo.org \
    --cc=dcostantino@meta.com \
    --cc=hao.li@linux.dev \
    --cc=kees@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 \
    --cc=vbabka@kernel.org \
    /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

all inboxes | Powered by JetHome®