From nobody Mon Jun 8 15:48:20 2026 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [160.30.148.34]) (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 620A82820C6 for ; Thu, 28 May 2026 11:35:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=160.30.148.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779968152; cv=none; b=tD1iyjmW2X2Zt68D6TBWzMnKp2jJZt6JxagLgKQXwStRTB3tbdJWlMQTzy4AZOyJEqMdGqRxSXNatZxte6aFKdAfA0f/UIoGg6lLXkXBWQRnugA5GrVzI3sCOxerEEL0VoY4xADeEz6ZX8l0PBH6xShzQh0wRZRZgEs/1Ht23bg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779968152; c=relaxed/simple; bh=YDLGIjhj8PqUKWoVi8PdlxxN9fxNAhrMdIxQ3mrLv4Q=; h=Message-ID:Date:Mime-Version:From:To:Cc:Subject:Content-Type; b=OfsJYZndPF4FAfLXdFuMFfJ6++S3VgX7EHXemqyYQGT20GcmK3ZqncsLA/aFZHU2elldVuVCYxKooTcPlUnHhmVpXojuuGENzWnMhtxa1JZNooHDElu8Ph3i66rrUthvuV6SJDhxAAeLpZRavUj8BnxgfTFhbN7HEE9o5wuyUn8= 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.34 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 mxhk.zte.com.cn (FangMail) with ESMTPS id 4gR4DZ1FDPz5BNS0; Thu, 28 May 2026 19:35:42 +0800 (CST) Received: from xaxapp04.zte.com.cn ([10.99.98.157]) by mse-fl2.zte.com.cn with SMTP id 64SBZY8q019030; Thu, 28 May 2026 19:35:35 +0800 (+08) (envelope-from hu.shengming@zte.com.cn) Received: from mapi (xaxapp02[null]) by mapi (Zmail) with MAPI id mid32; Thu, 28 May 2026 19:35:37 +0800 (CST) X-Zmail-TransId: 2afa6a18288917d-17382 X-Mailer: Zmail v1.0 Message-ID: <20260528193537623nAo-xYBNYBysGKSBjREuO@zte.com.cn> Date: Thu, 28 May 2026 19:35:37 +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?W1BBVENIIHY1XSBtbS9zbHViOiB1c2UgZW1wdHkgc2hlYWYgaGVscGVycyBmb3Igb3ZlcnNpemVkIHNoZWF2ZXM=?= X-MAIL: mse-fl2.zte.com.cn 64SBZY8q019030 X-TLS: YES X-SPF-DOMAIN: zte.com.cn X-ENVELOPE-SENDER: hu.shengming@zte.com.cn X-SPF: None X-SOURCE-IP: 10.5.228.133 unknown Thu, 28 May 2026 19:35:42 +0800 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6A18288E.000/4gR4DZ1FDPz5BNS0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Shengming Hu Oversized prefilled sheaves are allocated separately because their capacity can be larger than the cache's regular sheaf capacity. After they are flushed, however, they are empty sheaves as well, and should be released through the same empty-sheaf helper. Allocate oversized prefilled sheaves with __alloc_empty_sheaf() and free them with free_empty_sheaf() after a failed prefill or after they are returned and flushed. This keeps the oversized and pfmemalloc return paths consistent, including the SLAB_KMALLOC-specific __GFP_NO_OBJ_EXT and mark_obj_codetag_empty() handling. Keep the caller-GFP filtering in alloc_empty_sheaf() instead of __alloc_empty_sheaf(). In particular, do not clear OBJCGS_CLEAR_MASK in the raw helper, so the oversized prefill path does not unexpectedly drop caller-provided flags such as __GFP_NOFAIL. The SLAB_KMALLOC-specific addition of __GFP_NO_OBJ_EXT remains in __alloc_empty_sheaf(), matching the free_empty_sheaf() assumption. 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. Keep the capacity initialization in the oversized prefill path, since capacity is currently only used for prefilled sheaves Signed-off-by: Shengming Hu Reviewed-by: Hao Li Reviewed-by: Harry Yoo (Oracle) --- 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/ 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_SCDk2AT= DWfmg@zte.com.cn/ Changes in v4: - Address comments from Hao and Harry: - Keep capacity initialization in the oversized prefill path. - Update SHEAF_ALLOC and SHEAF_FREE comments to mention oversized sheaves. - Restore the oversized sheaf pfmemalloc comment. - Link to v3: https://lore.kernel.org/all/20260525211000387LYqTHmxYL900XIB8= qwV3h@zte.com.cn/ Changes in v5: - Address VlastimilBabka's comments: - Move caller-GFP filtering from __alloc_empty_sheaf() to alloc_empty_sheaf(): - keep the __GFP_NO_OBJ_EXT rejection for regular empty sheaves; - keep OBJCGS_CLEAR_MASK clearing out of the raw helper, so oversized prefilled sheaves do not lose caller-provided flags such as __GFP_NOFAIL. - Keep the SLAB_KMALLOC-specific __GFP_NO_OBJ_EXT addition in __alloc_empty_sheaf(), so allocations still match the free_empty_sheaf() and mark_obj_codetag_empty() handling. - Link to v4: https://lore.kernel.org/all/20260526232429176aHA6oZjTYdhXcZVH= c2ZQ-@zte.com.cn/ --- mm/slub.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 04692a6f9128..8663ce4ae1b0 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -362,8 +362,8 @@ enum stat_item { CMPXCHG_DOUBLE_FAIL, /* Failures of slab freelist update */ SHEAF_FLUSH, /* Objects flushed from a sheaf */ SHEAF_REFILL, /* Objects refilled to a sheaf */ - SHEAF_ALLOC, /* Allocation of an empty sheaf */ - SHEAF_FREE, /* Freeing of an empty sheaf */ + SHEAF_ALLOC, /* Allocation of an empty sheaf including oversized ones */ + SHEAF_FREE, /* Freeing of an empty sheaf including oversized ones */ BARN_GET, /* Got full sheaf from barn */ BARN_GET_FAIL, /* Failed to get full sheaf from barn */ BARN_PUT, /* Put full sheaf to barn */ @@ -2762,11 +2762,6 @@ static struct slab_sheaf *__alloc_empty_sheaf(struct= kmem_cache *s, gfp_t gfp, struct slab_sheaf *sheaf; size_t sheaf_size; - if (gfp & __GFP_NO_OBJ_EXT) - return NULL; - - gfp &=3D ~OBJCGS_CLEAR_MASK; - /* * Prevent recursion to the same cache, or a deep stack of kmallocs of * varying sizes (sheaf capacity might differ for each kmalloc size @@ -2791,6 +2786,11 @@ static struct slab_sheaf *__alloc_empty_sheaf(struct= kmem_cache *s, gfp_t gfp, static inline struct slab_sheaf *alloc_empty_sheaf(struct kmem_cache *s, gfp_t gfp) { + if (gfp & __GFP_NO_OBJ_EXT) + return NULL; + + gfp &=3D ~OBJCGS_CLEAR_MASK; + return __alloc_empty_sheaf(s, gfp, s->sheaf_capacity); } @@ -5015,12 +5015,11 @@ 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; /* @@ -5029,7 +5028,7 @@ kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t = gfp, unsigned int size) */ if (!__kmem_cache_alloc_bulk(s, gfp, size, &sheaf->objects[0])) { - kfree(sheaf); + free_empty_sheaf(s, sheaf); return NULL; } @@ -5097,7 +5096,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