From nobody Sun May 24 19:35:20 2026 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [160.30.148.35]) (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 1EA04332EA2 for ; Fri, 22 May 2026 06:59:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=160.30.148.35 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779433158; cv=none; b=tvIElwjdTXLvmcR/224ZOsB1jrbjlRsNMkh1X4Cu+ZwMH1vLbgx183thQf+dKLbKadeQGvwrFDevX5/iau5Ldy2loc2P/SDyZ/YII4i+MJcNJQE+Deob7F6fDFRylMSQgv9fG36LaOjjuWBC3rKt/afilShsJ6obsMB700i2hCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779433158; c=relaxed/simple; bh=Fqf8ndlaK2MnlJUkdKpmGiK1MW8vcwGfq5dxrInovhU=; h=Message-ID:Date:Mime-Version:From:To:Cc:Subject:Content-Type; b=uKjnfZ6HhtvVebCVfKoxFUhcTjfSmcijcLnTEIc+P8TWfm8O3lQqJcHzbfvA0Rb0PSBZN+l9u48NE4J0fwvXAf6oQJTgb0kZ5lzJL6p11zxFkwnOpykfX/G7tuCS9aw5Q+or9/aPe/Vy3w80ijIduIje0dSfc7fJkegLkLrXBKo= 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=160.30.148.35 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-fl1.zte.com.cn (unknown [10.5.228.132]) (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 mxhk.zte.com.cn (FangMail) with ESMTPS id 4gMGNC2gFVz8XrrJ; Fri, 22 May 2026 14:59:07 +0800 (CST) Received: from xaxapp02.zte.com.cn ([10.88.97.241]) by mse-fl1.zte.com.cn with SMTP id 64M6wwj6027824; Fri, 22 May 2026 14:58:58 +0800 (+08) (envelope-from hu.shengming@zte.com.cn) Received: from mapi (xaxapp02[null]) by mapi (Zmail) with MAPI id mid32; Fri, 22 May 2026 14:59:00 +0800 (CST) X-Zmail-TransId: 2afa6a0ffeb4e96-7a2a0 X-Mailer: Zmail v1.0 Message-ID: <20260522145900248m-nBcy07_SCDk2ATDWfmg@zte.com.cn> Date: Fri, 22 May 2026 14:59:00 +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?W1BBVENIIHYyXSBtbS9zbHViOiBmcmVlIHByZWZpbGxlZCBlbXB0eSBzaGVhdmVzIGNvbnNpc3RlbnRseQ==?= X-MAIL: mse-fl1.zte.com.cn 64M6wwj6027824 X-TLS: YES X-ENVELOPE-SENDER: hu.shengming@zte.com.cn X-SOURCE-IP: 10.5.228.132 unknown Fri, 22 May 2026 14:59:07 +0800 X-CLEAN: YES X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6A0FFEBB.000/4gMGNC2gFVz8XrrJ Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Shengming Hu Empty sheaves allocated by alloc_empty_sheaf() should be released with free_empty_sheaf(). Move the common empty-sheaf initialization into __alloc_empty_sheaf(), including the capacity and default pfmemalloc state, 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/20260521195015105Y4zvKHj0TfPZEuji= xy9Vo@zte.com.cn/ --- mm/slub.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 04692a6f9128..bbe8351f1bfa 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2782,6 +2782,8 @@ static struct slab_sheaf *__alloc_empty_sheaf(struct = kmem_cache *s, gfp_t gfp, return NULL; sheaf->cache =3D s; + sheaf->capacity =3D capacity; + sheaf->pfmemalloc =3D false; stat(s, SHEAF_ALLOC); @@ -5015,21 +5017,15 @@ kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_= t gfp, unsigned int size) if (unlikely(size > s->sheaf_capacity)) { - sheaf =3D kzalloc_flex(*sheaf, objects, size, gfp); + sheaf =3D __alloc_empty_sheaf(s, gfp, size); if (!sheaf) return NULL; stat(s, SHEAF_PREFILL_OVERSIZE); - sheaf->cache =3D s; - sheaf->capacity =3D size; - /* - * we do not need to care about pfmemalloc here because oversize - * sheaves area always flushed and freed when returned - */ if (!__kmem_cache_alloc_bulk(s, gfp, size, &sheaf->objects[0])) { - kfree(sheaf); + free_empty_sheaf(s, sheaf); return NULL; } @@ -5064,9 +5060,6 @@ kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t = gfp, unsigned int size) sheaf =3D alloc_empty_sheaf(s, gfp); if (sheaf) { - sheaf->capacity =3D s->sheaf_capacity; - sheaf->pfmemalloc =3D false; - if (sheaf->size < size && __prefill_sheaf_pfmemalloc(s, sheaf, gfp)) { sheaf_flush_unused(s, sheaf); @@ -5097,7 +5090,7 @@ void kmem_cache_return_sheaf(struct kmem_cache *s, gf= p_t gfp, if (unlikely((sheaf->capacity !=3D s->sheaf_capacity) || sheaf->pfmemalloc)) { sheaf_flush_unused(s, sheaf); - kfree(sheaf); + free_empty_sheaf(s, sheaf); return; } --=20 2.25.1