From mboxrd@z Thu Jan 1 00:00:00 1970 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 1B49E3B9D91 for ; Fri, 15 May 2026 16:24:50 +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=1778862290; cv=none; b=STYxyCzz5S4iE6wLNFsszwDjv9LDCt1aWlcfl2LqztW1jJcdJvmauRiZQNQcZGEELoRiWC6fubvY1LwkPD3u+IYtzuMguc/T0uPzuvJ2hhvQpgfoXjnn1HTUCAMwcGGgkWZEP7YuI8Eb4olY4OHe4+EJj7U0GVbaTiAN9tgv7CA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862290; c=relaxed/simple; bh=p7E51ELkjQ3iEfoGMpm7cOapjWiciEbqUEy1lvQfStY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qpJ669Jrf9vpZ8g+sa65iCqlpl1XxRPaagV4AIRVOCgW8BwYp0KGZ9qHPBEhMM2iwTwQFJ+qC8sAZdd8xv1bo1DJC+eaoy6gLxk7m82ePoNsvTFqVN6KlfzPfNRrXqQxqq3l7AtZUl7tQx8ZAgXfAFBFli3nyu27i4Q2tlQ5I74= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Jdj/KuQR; 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="Jdj/KuQR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F31E1C2BCB0; Fri, 15 May 2026 16:24:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778862289; bh=p7E51ELkjQ3iEfoGMpm7cOapjWiciEbqUEy1lvQfStY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Jdj/KuQRERrRriQ2EslwPMUFvOg+0uZhQtj1KSxohVCK8GzSivJVkseWGyo5e80cV ZLrOgfCArxxH15U6/ohQWFmKr4zW611h7XtwPEzcy4+yLxLhjFR5d0LXXNfCK85G/6 ng/+GdVfghISC2xEnU+pO9vS9rC4+XHFmT6CQlua/YL78ZFlR4FjH9izhhwCjPHfzs GIo4x/TuGKBYrAfS/rGwrrMjbDF3H03Z6cSruHE2PvTQnT5Yequs/F8EAc6EVFi/Yj nW3sk3Jq9AE0dbYOQ+6u2e3LDtxlKt4WD0V9BLOdVmr3YtAGChkf6gfnJeNzWiDqAw 9bHNO0t7hCizw== From: "Harry Yoo (Oracle)" Date: Sat, 16 May 2026 01:24:28 +0900 Subject: [PATCH RFC 4/8] mm/slab: allow bootstrap_cache_sheaves() to fail 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: 7bit Message-Id: <20260516-sheaves-tuning-v1-4-221aa3e1d829@kernel.org> References: <20260516-sheaves-tuning-v1-0-221aa3e1d829@kernel.org> In-Reply-To: <20260516-sheaves-tuning-v1-0-221aa3e1d829@kernel.org> To: Vlastimil Babka , Andrew Morton , Hao Li , Christoph Lameter , David Rientjes , Roman Gushchin Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Suren Baghdasaryan , "Liam R. Howlett" X-Mailer: b4 0.16-dev Panicking on sheaf allocation failure is acceptable during boot, but to allow changing the sheaf capacity at runtime, the bootstrap path must be able to propagate errors instead. Return an error code from bootstrap_cache_sheaves() so callers can decide how to react. Change it to return an int (0 on success, negative errno on failure), accept capacity as a parameter, and drop __init. Callers without a user-specified capacity pass zero to use the default capacity calculated by the slab allocator. Failures are now handled by the caller. Signed-off-by: Harry Yoo (Oracle) --- mm/slub.c | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 44f36ae32570..fb98d0da5c78 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -8462,18 +8462,18 @@ static struct kmem_cache * __init bootstrap(struct kmem_cache *static_cache) * init_kmem_cache_nodes(). For normal kmalloc caches we have to bootstrap it * since sheaves and barns are allocated by kmalloc. */ -static void __init bootstrap_cache_sheaves(struct kmem_cache *s) +static int bootstrap_cache_sheaves(struct kmem_cache *s, + unsigned short capacity) { struct kmem_cache_args empty_args = {}; - unsigned short capacity; - bool failed = false; - int node, cpu; + int node, cpu, err = 0; - capacity = calculate_sheaf_capacity(s, &empty_args); + if (!capacity) + capacity = calculate_sheaf_capacity(s, &empty_args); /* capacity can be 0 due to debugging or SLUB_TINY */ if (!capacity) - return; + return 0; for_each_node_mask(node, slab_barn_nodes) { struct node_barn *barn; @@ -8481,7 +8481,7 @@ static void __init bootstrap_cache_sheaves(struct kmem_cache *s) barn = kmalloc_node(sizeof(*barn), GFP_KERNEL, node); if (!barn) { - failed = true; + err = -ENOMEM; goto out; } @@ -8497,31 +8497,37 @@ static void __init bootstrap_cache_sheaves(struct kmem_cache *s) pcs->main = __alloc_empty_sheaf(s, GFP_KERNEL, capacity); if (!pcs->main) { - failed = true; + err = -ENOMEM; break; } } out: - /* - * It's still early in boot so treat this like same as a failure to - * create the kmalloc cache in the first place - */ - if (failed) - panic("Out of memory when creating kmem_cache %s\n", s->name); + if (!err) + s->sheaf_capacity = capacity; - s->sheaf_capacity = capacity; + return err; } +#define for_each_normal_kmalloc_cache(s, type, idx) \ + for (type = KMALLOC_NORMAL; type <= KMALLOC_RANDOM_END; type++) \ + for (idx = 0; idx < KMALLOC_SHIFT_HIGH + 1; idx++) \ + if ((s = kmalloc_caches[type][idx])) + static void __init bootstrap_kmalloc_sheaves(void) { enum kmalloc_cache_type type; + struct kmem_cache *s; + int idx; - for (type = KMALLOC_NORMAL; type <= KMALLOC_RANDOM_END; type++) { - for (int idx = 0; idx < KMALLOC_SHIFT_HIGH + 1; idx++) { - if (kmalloc_caches[type][idx]) - bootstrap_cache_sheaves(kmalloc_caches[type][idx]); - } + for_each_normal_kmalloc_cache(s, type, idx) { + /* + * It's still early in boot so treat this as a failure to + * create the kmalloc cache in the first place. + */ + if (bootstrap_cache_sheaves(s, 0)) + panic("Out of memory when creating kmem_cache %s\n", + s->name); } } -- 2.43.0