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 852EC342173; Tue, 9 Jun 2026 14:28:37 +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=1781015318; cv=none; b=V76r74RwwaQsck3ojoT40czZfjhEQ2DQ35ZlA8lDYOOOBhw0LD3ZuaxO81DUX0p3uHCMy9uM8RhdwHd/eSp/qlvx5ZN/xdLtmH99RuqfG1B3Yv9sPw/KCIu5NKm2dLFsnphOdPv7TYka00F4OGLIGDqATyZ0H/8bBQg/kiGDW+0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781015318; c=relaxed/simple; bh=uB6FI5sHv9duj2rUMo6jfNMlJ5jDCGMOWn62ZKD+INQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=r0z30iMqNDFia7+oKetYNL8aPdpTDMWq11T3n2KGh+okXbnhBcpm7JMjfaNWCcwOjKwbI/B7ELxsJyWl7gwoW+bg5Exayd+eiADleUOdvWVYPTXZxk/toxQcSawsqvswkf6YY3C1dzjAioy0wfmDHFJYk6PvJ8VV0DVSZVlVArA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mbwVx9+Z; 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="mbwVx9+Z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C3ED1F00893; Tue, 9 Jun 2026 14:28:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1781015317; bh=CY2fUp5PiAtg9rniwGH2er3NWoe7Vb+yrNQdtxoj72I=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=mbwVx9+Z463LZ40UMQRWkQlL0L/+2YidxpL9w4bR8UzoDWOVy3aJTaH5pM8EsZGjT VCjkxPahOd3Sp/KgsS5f2i6/X2u9vnl4gxm6hnGbIdaoEO41jBjmY6FVK0VA9zu/gD PBC54hhYy6a3GYeXaA+n1X9XxTTj/y/s1wfWEbZAL1+v+M576tyY53rW1srzxG6jDg DDEgmwyGIdjhsQmKGlXQ7zFzf6xGL77VvSFTgFPMd+He+CfxpSBnabQs/vFqq4Z5UN 2KMfpOgKZM1FfIEQBwn0KACrJrn1fF/iaKFlKG2RQ1htzlSJmGlDrOUePY5AKEHxjG ERvXCo3+dTlsg== Message-ID: Date: Tue, 9 Jun 2026 16:28:31 +0200 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 RFC 00/15] mm/slab: introduce alloc_flags and slab_alloc_context Content-Language: en-US To: Usama Arif Cc: Harry Yoo , hao.ge@linux.dev, Hao Li , Christoph Lameter , David Rientjes , Roman Gushchin , Suren Baghdasaryan , Alexei Starovoitov , Andrew Morton , Johannes Weiner , Michal Hocko , Shakeel Butt , Alexander Potapenko , Marco Elver , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org References: <20260609133534.3548059-1-usama.arif@linux.dev> From: "Vlastimil Babka (SUSE)" Autocrypt: addr=vbabka@kernel.org; keydata= xsFNBFZdmxYBEADsw/SiUSjB0dM+vSh95UkgcHjzEVBlby/Fg+g42O7LAEkCYXi/vvq31JTB KxRWDHX0R2tgpFDXHnzZcQywawu8eSq0LxzxFNYMvtB7sV1pxYw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Cdi8OdU/+V+R3O4 0PXWvX8qrvqYapVbZ+9KqT74FsuB0Ya9uXwgBF2Q6cRuETZk5vqaqKxzqoQZCO8AOz/58j6O 2RHNy/mZEN+7tJ5Tsq42zVJ4jxsT8b9YplavCMsnBgDeRWhcbYhCyttoL7nYISyWg4kQYZ/P wIV3OuNv2f8iKYsxNsRuClOAF82+gvqOy1/1pprFjy8uo2pkoOrb63aOP3vO5VHnRKgra6dq NcaZ+c6J4H+nEJGi2SkHAUJz5oBzuThvPudLvPA/SK8sKoM01IRxSihev/S/5WLazXB1PGem OCbvzC1IjWJJraxiDJ5IygokapUa2RP7+WBR22skQ3SSl6G107QgWKSyTOGWEaRmV53vxQLV jXuCmzSSasTL60zq5yGrT4/DYQVSNEUiUbG4pYekxJujNeEDkUlky0Y= In-Reply-To: <20260609133534.3548059-1-usama.arif@linux.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 6/9/26 15:35, Usama Arif wrote: > On Tue, 09 Jun 2026 11:17:45 +0200 "Vlastimil Babka (SUSE)" wrote: > >> This series is based on slab/for-next. If all goes well, it would >> hopefully go to slab/for-next soon after the 7.2 merge window, so any >> other work can be based on it to avoid conflicts, as it touches a lot >> parts of slab. >> >> Git: https://git.kernel.org/pub/scm/linux/kernel/git/vbabka/linux.git/log/?h=b4/slab_alloc_flags >> >> The slab implementation currently relies on gfp flags to convey >> some context information internally: >> >> - The absence of both __GFP_RECLAIM flags is interpreted as "cannot spin >> on locks", and intended to be used by kmalloc_nolock(). But false >> positives are possible e.g. during early boot where gfp_allowed_mask >> clears __GFP_RECLAIM from all allocations. This leads to unnecessary >> allocation failures and workarounds such as fd3634312a04 ("debugobject: >> Make it work with deferred page initialization - again"). >> >> - __GFP_NO_OBJ_EXT exists and takes up valuable bit in the gfp flags >> space, only to prevent recursive kmalloc() allocations for obj_ext >> arrays and sheaves. >> > > Hello Valstimil! > > I think memory allocation profiling uses __GFP_NO_OBJ_EXT, and I dont see > it being removed in the series (hopefully I didnt miss it). > > Adding Hao Ge in CC who did this in the commit: > mm/alloc_tag: replace fixed-size early PFN array with dynamic linked list Thanks for the heads up. I missed it because my series is based on slab/for-next and that commit is in mm-unstable. My patch 15 actually modifies the TODO comment that is meanwhile resolved by Hao Ge's patch. Which means my patch 15/15 can't be used as-is, and at worst I will drop it. But I'd encourage Hao Ge with Suren to find some way to avoid the gfp flag usage too, because it's now quite a niche use case (preventing false positive CONFIG_MEM_ALLOC_PROFILING_DEBUG warnings, IIUC?) to take a valuable gfp flag bit, IMHO. >> The page allocator uses its internal alloc_flags to convey various >> context information, including ALLOC_TRYLOCK (meaning "cannot spin"). >> This series copies that concept for the slab allocator, with its own >> slab-specific internal flags: >> >> - SLAB_ALLOC_DEFAULT - no extra flags (the value is 0), but explicit >> - SLAB_ALLOC_TRYLOCK - do not spin on locks (used by kmalloc_nolock()) >> - SLAB_ALLOC_NEW_SLAB - replacing existing 'bool new_slab' parameter >> for allocating obj_ext arrays >> - SLAB_ALLOC_NO_RECURSE - replacing usage of __GFP_NO_OBJ_EXT >> >> To reduce the amount of parameters in various internal functions, we >> additionally introduce slab_alloc_context (also inspired by page >> allocator's alloc_context) for passing a number of existing arguments >> and the new alloc_flags: >> >> /* Structure holding extra parameters for slab allocations */ >> struct slab_alloc_context { >> unsigned long caller_addr; >> unsigned long orig_size; >> unsigned int alloc_flags; >> struct list_lru *lru; >> }; >> >> This also replaces the existing struct partial_context. >> >> The last necessary piece is kmalloc_flags() which can take the >> alloc_flags in addition to gfp flags and is intended for the recursive >> allocations of sheaves and obj_ext arrays, so that both >> SLAB_ALLOC_TRYLOCK and SLAB_ALLOC_NO_RECURSE can be communicated. >> Internally it decides between kmalloc_nolock() and normal kmalloc() >> depending SLAB_ALLOC_TRYLOCK. >> >> The rest of the series is gradually expanding the usage of both >> alloc_flags and slab_alloc_context as necessary, with bits of >> refactoring. Then, __GFP_NO_OBJ_EXT is removed completely. >> >> Note that some usage of gfpflags_allow_spinning() relying on absence of >> __GFP_RECLAIM remains outside of slab (and page allocator) in memcg, >> page_owner and stackdepot code. These can thus yield false-positive >> decisions that spinning is not allowed, but should not result in >> important allocations failing anymore. >> >> Signed-off-by: Vlastimil Babka (SUSE) >> --- >> Vlastimil Babka (SUSE) (15): >> mm/slab: always zero only requested size on alloc >> mm/slab: stop inlining __slab_alloc_node() >> mm/slab: introduce slab_alloc_context >> mm/slab: introduce alloc_flags and SLAB_ALLOC_TRYLOCK >> mm/slab: add alloc_flags to slab_alloc_context >> mm/slab: replace struct partial_context with slab_alloc_context >> mm/slab: pass alloc_flags to new slab allocation >> mm/slab: pass alloc_flags through slab_post_alloc_hook() chain >> mm/slab: replace slab_alloc_node() parameters with slab_alloc_context >> mm/slab: allow kmem_cache_alloc_bulk() with any gfp flags >> mm/slab: pass slab_alloc_context to __do_kmalloc_node() >> mm/slab: introduce kmalloc_flags() >> mm/slab: remove __GFP_NO_OBJ_EXT usage from alloc_slab_obj_exts() >> mm/slab: replace __GFP_NO_OBJ_EXT with SLAB_ALLOC_NO_RECURSE for sheaves >> mm: remove the __GFP_NO_OBJ_EXT flag >> >> include/linux/gfp_types.h | 7 - >> include/linux/slab.h | 14 +- >> include/trace/events/mmflags.h | 10 +- >> lib/alloc_tag.c | 2 +- >> mm/kfence/core.c | 6 +- >> mm/memcontrol.c | 5 +- >> mm/slab.h | 16 +- >> mm/slub.c | 423 ++++++++++++++++++++++++---------------- >> tools/include/linux/gfp_types.h | 7 - >> 9 files changed, 288 insertions(+), 202 deletions(-) >> --- >> base-commit: 500b2c9755301742bdbb61249511ac11a4665dae >> change-id: 20260601-slab_alloc_flags-25c782b0c57c >> >> Best regards, >> -- >> Vlastimil Babka (SUSE) >> >>