From nobody Tue Apr 7 19:55:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CB6692C11CB for ; Wed, 11 Mar 2026 18:22:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773253365; cv=none; b=Q8LUgXjfw0iGYpmlJq0CbytE5/M0i7jsXMOCXS8LMrtOigwbnP5y7yAGfRphgQ7tSEALlYs9NtjtIb5MyKjZ/92lToG/wB7fUqkXxDatRap1UhsdmXANASds7DxCrImAN2JQBO0AISgAN1ZtHyMvASV0+bRxXSRED0K7RqfIU+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773253365; c=relaxed/simple; bh=0JJV5PdU67v1Ylt2HTvrKQMniMwA9sO7ZQpFQJb6PAo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=bXcw6CB6OQ8oAEet/B0ZGF5krYlJjy/nA7mZdpLv9vwoRFzUZYXslnqamH4OXeRcfthVUDx+TDOUBanfclAyJRujeMc6yZ0QxqeWCFWm7gVx0vcPQCaL+yAy57lNvQyoOCTwd7JXuWXjN64i6GqznBVeSfSRTIxbcMOel8l5Ij8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FmCu2eCm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FmCu2eCm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 736F3C19421; Wed, 11 Mar 2026 18:22:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773253365; bh=0JJV5PdU67v1Ylt2HTvrKQMniMwA9sO7ZQpFQJb6PAo=; h=From:Date:Subject:To:Cc:From; b=FmCu2eCmtf0r0qFr0xEHctcuykykfT/lLM3pc341wa0bEbIDmvHUpkS3KdzhDfqE/ VMaS+Lyh55nd/Q1W2kvSvkNQ6ycduW5miiOhty1UgyqJf1Oi82nHel/a+rZ1kolBcG MQdvuaeQ200g4k40Zwo0N7d9FyiBzsfD9RHNR3i+yYI+K7VeJqWcBOCaGPlZ3iSWPq qAYfNxG36ZqXhfoX5cCofjWJ3/xx/ZRcC94oIBRJkD3811MgeUCoLpaADmFMJQwP4F xoQlZ2bH/VJRZoDBfinbqWtBStkoA5BNe1JKgHIavKq491S1k2VQDzsWWyYLnohbKx 4Jkn3880W/V6w== From: "Vlastimil Babka (SUSE)" Date: Wed, 11 Mar 2026 19:22:33 +0100 Subject: [PATCH] slab: remove alloc_full_sheaf() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260311-b4-slab-remove-alloc_full_sheaf-v1-1-c4c5bb587ae5@kernel.org> X-B4-Tracking: v=1; b=H4sIAOiysWkC/x3NQQqEMAxA0atI1hNotSPiVYZBWk01EO3QoAji3 S2zfJv/L1DKTAp9dUGmg5XTVmBfFYyL32ZCnoqhNnVrGmsxOFTxATOt6SD0Imkc4i4y6EI+Ymi ccV1nJ/eOUCq/TJHP/+Hzve8HrSOsqHEAAAA= X-Change-ID: 20260311-b4-slab-remove-alloc_full_sheaf-b3404881d45f To: Harry Yoo Cc: Hao Li , Qing Wang , Andrew Morton , Christoph Lameter , David Rientjes , Roman Gushchin , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Vlastimil Babka (SUSE)" X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3535; i=vbabka@kernel.org; h=from:subject:message-id; bh=0JJV5PdU67v1Ylt2HTvrKQMniMwA9sO7ZQpFQJb6PAo=; b=owGbwMvMwMG4+8GG0kuuHbMYT6slMWRu3PT+7fsfsWfYmM3XLk9RVP3T9MbvkyjztlleVg410 dskvB26Ohn9WRgYORgsxRRZqnefcBSdqewxzcP3I8wgViaQKdIiDQxAwMLAl5uYV2qkY6Rnqm2o Zwhk6BgxcHEKwFSrzeNgWPCiaSL/r40pnnYv9kpbKbE//1xsdGNq4aWG02UBJ35VSO82PR3FI/D bt2ul9T6zdTt7NbMmql6dv3TyiWquz1EnDDZO4DlVfP6WeKfoI+WwZJmNW9K2L0nWXXnZN3zW0V 9rnn71YY1j4GxnfcTLIjPvwo60n29fP3+dfjJ2omJf/umDXhvk68t05T9YXmj9Em2y/ex65W+7n 0rO3bn6woesD1n3Hi+a22DQWTH1QaXTzLyeZ1syO666zpH04QlkYZhvzGg/b9fuDT1Ky4N22fUz TH7Y0rpWOrK+4Kr/5Z7lu8S4Z3ZKlvA6+F7eevKpH4sNZ7Lu7UN2L+pEl2XEmn61V8lY7MMk1fK rRmbhQQA= X-Developer-Key: i=vbabka@kernel.org; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 The function allocates and then refills and empty sheaf. It's only called from __pcs_replace_empty_main(), which can also in some cases refill an empty sheaf. We can therefore consolidate this code. Remove alloc_full_sheaf() and refactor __pcs_replace_empty_main() so it will call alloc_empty_sheaf() when necessary, and then use the pre-existing refill_sheaf(). The result should be simpler to follow and less duplicated code. Also adjust the comment about returning sheaves to barn, the part about where the empty sheaf we'd be returning comes from is incorrect. No functional change intended. Signed-off-by: Vlastimil Babka (SUSE) Reviewed-by: Hao Li Reviewed-by: Harry Yoo Reviewed-by: Qing Wang --- Just something I noticed when applying Qing's hotfix, thus a followup. But since it's a cleanup, it would be for 7.1. --- mm/slub.c | 57 ++++++++++++++++++++------------------------------------- 1 file changed, 20 insertions(+), 37 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 2b2d33cc735c..a8347b79e46f 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2822,24 +2822,6 @@ static int refill_sheaf(struct kmem_cache *s, struct= slab_sheaf *sheaf, return 0; } =20 -static void sheaf_flush_unused(struct kmem_cache *s, struct slab_sheaf *sh= eaf); - -static struct slab_sheaf *alloc_full_sheaf(struct kmem_cache *s, gfp_t gfp) -{ - struct slab_sheaf *sheaf =3D alloc_empty_sheaf(s, gfp); - - if (!sheaf) - return NULL; - - if (refill_sheaf(s, sheaf, gfp | __GFP_NOMEMALLOC | __GFP_NOWARN)) { - sheaf_flush_unused(s, sheaf); - free_empty_sheaf(s, sheaf); - return NULL; - } - - return sheaf; -} - /* * Maximum number of objects freed during a single flush of main pcs sheaf. * Translates directly to an on-stack array size. @@ -4611,34 +4593,35 @@ __pcs_replace_empty_main(struct kmem_cache *s, stru= ct slub_percpu_sheaves *pcs, if (!allow_spin) return NULL; =20 - if (empty) { - if (!refill_sheaf(s, empty, gfp | __GFP_NOMEMALLOC | __GFP_NOWARN)) { - full =3D empty; - } else { - /* - * we must be very low on memory so don't bother - * with the barn - */ - sheaf_flush_unused(s, empty); - free_empty_sheaf(s, empty); - } - } else { - full =3D alloc_full_sheaf(s, gfp); + if (!empty) { + empty =3D alloc_empty_sheaf(s, gfp); + if (!empty) + return NULL; } =20 - if (!full) + if (refill_sheaf(s, empty, gfp | __GFP_NOMEMALLOC | __GFP_NOWARN)) { + /* + * we must be very low on memory so don't bother + * with the barn + */ + sheaf_flush_unused(s, empty); + free_empty_sheaf(s, empty); + return NULL; + } + + full =3D empty; + empty =3D NULL; =20 if (!local_trylock(&s->cpu_sheaves->lock)) goto barn_put; pcs =3D this_cpu_ptr(s->cpu_sheaves); =20 /* - * If we are returning empty sheaf, we either got it from the - * barn or had to allocate one. If we are returning a full - * sheaf, it's due to racing or being migrated to a different - * cpu. Breaching the barn's sheaf limits should be thus rare - * enough so just ignore them to simplify the recovery. + * If we put any empty or full sheaf to the barn below, it's due to + * racing or being migrated to a different cpu. Breaching the barn's + * sheaf limits should be thus rare enough so just ignore them to + * simplify the recovery. */ =20 if (pcs->main->size =3D=3D 0) { --- base-commit: 464b1c115852fe025635ae2065e00caced184d92 change-id: 20260311-b4-slab-remove-alloc_full_sheaf-b3404881d45f Best regards, --=20 Vlastimil Babka (SUSE)