From patchwork Tue Sep 3 14:20:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13788782 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 221B7CD343A for ; Tue, 3 Sep 2024 14:22:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 993998D0176; Tue, 3 Sep 2024 10:22:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 942C28D0151; Tue, 3 Sep 2024 10:22:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80AE08D0176; Tue, 3 Sep 2024 10:22:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 62CB08D0151 for ; Tue, 3 Sep 2024 10:22:26 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0573D80132 for ; Tue, 3 Sep 2024 14:22:25 +0000 (UTC) X-FDA: 82523642292.27.B4A665E Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf06.hostedemail.com (Postfix) with ESMTP id 3901518001A for ; Tue, 3 Sep 2024 14:22:24 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aXg9pTFQ; spf=pass (imf06.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=1725373249; 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=/p0nqZ5qDhgNqgTbR6ahfmoo5EVIQXAs3iIcvwDbAR4=; b=ZzrX+VcNO5020BrEcinLsuUXWEDAczQYsP92R+Vfz4LVPZmGvFzP3EN4nxLg+BJVccyjXC RxDmRwb3ZAEsQvVoDJKkqisavBwycNYIPiuQK+fSujXh7hKGXQOIUP87ABTSb3x4UsasoX TIwHhNAC+/vmQrrUxQbGWyLDU0OBZz4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725373249; a=rsa-sha256; cv=none; b=JPu6Ge59tlQqPWUTkvXRRJAPChQ8wg3fsrk+1uB1zMLCRtfxCU/QZWEaABtqNvr5Hq0gXT +ZtH1tyI47S0PRb+mZsvEDGZwa84DVwTPYjH8MqbyvBOqF8N7z3K1F0L3R+y1EThdMIbBj sBgOxVGRNWhjD4POK7aQ8XQLtPyM9G8= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aXg9pTFQ; spf=pass (imf06.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 2FAD4A43677; Tue, 3 Sep 2024 14:22:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 375FDC4CEC4; Tue, 3 Sep 2024 14:22:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725373343; bh=/5+W8BUQgxXjxU+Pa51Xbo+dm4yfnXGJFSuXL945Ubw=; h=From:Subject:Date:To:Cc:From; b=aXg9pTFQ8zcmMViTrn/8DMUlrjtw5eatUvN7vHL7oRI8/qfVhhsukABvdadkxiD0A KxfpHs9gdoY6ul9XWaRpdoiOCRMkUo1r72DnX3nmAi7UrvYOYTxVbzBJQhdoRXD8w+ 4c7cwSWO0/i2Gsfw3lWni0ljKtF5MBqODkUj9btxutL/+vKcQshBlCgUMwCOF/e7Cq RLNNBXk+BsmypR4OI7RPYbmL/0lc6TSlGfbfL053IXpw2RFUbmCdr1PQbdirQVbRJz WcRVtWaphLC/5sISZbrA5k3yFj5ZChH732nwp3GEC5ao2SpxtYKeza8zWjna4EooJB U1AII108MmE0g== From: Christian Brauner Subject: [PATCH v2 00/15] slab: add struct kmem_cache_args Date: Tue, 03 Sep 2024 16:20:41 +0200 Message-Id: <20240903-work-kmem_cache_args-v2-0-76f97e9a4560@kernel.org> MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIADob12YC/4WOQQqDMBREryJZNxKDNrUr71FEYvyaj5qUn5K2i Hdv9AJdPph5MxsLQAiB3bONEUQM6F0CecmYsdpNwHFIzKSQpaiF5G9PM59XWDujjYVO0xQ41Oo qaiWNGkqWqk+CET+n9tEm7nUA3pN2xh6yOIZ8xAWOqMXw8vQ9D8TiKPzZigUXXKpBVL0RVSFvz QzkYMk9Tazd9/0Ho6aZldQAAAA= 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=3587; i=brauner@kernel.org; h=from:subject:message-id; bh=/5+W8BUQgxXjxU+Pa51Xbo+dm4yfnXGJFSuXL945Ubw=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaRdl54typIQP/+OXdzHTV/PyJ6ab3LPecXNTO6/Ck5Cg fM5Tomyd5SyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAEzEv4nhf+acR1+UFWTLLbQl 5zMEzfWxa4iTW1o/cX/qum2zeX84BTP801BnXT7ncNOOyb2JK1+JfTStvTXtYfnNzUE3zzFWz7T NYwMA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3901518001A X-Stat-Signature: wjwtiiyn9go3rwk48cs9d5fitye6xyky X-HE-Tag: 1725373344-276270 X-HE-Meta: U2FsdGVkX18DjNGza5/9k0oU20kXzpFf+d33TxDTTUf98YT1qy0IncDgHi3/JkH2SeR9/LfetjCK6xISkzQcxyeffj8K7lSrN1Ya4rInpYb20hKbqDUVYukKigdZsXBZ7opUBy7O6vLSF9n/QLMRkLU6V9rwBFP5Oz8/ha/owbOsTI7HMki+4Wu0bA9Me/mi3MLt1CqlFE8wUMEn13eBfxR1zDY5It2VnlYBkABbbm+wPwAo4xleDmxlShPKZaJwEhOU0zxcl7BAPoir54O5aEZ15h1yVLXqAEIbs9qtpWZKZQ6ZtwK3FB+wMDX2kMMO7KHeifJOzenhM8xtu7QpvbWqi7lgPWDlLwaf3P1V6h/yZD1h4sUouSxZSFzZNwVab8MaP+6i6gCA49wmpAWyO7U9D2zPQRNmfrgfWKxbGok5oeuxhNQbaf+d/pQXN8nm/PJhyZZhqUbpEbRvls2Si67o8pVUxKA/GX0OHpJw/CpQhrpeeGOYgmfh22W3MZWefAEaAkrHwy1WbY3//fUOVXUYMDxk66r11AgFpX+N3wcw/jJf5+7bO2n0TqKdHwjVo6tiJq/ALIVWbemZVzJAdmn3APL3zcz0WYdZgJcyVObC1jo9t9Nm0HCmmB5i2VABNuIAD3nz3s/rtHwinQU4bPE513jGV4cV/p1PlK9bOcrun0IC+QNcfAccZ1dl+PTWKmVUpXtTozODfVbDMwlBiM3bCnGBJukzjZsWohMh6/JbD+8v2EWdKqSPhj0M1V47+vFLHtLljzIsprtEtNpFmnTHejE9cTjFgitmcGLsxJCX8tXCm04gyhmEvDPnsDlhFIApNuzudREa90aFxYCUnolKjVt/z4XcOIP8A3gUZ8RokZxLH7wgQ9vSegDrbUISNPqM0qjX7kf1rizGGXzXyYVfz2A1XQ9zTQxESViq6S4celb8zmp31YiXZwEQ4HksDER+LwVFWeA6WtzfdmS SHDxgtY5 CM+FaQYkLsVUMQ6IY0/wJHs9GqyZCHDiGD3mX6ALeMUbxdcvx8U4GUjdIkpPS4H1VLp/ScuIsJJGu2DOFhHQ+myUdMs11A4IX3HUqqRxy4voZo/s3neXwEyeXOgOkywAI2zYCFpS4E9hqPeFLY9EqTTtYj0WH9jA1c9Vj+3FyG3gcbFTksnjwBQLa7cClNqGFNW+eqVqwObgaKO8bsXYUef+3OqFMzlEEGc5CJhjkYAFqAwpqhavelAJkpcZDyFNp4EFD5dPGXUOAjrgBcjdW86LTZQ8hnw5Zh0DD 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, 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 Reviewed-by: Kees Cook Reviewed-by: Jens Axboe Reviewed-by: Vlastimil Babka --- 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 (15): sl*b: 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() slub: pull kmem_cache_open() into do_kmem_cache_create() slab: pass struct kmem_cache_args to do_kmem_cache_create() sl*b: 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() io_uring: port to struct kmem_cache_args fs/file_table.c | 11 +++- include/linux/slab.h | 60 ++++++++++++++----- io_uring/io_uring.c | 14 +++-- mm/slab.h | 6 +- mm/slab_common.c | 150 +++++++++++++++++++---------------------------- mm/slub.c | 162 +++++++++++++++++++++++++-------------------------- 6 files changed, 203 insertions(+), 200 deletions(-) --- base-commit: 6e016babce7c845ed015da25c7a097fa3482d95a change-id: 20240902-work-kmem_cache_args-e9760972c7d4