From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mxct.zte.com.cn (mxct.zte.com.cn [183.62.165.209]) (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 18C583803F1 for ; Tue, 26 May 2026 07:12:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=183.62.165.209 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779779539; cv=none; b=d4mAOUl0s2u9vOyeBbiTqcbTkSAGfXMuO8oeuF0VoYDx4KGXr/YxbmHVfJc5q5Mq9tC9VoCWQa9YRHed0p9vVvP43P985lnTz802o2cdKmzptKP30MEx28yzrTlUSgIseH3hXLd/vNi5nKRfm5y0EZUji0alYQj8srx4ca/im+U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779779539; c=relaxed/simple; bh=vKFJy8gCkoeMpsgEyT7f6pjt89Xk0cCBKHAEJY3+CpI=; h=Message-ID:In-Reply-To:References:Date:Mime-Version:From:To:Cc: Subject:Content-Type; b=OwDqKKgztWEiTIk0qD7sPIOcAJp+rFYRDZ3HyIU3gbBSdrEX7L49rJ9QPt5I/NH+FhXed3rgoML11lqiHGn3cDOv4hDTnTCbqye/7psv5D4dhGXD62XYCPGKwINbV00A455GsLHxAizY3YnWxWsCYrRYsollJmf6TcwrYUmBipI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn; spf=pass smtp.mailfrom=zte.com.cn; arc=none smtp.client-ip=183.62.165.209 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zte.com.cn Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mxct.zte.com.cn (FangMail) with ESMTPS id 4gPkTH75Rvz51Stv; Tue, 26 May 2026 15:12:03 +0800 (CST) Received: from xaxapp02.zte.com.cn ([10.88.97.241]) by mse-fl2.zte.com.cn with SMTP id 64Q7Bv8w008025; Tue, 26 May 2026 15:11:57 +0800 (+08) (envelope-from hu.shengming@zte.com.cn) Received: from mapi (xaxapp02[null]) by mapi (Zmail) with MAPI id mid32; Tue, 26 May 2026 15:11:59 +0800 (CST) X-Zmail-TransId: 2afa6a1547bff29-4dfea X-Mailer: Zmail v1.0 Message-ID: <20260526151159456kRq8QhhwO2mb6qdqY2_L-@zte.com.cn> In-Reply-To: References: 20260525211000387LYqTHmxYL900XIB8qwV3h@zte.com.cn,ahU1JTiy27FI9QaU@fedora Date: Tue, 26 May 2026 15:11:59 +0800 (CST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 From: To: Cc: , , , , , , , , , Subject: =?UTF-8?B?UmU6IFtQQVRDSCB2M10gbW0vc2x1YjogZnJlZSBwcmVmaWxsZWQgZW1wdHkgc2hlYXZlcyBjb25zaXN0ZW50bHk=?= Content-Type: text/plain; charset="UTF-8" X-MAIL:mse-fl2.zte.com.cn 64Q7Bv8w008025 X-TLS: YES X-ENVELOPE-SENDER: hu.shengming@zte.com.cn X-SOURCE-IP: 10.5.228.133 unknown Tue, 26 May 2026 15:12:04 +0800 X-CLEAN: YES X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6A1547C3.000/4gPkTH75Rvz51Stv Hao wrote: > On Mon, May 25, 2026 at 09:10:00PM +0800, hu.shengming@zte.com.cn wrote: > > From: Shengming Hu > > > > Empty sheaves allocated by alloc_empty_sheaf() should be released with > > free_empty_sheaf(). > > > > Move the empty-sheaf capacity initialization into __alloc_empty_sheaf() > > and use it for oversized prefilled sheaves as well. > > > > This keeps the prefill paths consistent: after flushing an oversized or > > pfmemalloc sheaf, release the now-empty sheaf through free_empty_sheaf() > > instead of kfree(). > > > > Signed-off-by: Shengming Hu > > --- > > Changes in v2: > > - Rework the change as suggested by Harry. > > - Teach __alloc_empty_sheaf() to initialize capacity and pfmemalloc. > > - Allocate oversized prefilled sheaves through __alloc_empty_sheaf(). > > - Free flushed oversized and pfmemalloc sheaves through free_empty_sheaf(). > > - Link to v1: https://lore.kernel.org/all/20260521195015105Y4zvKHj0TfPZEujixy9Vo@zte.com.cn/ > > > > Changes in v3: > > - Address Hao's comments: > > - Drop the redundant `pfmemalloc` initialization in > > __alloc_empty_sheaf(). > > - Keep initializing `capacity` and `pfmemalloc` in the normal-sized > > prefill path, since the sheaf may be reused rather than freshly > > allocated. > > - Link to v2: https://lore.kernel.org/all/20260522145900248m-nBcy07_SCDk2ATDWfmg@zte.com.cn/ > > > > --- > > mm/slub.c | 13 ++++--------- > > 1 file changed, 4 insertions(+), 9 deletions(-) > > > > diff --git a/mm/slub.c b/mm/slub.c > > index 04692a6f9128..f4c06bf43f2d 100644 > > --- a/mm/slub.c > > +++ b/mm/slub.c > > @@ -2782,6 +2782,7 @@ static struct slab_sheaf *__alloc_empty_sheaf(struct kmem_cache *s, gfp_t gfp, > > return NULL; > > > > sheaf->cache = s; > > + sheaf->capacity = capacity; > > > > stat(s, SHEAF_ALLOC); > > > > @@ -5015,21 +5016,15 @@ kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int size) > > > > if (unlikely(size > s->sheaf_capacity)) { > > > > - sheaf = kzalloc_flex(*sheaf, objects, size, gfp); > > + sheaf = __alloc_empty_sheaf(s, gfp, size); > > if (!sheaf) > > return NULL; > > > > stat(s, SHEAF_PREFILL_OVERSIZE); > > - sheaf->cache = s; > > - sheaf->capacity = size; > > > > - /* > > - * we do not need to care about pfmemalloc here because oversize > > - * sheaves area always flushed and freed when returned > > - */ > > just a bit curious, why did you decide to delete these comments? > Sorry about that. I removed the comment while moving the oversized sheaf allocation to __alloc_empty_sheaf(), because the local cache/capacity initialization was removed from this path. However, looking at it again, the comment is still worth. I will restore it in v4. Thanks a lot. > > if (!__kmem_cache_alloc_bulk(s, gfp, size, > > &sheaf->objects[0])) { > > - kfree(sheaf); > > + free_empty_sheaf(s, sheaf); > > return NULL; > > } > > > > @@ -5097,7 +5092,7 @@ void kmem_cache_return_sheaf(struct kmem_cache *s, gfp_t gfp, > > if (unlikely((sheaf->capacity != s->sheaf_capacity) > > || sheaf->pfmemalloc)) { > > sheaf_flush_unused(s, sheaf); > > - kfree(sheaf); > > + free_empty_sheaf(s, sheaf); > > return; > > } > > > > -- > > 2.25.1 -- With Best Regards, Shengming