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 DEFD51DE4E0 for ; Wed, 27 May 2026 15:47:39 +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=1779896861; cv=none; b=ux7P2CQg9+9fD1qKQOU981G5c7XxbVfddHprZCb78M58b4lT4AHJWOlnr0O/W77kPHMix3YoJUlYjRc2yWkwDeRzyLqtgtmx+UnZSF1+BC96f4C2tDdNO3aKMyvCABAPV8WNPAVs+B9p837mTasXhCxyF0WVEVhXHW8SP3D7LSM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779896861; c=relaxed/simple; bh=dPMbzXcMdlOeV8bA9ojmoG9cTRmkFpW1+8uOhVh8H3A=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=XSzZlUwwZYHEQHptLR6GFH0rA3b1KL0fvqt9OC+Tu9tCO1ruUK8nxZDeL1qtYCj3k6m12DBYsLKN/+f9cIoGsvEucmUsw1mckxok0RQMEtKuQZdWAJ9I7OpiE7bHXDhPQB1WNvngCGy93WfNoShtvobITXFEdobPQB/wKCUc84A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U2gGzh0u; 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="U2gGzh0u" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D8441F000E9; Wed, 27 May 2026 15:47:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779896859; bh=A1LehxyQXtk2uo55XzhchktGNtxckIshURQweL13HfQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=U2gGzh0u9Qc22u2OKtAf7paVQHXrypMrIvhRvWgE31Xp+8iSb332QEX0GhjQevIPz WJJendkr7hgEe2syxLHu6wYxyF9mZJ87SfdXQEk0xsYDun9HujLrQr1TT9gXLZsniG 4km/nd5J5+09uvDDE1bqEkk51N3EobmFefOOJXMX2pBYdomuSOkUIvFw59zeGvfiSG /Tjqjg3sykk4liJMNl0q0A9OVxGy0ICosRnKSmVzBuL1LnqFOBXyqqbvCL5GVse+dq XzH9au9rJsElTFsDIg78BAlGWNM18a2Df1k3MCfVHL5ygUBLm70J8JI0GNs7Pi7W2j mPPu33g5XptDw== Message-ID: <44b8ba46-a002-4668-ab99-4bf01f4b66e5@kernel.org> Date: Wed, 27 May 2026 17:47:35 +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 v4] mm/slub: use empty sheaf helpers for oversized sheaves Content-Language: en-US To: hu.shengming@zte.com.cn, Suren Baghdasaryan Cc: harry@kernel.org, akpm@linux-foundation.org, hao.li@linux.dev, cl@gentwo.org, rientjes@google.com, roman.gushchin@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, zhang.run@zte.com.cn, cai.qu@zte.com.cn References: <20260527214840093l-oER8Ds4tJLCyI14we0S@zte.com.cn> From: "Vlastimil Babka (SUSE)" Autocrypt: addr=vbabka@kernel.org; keydata= xsFNBFZdmxYBEADsw/SiUSjB0dM+vSh95UkgcHjzEVBlby/Fg+g42O7LAEkCYXi/vvq31JTB KxRWDHX0R2tgpFDXHnzZcQywawu8eSq0LxzxFNYMvtB7sV1pxYwej2qx9B75qW2plBs+7+YB 87tMFA+u+L4Z5xAzIimfLD5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uB0Ya9uXwgBF2Q6cRuETZk5vqaqKxzqoQZCO8AOz/58j6O 2RHNy/mZEN+7tJ5Tsq42zVJ4jxsT8b9YplavCMsnBgDeRWhcbYhCyttoL7nYISyWg4kQYZ/P wIV3OuNv2f8iKYsxNsRuClOAF82+gvqOy1/1pprFjy8uo2pkoOrb63aOP3vO5VHnRKgra6dq NcaZ+c6J4H+nEJGi2SkHAUJz5oBzuThvPudLvPA/SK8sKoM01IRxSihev/S/5WLazXB1PGem OCbvzC1IjWJJraxiDJ5IygokapUa2RP7+WBR22skQ3SSl6G107QgWKSyTOGWEaRmV53vxQLV jXuCmzSSasTL60zq5yGrT4/DYQVSNEUiUbG4pYekxJujNeEDkUlky0Y= In-Reply-To: <20260527214840093l-oER8Ds4tJLCyI14we0S@zte.com.cn> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 5/27/26 15:48, hu.shengming@zte.com.cn wrote: > VlastimilBabka(SUSE) wrote: >> On 5/26/26 17:24, hu.shengming@zte.com.cn wrote: >> > From: Shengming Hu >> > >> > Oversized prefilled sheaves are allocated separately, but after they are >> > flushed they are empty sheaves as well. Release them through >> > free_empty_sheaf() instead of calling kfree() directly. >> > >> > Use __alloc_empty_sheaf() for oversized prefilled sheaves as well, so >> > that they are allocated through the same helper as regular empty sheaves >> > and released through the matching helper. >> > >> > Since oversized sheaves are now allocated and freed through the empty >> > sheaf helpers, SHEAF_ALLOC and SHEAF_FREE also account for oversized >> > sheaves. Update the stat comments accordingly. >> > >> > This keeps the oversized and pfmemalloc prefill paths consistent after >> > flushing. >> > >> > Signed-off-by: Shengming Hu >> >> Hmm, __alloc_empty_sheaf() does "gfp &= ~OBJCGS_CLEAR_MASK" which includes >> __GFP_NOFAIL. A caller of kmem_cache_prefill_sheaf() with __GFP_NOFAIL might >> not expect failure. The __GFP_NO_OBJ_EXT handling is also not necessary for >> prefilled sheaves. >> >> Well maybe all the gfp handling could be simply moved to >> alloc_empty_sheaf()? The other caller of __alloc_empty_sheaf() is >> bootstrap_cache_sheaves() and I think it doesn't need it either. >> > > Thanks for the review! > > I agree that clearing OBJCGS_CLEAR_MASK in __alloc_empty_sheaf() > is not right for the oversized prefill path. In particular, it changes > the caller-provided GFP flags and can drop __GFP_NOFAIL. I will move that > part out of __alloc_empty_sheaf(). > > I am less sure about moving the __GFP_NO_OBJ_EXT handling out of > __alloc_empty_sheaf() as well, because that seems to make the free side > more complicated. > > Currently free_empty_sheaf() assumes that sheaves for SLAB_KMALLOC caches > were allocated with __GFP_NO_OBJ_EXT, and therefore calls > mark_obj_codetag_empty() before kfree(). If __GFP_NO_OBJ_EXT is moved out > of __alloc_empty_sheaf(), then oversized prefilled sheaves allocated by > the raw helper would not have that flag anymore, while regular sheaves > allocated through alloc_empty_sheaf() would still have it. > > In that case, the return path could no longer use one free helper for both > oversized and pfmemalloc sheaves after flushing. It would need to split > the two cases, for example: > > if (unlikely(sheaf->capacity != s->sheaf_capacity)) { > sheaf_flush_unused(s, sheaf); > __free_empty_sheaf(s, sheaf); > return; > } > > if (unlikely(sheaf->pfmemalloc)) { > sheaf_flush_unused(s, sheaf); > free_empty_sheaf(s, sheaf); > return; > } > > There is also the bootstrap_cache_sheaves() case. The sheaves allocated > there are regular-sized sheaves. If such a sheaf later reaches > kmem_cache_return_sheaf(), it could not safely be released through > free_empty_sheaf() unless it was also allocated with __GFP_NO_OBJ_EXT, > because free_empty_sheaf() currently assumes that SLAB_KMALLOC sheaves > were allocated with __GFP_NO_OBJ_EXT and calls mark_obj_codetag_empty(). > Unlike oversized sheaves, these bootstrap-created sheaves have the regular > capacity, so the return path cannot distinguish them by > sheaf->capacity != s->sheaf_capacity. > > So I wonder if it would be better to move only the OBJCGS_CLEAR_MASK > clearing out of __alloc_empty_sheaf(), but keep the __GFP_NO_OBJ_EXT > handling there. That would fix the __GFP_NOFAIL issue for oversized > prefilled sheaves, while still keeping the allocation/free assumptions > consistent and allowing flushed oversized and pfmemalloc sheaves to use > the same free_empty_sheaf() path. > > Would this approach be acceptable, or did I misunderstand your suggestion? I see, thanks. Could we perhaps move the mark_obj_codetag_empty() code to alloc_empty_sheaf()? If not, then do as you suggest? > > -- > With Best Regards, > Shengming