From patchwork Thu Sep 5 07:56:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13791880 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 DF12FCD4F5B for ; Thu, 5 Sep 2024 07:57:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 716006B01A3; Thu, 5 Sep 2024 03:57:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6EBEE6B01A4; Thu, 5 Sep 2024 03:57:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B3378D0001; Thu, 5 Sep 2024 03:57:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3C7FF6B01A3 for ; Thu, 5 Sep 2024 03:57:07 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B79FA1C4C02 for ; Thu, 5 Sep 2024 07:57:06 +0000 (UTC) X-FDA: 82529928852.15.B9A496C Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf20.hostedemail.com (Postfix) with ESMTP id 0B4011C0010 for ; Thu, 5 Sep 2024 07:57:04 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RUIzIhLb; spf=pass (imf20.hostedemail.com: domain of brauner@kernel.org designates 147.75.193.91 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=1725522976; 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: references:dkim-signature; bh=LfeeGmmQxO6bQOY8CbQ/1el9yBwolGY4BI1IMh+UggI=; b=56ojz8ZJ4wkETrCI4jljcgp/b83xg4qdwKdtfbXWGCxwhaLn2oeaMyzB+JBk4jUJhBw2TR igYn+p7gky3m18Wdpb1uFxXYIYv3vCHQD5qf3/rvhxgkc5xuYDoJWeJ94lj2YNzuXDvkr3 07PSFFUxJTWM2kfMLnQIlAyvXaaQlKY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RUIzIhLb; spf=pass (imf20.hostedemail.com: domain of brauner@kernel.org designates 147.75.193.91 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=1725522976; a=rsa-sha256; cv=none; b=SxyNZveX8akaGkcQ8VHcUybHGwSVy0+SMEQ/c/iy8yeVrbwjALxLWcULX0NpjMVzKOFgZU 4PlR3ebEGab4RIdFn+QkcalFeCSTQhigcJNIWtoc1Iv+QoZyXz8BSn/KN4nO0UwxKL4Xbb 9epFhtpHhfJn0PtPMD2QkYye+iOKROg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id EF83CA431BC; Thu, 5 Sep 2024 07:56:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DFCCC4CEC3; Thu, 5 Sep 2024 07:57:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523023; bh=BmsQjTGSfRDhmsoE1J1AfilYRU8gY8cnWKKMi7Hz+Xo=; h=From:Subject:Date:To:Cc:From; b=RUIzIhLbUtgwRcSoD6rQn/ee5RVbJZNmn2VN+vTwV0PmAYVF7hMaDykpieG/V00Ua wtbrjbGOtUF+JUR8Drd+7YFecOQlQP3AJzTuGOiXDKrls/252S/4GN6FWMnys5lrN5 Jr4Os/eAPrz4qJT4+SUtukqH9pRGvYm1v5uUlKLZmpQKUvWKkrlCWEklJn7v0z8itM 6ivzJ8uWKdJIf4fyotxowkcXco+KLuQGmbPc3ZZyoDxhFQMs40+7UEH8sxypO6SdzE afW9M0m53q84SK41PhC1bq0tTBTjpnisC6RCuPdySNU8LNryOBbwi1BxTpwr38fxEE cyPZsJohft4Sw== From: Christian Brauner Subject: [PATCH v4 00/17] slab: add struct kmem_cache_args Date: Thu, 05 Sep 2024 09:56:43 +0200 Message-Id: <20240905-work-kmem_cache_args-v4-0-ed45d5380679@kernel.org> MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIADtk2WYC/4XOQQrCMBAF0KtI1kam07QxrryHiKTptA3VViYSF endTV0pIi4/zH9/HiIQewpis3gIpuiDH4cU1HIhXGeHlqSvUxYIqMAAyuvIvexPdDo46zo6WG6 DJKNLMBqdrpVI1TNT428vdrdPubKBZMV2cN2MxSasGn+k+bTz4TLy/fVAzObCn62YSZCoaygqB 0WG621PPNBxNXIr5rGI70r+Q8Gk6LIxmoxVRQlfSv6uqB9KnhQo6gozbeza4YcyTdMTDuafCmA BAAA= To: Vlastimil Babka , Jens Axboe , Jann Horn , Linus Torvalds , Mike Rapoport Cc: Kees Cook , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, 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=4355; i=brauner@kernel.org; h=from:subject:message-id; bh=BmsQjTGSfRDhmsoE1J1AfilYRU8gY8cnWKKMi7Hz+Xo=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdTPG6kH10lgWDahBb1mKbq5KK550O7P7xLGndO5810 jsMdJnSO0pZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACay5A/D/9IZuyt5j8Wucdr7 c23uhFWhSzYWMSrzeHybNrVp4zTlx/sZ/un2qfluX7x6cZLNS6sX2wySvsbG3zWa4X5x7ULtTRO /NjIAAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 0B4011C0010 X-Stat-Signature: 1yx9nsc4ff9tk3pzs85dgg4po1axby9z X-HE-Tag: 1725523024-854091 X-HE-Meta: U2FsdGVkX1+Dl2Bu6Q7JBbugx60nG8wLTEG+aqdxox5YBolAjMHdRElxwApMP9Hz1csbr7mhBOeqjixpocM9c5seFb9ylemrKgpImfmzTOxRim3S9hg0HE2yicl0Xd+WrGKi9trf56JqRAUYXhw3gAzoT0I89kRIKYvVrhfTyI9C5EWlw5HRkbgPWGa4xMrfRu6r7WXyJUkRlj+vMPL6xPUzzpDKGPdPtzzl9EL4wgh4jjBA0IWRF9dp+wKRzcJlwfTVcXin5uasLPIs/bnFm4a8+oagcoxc1Y+LmDFSvaDkd/6Le6wAaXTrrlaQOLp7oSNpb+daLc3+QWJ+QvO6WkzYI+6rVrxO30KArQ+l8eGqtJ3FzuY884sbcyeqRm+A7O9Z74ym1z3lDr5KLXgm8dtJau2Sa1gNGR/P/GYxeIa0IvEHjp82k0usF/CE6/hdRemUHxIw9dJyDA2lwcifARNXBAsmvKq4gghhae8n6GglqAqAyfMOBnKBCDqCPRw5rNRAEsOkL2zwZhAGJ6kzfmqbTe+tNdZadctCtAUqxtM0Leiw/e42G7od1a7UoO9NkDroUtwC4eNuwlgwIJoaQZMmxH8TmrUp2xAqB4bN99sZ9oSzEpSULPEPeg1+1iidn/4tmaGxzkQUE62gtdxUzeoFa2gGpzmops0i1W4u1lwCGbqwzMqM6z61utQFeEESE/377iKEopVIjmd7fXVkSNvyc+os+ZgBSI97ONsSsplgwchSyuswID+UlUTf7/dNKdYHHgmH798PICMbIQ2vN+Db9JEykEVvdG10AlhPhcP9Q8wnSSqn8aztmcAEoyFYK+0Ms/Uk8QChgOTCf6yGJvF37cH1ic3pcZ8jmLTjish7CTUpeKLKGqYlbyRMCDWXHV6Bgr5XFbpUZDl1jPtXQU0DgiF1urgPYQx8x7RKTSIRvA6PrsH47QCPKyaq+xObfMHmHrniafR6t8vz9O3 lRelkLZW TP5Yp1wGt1zm3GydN18YFKnw57yXUBfondlZ2RWG/Ix+AE3i1VMWfb6asQrUSthgW1pADW+tzZhTYugvLjpcgWfGPj1avZ3om477THNE1QrZ2rOdnCiyJhnU83XylPOybkeUXotgK4f9d6AcbScAhvBxEbo3aoWsPk97DCLaADcuj8Z4GxNHYxHvj6SrnH8c1EpbBXkXQ5s7oeILiJ6x5Z//dzt0Gh1HEGQxxVWLoAZEGFXg6T/OKpIi0ARN7ZgBJmkAZQ2JincHSh8FYuBYcf6g7yoSXAU4hNO77DnnIZG3tRjGs7unIfmbvfaoUV0S3SA6jl0FwHMc+cd3kTF6ptOr1v4TGPwKiHJJSwftd4ub2y4k= 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: Hey, This is v4 which allows NULL to be passed in the struct kmem_cache_args argument of kmem_cache_create() and substitutes default parameters in this case. As discussed last week the various kmem_cache_*() functions should be replaced by a unified function that is based around a struct, with only the basic parameters passed separately. Vlastimil already said that he would like to keep core parameters out of the struct: name, object size, and flags. I personally don't care much and would not object to moving everything into the struct but that's a matter of taste and I yield that decision power to the maintainer. In the first version I pointed out that the choice of name is somewhat forced as kmem_cache_create() is taken and the only way to reuse it would be to replace all users in one go. Or to do a global sed/kmem_cache_create()/kmem_cache_create2()/g. And then introduce kmem_cache_setup(). That doesn't strike me as a viable option. If we really cared about the *_create() suffix then an alternative might be to do a sed/kmem_cache_setup()/kmem_cache_create()/g after every user in the kernel is ported. I honestly don't think that's worth it but I wanted to at least mention it to highlight the fact that this might lead to a naming compromise. However, I came up with an alternative using _Generic() to create a compatibility layer that will call the correct variant of kmem_cache_create() depending on whether struct kmem_cache_args is passed or not. That compatibility layer can stay in place until we updated all calls to be based on struct kmem_cache_args. From a cursory grep (and not excluding Documentation mentions) we will have to replace 44 kmem_cache_create_usercopy() calls and about 463 kmem_cache_create() calls which makes for a bit above 500 calls to port to kmem_cache_setup(). That'll probably be good work for people getting into kernel development. Signed-off-by: Christian Brauner --- Changes in v4: - Allow NULL to be passed in the struct kmem_cache_args argument of kmem_cache_create() and use default parameters in this case. - Link to v3: https://lore.kernel.org/r/20240904-work-kmem_cache_args-v3-0-05db2179a8c2@kernel.org Changes in v3: - Reworded some commit messages. - Picked up various RvBs. - Added two patches to make two functions static inline. - Link to v2: https://lore.kernel.org/r/20240903-work-kmem_cache_args-v2-0-76f97e9a4560@kernel.org Changes in v2: - Remove kmem_cache_setup() and add a compatibility layer built around _Generic() so that we can keep the kmem_cache_create() name and type switch on the third argument to either call __kmem_cache_create() or __kmem_cache_create_args(). - Link to v1: https://lore.kernel.org/r/20240902-work-kmem_cache_args-v1-0-27d05bc05128@kernel.org --- Christian Brauner (17): slab: s/__kmem_cache_create/do_kmem_cache_create/g slab: add struct kmem_cache_args slab: port kmem_cache_create() to struct kmem_cache_args slab: port kmem_cache_create_rcu() to struct kmem_cache_args slab: port kmem_cache_create_usercopy() to struct kmem_cache_args slab: pass struct kmem_cache_args to create_cache() slab: pull kmem_cache_open() into do_kmem_cache_create() slab: pass struct kmem_cache_args to do_kmem_cache_create() slab: remove rcu_freeptr_offset from struct kmem_cache slab: port KMEM_CACHE() to struct kmem_cache_args slab: port KMEM_CACHE_USERCOPY() to struct kmem_cache_args slab: create kmem_cache_create() compatibility layer file: port to struct kmem_cache_args slab: remove kmem_cache_create_rcu() slab: make kmem_cache_create_usercopy() static inline slab: make __kmem_cache_create() static inline io_uring: port to struct kmem_cache_args fs/file_table.c | 11 ++- include/linux/slab.h | 130 +++++++++++++++++++++++++++------ io_uring/io_uring.c | 14 ++-- mm/slab.h | 6 +- mm/slab_common.c | 197 +++++++++++---------------------------------------- mm/slub.c | 162 +++++++++++++++++++++--------------------- 6 files changed, 250 insertions(+), 270 deletions(-) --- base-commit: 6e016babce7c845ed015da25c7a097fa3482d95a change-id: 20240902-work-kmem_cache_args-e9760972c7d4