From patchwork Tue Aug 27 15:59:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13779769 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 671571CDA24 for ; Tue, 27 Aug 2024 16:00:04 +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=1724774404; cv=none; b=uu0cex2Y898k6DOjHevITz+cinVUeDU3k0UQ+4KplnxcCZtECEC3beEqN8+qNbxG3Q+ZyM2VNVXL/syngFZNfvPCRUodc0A5lyuVK1kTyYiwCOpmQdomhPOtnc8UON39y7DSCcf5zYdbb+hshXWm7eHKrVBhbmzrkVcbwtQRkX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724774404; c=relaxed/simple; bh=DE+gGtjVtEol42ZCGLAdc2sv/qn+B/OiKlktxCin3uE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UxQeQ6DkWI6NcqAAYcaYn1vHmDgccpMImL1euQ24of7XTFDgHUmsx+bwdkCXSVjeEJK484MCCvqjNwM7VyHHSF05eL/k+JcHNP95uQi+cGUbY/GVTQ6C+ymdM83CNnsS8WZTJdHoCgM7Pnazl0cRxRH6OpjPsm0saQwCfph2uaQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XDQq7ZjD; 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="XDQq7ZjD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 783A1C4FE07; Tue, 27 Aug 2024 16:00:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724774404; bh=DE+gGtjVtEol42ZCGLAdc2sv/qn+B/OiKlktxCin3uE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XDQq7ZjDwI8AC6Fj1oxAsuHrCGy9En+5jUbhNv0Hn009zPn4EP5k3gaSgiWsMIcmU v1aYprobuu5S8xNKWJJRLEpZ9Sn9FF9ZUjueUF9l2gAqAkHuB4G/via8om737bC4R7 s5ZFwup6mp0rtIPfyiegT5qfOvoG1HTnQupT70d7fQ2dqldnbQnk/T1tsD8Bfh+qGr JDkeBjOVndsuv1YbThNR/Y41t72q5vvxcypc6aj4ziqaQPe/U2JBo1+GjPpfSj1qPm yHjMC+JW2U2I1LdAjG6yiIVsNj5C6xrXW28N561WPBYxapRMufCgNcRPSZDMcUx28L 3xzdoo92Hg9NA== From: Christian Brauner Date: Tue, 27 Aug 2024 17:59:44 +0200 Subject: [PATCH v2 3/3] fs: use kmem_cache_create_rcu() Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240827-work-kmem_cache-rcu-v2-3-7bc9c90d5eef@kernel.org> References: <20240827-work-kmem_cache-rcu-v2-0-7bc9c90d5eef@kernel.org> In-Reply-To: <20240827-work-kmem_cache-rcu-v2-0-7bc9c90d5eef@kernel.org> To: Vlastimil Babka , Jens Axboe , "Paul E. McKenney" , Roman Gushchin , Jann Horn , Linus Torvalds , linux-mm@kvack.org Cc: Christian Brauner , linux-fsdevel@vger.kernel.org X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=1379; i=brauner@kernel.org; h=from:subject:message-id; bh=DE+gGtjVtEol42ZCGLAdc2sv/qn+B/OiKlktxCin3uE=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaSd/f7767KcLA/hXX+3aE6tvXhpOj9fz6VNL8v+yF7fO GGj0dxcjo5SFgYxLgZZMUUWh3aTcLnlPBWbjTI1YOawMoEMYeDiFICJcKUw/C95ceaBUq2q+/RX X04fzUt9zn6zW5GxcvKWiepRa62Ss4UZ/lcZel3xF2AyljeveZNyn7PvRPK98DnzdspOlFy3QcT qCSMA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Switch to the new kmem_cache_create_rcu() helper which allows us to use a custom free pointer offset avoiding the need to have an external free pointer which would grow struct file behind our backs. Signed-off-by: Christian Brauner --- fs/file_table.c | 6 +++--- include/linux/fs.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/file_table.c b/fs/file_table.c index 694199a1a966..83d5ac1fadc0 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -514,9 +514,9 @@ EXPORT_SYMBOL(__fput_sync); void __init files_init(void) { - filp_cachep = kmem_cache_create("filp", sizeof(struct file), 0, - SLAB_TYPESAFE_BY_RCU | SLAB_HWCACHE_ALIGN | - SLAB_PANIC | SLAB_ACCOUNT, NULL); + filp_cachep = kmem_cache_create_rcu("filp", sizeof(struct file), + offsetof(struct file, f_freeptr), + SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT); percpu_counter_init(&nr_files, 0, GFP_KERNEL); } diff --git a/include/linux/fs.h b/include/linux/fs.h index 61097a9cf317..12a72f162da7 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1057,6 +1057,7 @@ struct file { struct callback_head f_task_work; struct llist_node f_llist; struct file_ra_state f_ra; + freeptr_t f_freeptr; }; /* --- cacheline 3 boundary (192 bytes) --- */ } __randomize_layout