From patchwork Tue Sep 3 14:20:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13788789 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1B86CD343A for ; Tue, 3 Sep 2024 14:22:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D2DE8D017D; Tue, 3 Sep 2024 10:22:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 881C78D0151; Tue, 3 Sep 2024 10:22:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D3CB8D017D; Tue, 3 Sep 2024 10:22:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 49C0E8D0151 for ; Tue, 3 Sep 2024 10:22:42 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E668D1604EF for ; Tue, 3 Sep 2024 14:22:41 +0000 (UTC) X-FDA: 82523642922.28.7AC0A5E Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id 192C4A0002 for ; Tue, 3 Sep 2024 14:22:39 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=iC8yw4Sz; spf=pass (imf15.hostedemail.com: domain of brauner@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=brauner@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725373336; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lyceHmOdHcYpPumcL6F0x/Qy6aEh/eoDX6pXPbAt/0I=; b=X/SZnb9H8LfqYmNsW01bCFEtg7KQMBKnbwZMMmee7XwKDSRq4qs6ctue8bF7EP9YejZNK5 4mHq/kb3+zGl6MGn6Tjl/YzoHtEh+diyA2fvPUmD11lWfl/q72K1pwRRX27XHPnP9/47BR mDrMtjY75/TL3ioYpnoaC7/lAz5tsjM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=iC8yw4Sz; spf=pass (imf15.hostedemail.com: domain of brauner@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=brauner@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725373336; a=rsa-sha256; cv=none; b=FsWy6MXGHCe1X6T0o7YkWQYur2gUWAuoxVooDSVAb92vXHFGSsf0CsWsjn5AX6pGWcQOQI ASkHX0ziZDRkwE5a3MbcfTv3ULWxg00Klj9qSbJqcdpJRzoqGto0bY5yNih6y14s2/PsLR zcFHub6ZWhin9o6idJ83LO8guSZAtT4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D82B25C5816; Tue, 3 Sep 2024 14:22:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F9BDC4CECA; Tue, 3 Sep 2024 14:22:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725373359; bh=NICKa5KUOQG+AjRPua/q+Zy7rozMk7chEiygU85Xzfw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=iC8yw4SzaTmXOI0hC0s8OsuBU5aCzpjtbsOXChYJgSb+rOOw8TJqTrZReqPkClcGK ZNgy01bxU/uKUhxj7oMkaQhQAQx/3DyNu5CeaR/EV1moRwRvMHEMwMUAnyjEI/TDMW skD2yBxQE+vFthDy+IfReCtlevTldr3uCMhDIvE8Z+T4hQhePNd2ER/HHlrrFD/4JJ 0kGkpS2svFTSfpQC/Q40LPhG3ke3P4HRh3ee0tF902OveKbf7i3QXXtYpW3TGeBec6 Vrza4B7lPz457uYQqrZhBLocJthwFr5XglrmZMgfN9bATDcthv/vrHLusm04OqJSJH +goSwi9E619bA== From: Christian Brauner Date: Tue, 03 Sep 2024 16:20:48 +0200 Subject: [PATCH v2 07/15] slub: pull kmem_cache_open() into do_kmem_cache_create() MIME-Version: 1.0 Message-Id: <20240903-work-kmem_cache_args-v2-7-76f97e9a4560@kernel.org> References: <20240903-work-kmem_cache_args-v2-0-76f97e9a4560@kernel.org> In-Reply-To: <20240903-work-kmem_cache_args-v2-0-76f97e9a4560@kernel.org> To: Vlastimil Babka , Jens Axboe , Jann Horn , Linus Torvalds , Mike Rapoport Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Christian Brauner X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=4182; i=brauner@kernel.org; h=from:subject:message-id; bh=NICKa5KUOQG+AjRPua/q+Zy7rozMk7chEiygU85Xzfw=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaRdl55TEKXz8vYFK94ZvtNPxHhluBqE8J9eprm0vqG4t aFTqWhWRykLgxgXg6yYIotDu0m43HKeis1GmRowc1iZQIYwcHEKwETUFzAyHK382DX77OSW782/ Tyb0tolO+W8Z9G1hP99sobz366eZKTP8L/Lb0Wjtcnz14nu562PZJ+ZXWnRa+BqwelZ9XbLf9vo 9VgA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspam-User: X-St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l DfvzhFlY BYyEX82c/N5s0OGwf8Gkg5v1SRalzNEZtrP/4UOIrG3TO5hDcHNT+Z7ta5q2+vBcm4Yc8HTHyBYDJQyD7jisMrc7pDjPrViEYHS0N+WVkk9yQ9pZ7/pG1Lg+uWgSat9tjE631K52PVU3vVZ5BPU90gMFTGWJ9Mep9y7rdb5sj/lqKaN9CV760Y8qHBATGsT29r5ACnEtTF/ohG1pzXMtgRnx5MVAIzJl8bzsZ4x72I9K43Bw8NSjz7GcZyjkAtLpoZ4kCtt+OUpf3rSJRVsQxcM1gMDk81Vu05jFj X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: do_kmem_cache_create() is the only caller and we're going to pass down struct kmem_cache_args in a follow-up patch. Signed-off-by: Christian Brauner Reviewed-by: Mike Rapoport (Microsoft) --- mm/slub.c | 132 +++++++++++++++++++++++++++++--------------------------------- 1 file changed, 62 insertions(+), 70 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 23d9d783ff26..30f4ca6335c7 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5290,65 +5290,6 @@ static int calculate_sizes(struct kmem_cache *s) return !!oo_objects(s->oo); } -static int kmem_cache_open(struct kmem_cache *s, slab_flags_t flags) -{ - s->flags = kmem_cache_flags(flags, s->name); -#ifdef CONFIG_SLAB_FREELIST_HARDENED - s->random = get_random_long(); -#endif - - if (!calculate_sizes(s)) - goto error; - if (disable_higher_order_debug) { - /* - * Disable debugging flags that store metadata if the min slab - * order increased. - */ - if (get_order(s->size) > get_order(s->object_size)) { - s->flags &= ~DEBUG_METADATA_FLAGS; - s->offset = 0; - if (!calculate_sizes(s)) - goto error; - } - } - -#ifdef system_has_freelist_aba - if (system_has_freelist_aba() && !(s->flags & SLAB_NO_CMPXCHG)) { - /* Enable fast mode */ - s->flags |= __CMPXCHG_DOUBLE; - } -#endif - - /* - * The larger the object size is, the more slabs we want on the partial - * list to avoid pounding the page allocator excessively. - */ - s->min_partial = min_t(unsigned long, MAX_PARTIAL, ilog2(s->size) / 2); - s->min_partial = max_t(unsigned long, MIN_PARTIAL, s->min_partial); - - set_cpu_partial(s); - -#ifdef CONFIG_NUMA - s->remote_node_defrag_ratio = 1000; -#endif - - /* Initialize the pre-computed randomized freelist if slab is up */ - if (slab_state >= UP) { - if (init_cache_random_seq(s)) - goto error; - } - - if (!init_kmem_cache_nodes(s)) - goto error; - - if (alloc_kmem_cache_cpus(s)) - return 0; - -error: - __kmem_cache_release(s); - return -EINVAL; -} - static void list_slab_objects(struct kmem_cache *s, struct slab *slab, const char *text) { @@ -5904,26 +5845,77 @@ __kmem_cache_alias(const char *name, unsigned int size, unsigned int align, int do_kmem_cache_create(struct kmem_cache *s, slab_flags_t flags) { - int err; + int err = -EINVAL; - err = kmem_cache_open(s, flags); - if (err) - return err; + s->flags = kmem_cache_flags(flags, s->name); +#ifdef CONFIG_SLAB_FREELIST_HARDENED + s->random = get_random_long(); +#endif + + if (!calculate_sizes(s)) + goto out; + if (disable_higher_order_debug) { + /* + * Disable debugging flags that store metadata if the min slab + * order increased. + */ + if (get_order(s->size) > get_order(s->object_size)) { + s->flags &= ~DEBUG_METADATA_FLAGS; + s->offset = 0; + if (!calculate_sizes(s)) + goto out; + } + } + +#ifdef system_has_freelist_aba + if (system_has_freelist_aba() && !(s->flags & SLAB_NO_CMPXCHG)) { + /* Enable fast mode */ + s->flags |= __CMPXCHG_DOUBLE; + } +#endif + + /* + * The larger the object size is, the more slabs we want on the partial + * list to avoid pounding the page allocator excessively. + */ + s->min_partial = min_t(unsigned long, MAX_PARTIAL, ilog2(s->size) / 2); + s->min_partial = max_t(unsigned long, MIN_PARTIAL, s->min_partial); + + set_cpu_partial(s); + +#ifdef CONFIG_NUMA + s->remote_node_defrag_ratio = 1000; +#endif + + /* Initialize the pre-computed randomized freelist if slab is up */ + if (slab_state >= UP) { + if (init_cache_random_seq(s)) + goto out; + } + + if (!init_kmem_cache_nodes(s)) + goto out; + + if (!alloc_kmem_cache_cpus(s)) + goto out; /* Mutex is not taken during early boot */ - if (slab_state <= UP) - return 0; + if (slab_state <= UP) { + err = 0; + goto out; + } err = sysfs_slab_add(s); - if (err) { - __kmem_cache_release(s); - return err; - } + if (err) + goto out; if (s->flags & SLAB_STORE_USER) debugfs_slab_add(s); - return 0; +out: + if (err) + __kmem_cache_release(s); + return err; } #ifdef SLAB_SUPPORTS_SYSFS