From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3503367297 for ; Thu, 2 Jul 2026 05:14:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782969267; cv=none; b=ZJFJQaa1qjsB8WeIFG6L2MSVXzcCDYo3Je80AInqG+AT0TM3nDfPckx7CbkITgmyzU9VuyXVCqqqW1EKdwAAgbbygWWESUxHcejANk1mzt299kWw69ATeOwUUS07lxJup2bVC2+vHTUpn7EkQKP7BFmp2yRNnL8LNJ9sZdB2wD8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782969267; c=relaxed/simple; bh=oCug0vPDD8s7GsPTASlMDHL3qE/dWL++AyTXh1qfDgo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=mKKLL7NDDLH6aLf1Fif+mPZLOAJZpz/BLQh6VuX+mNtUB02us2KKkformo3KHLR8o2KPpme7mo2iSndCspHhxTLQinzHwKQqnmJiujsnO9kVV9HnTcrtnwSJs3pHObh2COYa6MK753s9JBP6mIB4MQx2qYjt0YkDAdZpATfZOnM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LcWfFXNQ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LcWfFXNQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B98381F00A3A; Thu, 2 Jul 2026 05:14:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1782969265; bh=iYTRXCkzbO8y1EOcU9JHzQAlVkOkao7gKekDMmvRoqk=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=LcWfFXNQKF/usTaFgxQ07lCa/LgGDd1xE4AzzVbC+sA69V4P/fAHfJLlUpImNXqj2 YMr+bXzaNjpMvKJlO4arojHdLwJGA5Qzik0gQ1o3ua4M9Q+knMYGHvxjtt8MlfO25V W6hCIAM0fCw9PNAH7zgNVKjjbntKhow2nmiGvoeg/ag0mGCBHMRlY+mg96+TfszaL9 jvUu5MUzRtIlcrXdykbTgViJVKVk8ytPBM+Q5Ag6b0Gax9gaVQtkLuuKWoHuRvXoDa lV3BUCQ3gPfUop6FeKQqClrAzi+gAzB2lf63MCVGVC7lMchx/SlqIEATH+gnnWwi/Y ExsuPjsQQiGKg== Message-ID: <081b80ee-a75b-4d66-8bb1-2d5f847e83c9@kernel.org> Date: Thu, 2 Jul 2026 14:14:17 +0900 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm/slub: serve slabobj_ext array from a strictly larger kmalloc cache To: Suren Baghdasaryan Cc: Shakeel Butt , "Vlastimil Babka (SUSE)" , Andrew Morton , Roman Gushchin , Hao Li , Christoph Lameter , David Rientjes , Usama Arif , Meta kernel team , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Danielle Costantino , Kees Cook References: <62969830-4b1f-483d-8fa9-9ce487568570@kernel.org> <39a79576-dcae-4b66-9478-c81dfe676699@kernel.org> <5ebd3c4a-5c06-43b4-ab0a-7a8f0396c84c@kernel.org> <9a139365-28e6-4f1e-b35b-7f6091e9aa14@kernel.org> <92bf5e21-690e-4a77-929e-5217e0d7cb0c@kernel.org> <68e7f6cd-cf11-46b2-84a2-d512bb22dae4@kernel.org> Content-Language: en-US From: Harry Yoo In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------CChB0t3VR8viSkCmOhEZD0JS" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --------------CChB0t3VR8viSkCmOhEZD0JS Content-Type: multipart/mixed; boundary="------------5GJ3D5zH5Xuw6UD6WsGfEvqD"; protected-headers="v1" From: Harry Yoo To: Suren Baghdasaryan Cc: Shakeel Butt , "Vlastimil Babka (SUSE)" , Andrew Morton , Roman Gushchin , Hao Li , Christoph Lameter , David Rientjes , Usama Arif , Meta kernel team , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Danielle Costantino , Kees Cook Message-ID: <081b80ee-a75b-4d66-8bb1-2d5f847e83c9@kernel.org> Subject: Re: [PATCH] mm/slub: serve slabobj_ext array from a strictly larger kmalloc cache References: <62969830-4b1f-483d-8fa9-9ce487568570@kernel.org> <39a79576-dcae-4b66-9478-c81dfe676699@kernel.org> <5ebd3c4a-5c06-43b4-ab0a-7a8f0396c84c@kernel.org> <9a139365-28e6-4f1e-b35b-7f6091e9aa14@kernel.org> <92bf5e21-690e-4a77-929e-5217e0d7cb0c@kernel.org> <68e7f6cd-cf11-46b2-84a2-d512bb22dae4@kernel.org> In-Reply-To: --------------5GJ3D5zH5Xuw6UD6WsGfEvqD Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 7/1/26 8:37 PM, Suren Baghdasaryan wrote: > On Wed, Jul 1, 2026 at 12:42=E2=80=AFAM Harry Yoo wr= ote: >> On 7/1/26 1:53 PM, Harry Yoo wrote: >>> On 7/1/26 1:30 PM, Harry Yoo wrote: >>>> 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 no= t >>>> set AND __GFP_NO_OBJ_EXT is set. >>> >>> Uh, this is bit subtle though. >>> >>> In some cases KMALLOC_DMA =3D=3D KMALLOC_NORMAL, >>> KMALLOC_CGROUP =3D=3D KMALLOC_NORMAL, >>> or KMALLOC_RECLAIM =3D=3D KMALLOC_NORMAL. >>> >>> Just checking KMALLOC_NOT_NORMAL_BITS is misleading. >> >> Here's a prototype for slab/for-next. Backporting it requires handling= >> __GFP_NO_OBJ_EXT instead of SLAB_ALLOC_NO_RECURSE, but shouldn't be >> too difficult. Now writing changelog and going through testing... >> >> diff --git a/include/linux/slab.h b/include/linux/slab.h >> index 51f03f18c9a7..91a71537a2fe 100644 >> --- a/include/linux/slab.h >> +++ b/include/linux/slab.h >> @@ -684,6 +684,26 @@ static inline unsigned int arch_slab_minalign(voi= d) >> #define KMALLOC_PARTITION_CACHES_NR 0 >> #endif >> >> +/* >> + * SLUB needs a separate kmalloc type, KMALLOC_NO_RECURSE, when >> internal slab >> + * metadata of kmalloc objects can be allocated from the same kmalloc= type. >> + */ >> +#if defined(CONFIG_MEM_ALLOC_PROFILING) >> +/* >> + * Memory allocation profiling can allocate internal slab metadata >> + * for any slab cache. >> + */ >> +#define HAS_KMALLOC_NO_RECURSE >> +#elif defined(CONFIG_SLUB_TINY) && defined(CONFIG_MEMCG) >> +/* >> + * Accounted slab objects are usually allocated from KMALLOC_CGROUP. >> + * On SLUB_TINY, those can be allocated from KMALLOC_NORMAL because >> + * KMALLOC_RECLAIM aliases with KMALLOC_CGROUP and has higher priorit= y than >> + * KMALLOC_CGROUP. >> + */ >> +#define HAS_KMALLOC_NO_RECURSE >> +#endif >> + >> /* >> * Whenever changing this, take care of that kmalloc_type() and >> * create_kmalloc_caches() still work as intended. >> @@ -702,6 +722,9 @@ enum kmalloc_cache_type { >> #endif >> KMALLOC_PARTITION_START =3D KMALLOC_NORMAL, >> KMALLOC_PARTITION_END =3D KMALLOC_PARTITION_START + >> KMALLOC_PARTITION_CACHES_NR, >> +#ifdef HAS_KMALLOC_NO_RECURSE >> + KMALLOC_NO_RECURSE, >> +#endif >> #ifdef CONFIG_SLUB_TINY >> KMALLOC_RECLAIM =3D KMALLOC_NORMAL, >> #else >> @@ -716,6 +739,16 @@ enum kmalloc_cache_type { >> NR_KMALLOC_TYPES >> }; >> >> +#if !defined(HAS_KMALLOC_NO_RECURSE) && defined(CONFIG_SLAB_OBJ_EXT) >> +/* >> + * kmalloc_flags() with SLAB_ALLOC_NO_RECURSE should not use KMALLOC_= NORMAL >> + * if any of these alias with KMALLOC_NORMAL. >> + */ >> +static_assert(KMALLOC_DMA !=3D KMALLOC_NORMAL); >> +static_assert(KMALLOC_CGROUP !=3D KMALLOC_NORMAL); >> +static_assert(KMALLOC_RECLAIM !=3D KMALLOC_NORMAL); >> +#endif >> + >> typedef struct kmem_cache * kmem_buckets[KMALLOC_SHIFT_HIGH + 1]; >> >> extern kmem_buckets kmalloc_caches[NR_KMALLOC_TYPES]; >> diff --git a/mm/slab.h b/mm/slab.h >> index 281a65233795..ba0560111488 100644 >> --- a/mm/slab.h >> +++ b/mm/slab.h >> @@ -386,12 +386,21 @@ static inline unsigned int >> size_index_elem(unsigned int bytes) >> * KMALLOC_MAX_CACHE_SIZE and the caller must check that. >> */ >> static inline struct kmem_cache * >> -kmalloc_slab(size_t size, kmem_buckets *b, gfp_t flags, kmalloc_token= _t >> token) >> +kmalloc_slab(size_t size, kmem_buckets *b, gfp_t flags, kmalloc_token= _t >> token, >> + unsigned int alloc_flags) >> { >> unsigned int index; >> + enum kmalloc_cache_type type =3D kmalloc_type(flags, token); >> + >> +#ifdef HAS_KMALLOC_NO_RECURSE >> + if (type >=3D KMALLOC_PARTITION_START && >> + type <=3D KMALLOC_PARTITION_END && >> + (alloc_flags & SLAB_ALLOC_NO_RECURSE)) >> + type =3D KMALLOC_NO_RECURSE; >> +#endif >=20 > Overall your approach LGTM, just here why not simply: Thanks! There's been few chances since this prototype... 1. KMALLOC_NO_RECURSE -> KMALLOC_NO_OBJ_EXT 2. Unlike KMALLOC_NO_RECURSE, KMALLOC_NO_OBJ_EXT caches have sheaves 3. To allow 2. SLAB_NO_SHEAVES was decoupled from SLAB_NO_OBJ_EXT. Now SLAB_NO_OBJ_EXT disallows obj_exts only. 4. with CONFIG_SLAB_OBJ_EXT=3Dy, KMALLOC_NO_OBJ_EXT caches are created by default but remains unused until needed. > +#ifdef HAS_KMALLOC_NO_RECURSE > + if (alloc_flags & SLAB_ALLOC_NO_RECURSE) > + type =3D KMALLOC_NO_RECURSE; > +#endif Did that in the RFC [1], thanks. [1] https://lore.kernel.org/lkml/20260702-kmalloc-no-objext-v1-0-167175008538= @kernel.org --=20 Cheers, Harry / Hyeonggon --------------5GJ3D5zH5Xuw6UD6WsGfEvqD-- --------------CChB0t3VR8viSkCmOhEZD0JS Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature.asc" -----BEGIN PGP SIGNATURE----- iHUEARYKAB0WIQQQ1ub6gR5ogjaKRmOGXBN6rc5S1gUCakXzqgAKCRCGXBN6rc5S 1l5NAPsH0KVzjAF7buxqw5HY6cb3/V35hr1Tla8Z1ixTQPnSuQEAjxv7sBMiPxlO +xrCaDqTAw75JoM+zBVzW8UH+ov5ags= =9bEJ -----END PGP SIGNATURE----- --------------CChB0t3VR8viSkCmOhEZD0JS--