]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
pid: reorder fields in pid_namespace to reduce false sharing
authorMateusz Guzik <mjguzik@gmail.com>
Tue, 20 Jan 2026 20:48:20 +0000 (21:48 +0100)
committerChristian Brauner <brauner@kernel.org>
Tue, 10 Feb 2026 10:39:30 +0000 (11:39 +0100)
alloc_pid() loads pid_cachep, level and pid_max prior to taking the
lock.

It dirties idr and pid_allocated with the lock.

Some of these fields share the cacheline as is, split them up.

No change in the size of the struct.

Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
Link: https://patch.msgid.link/20260120204820.1497002-1-mjguzik@gmail.com
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
include/linux/pid_namespace.h

index 0e7ae12c96d2aea1c8cd14ed3578f92e20317155..b20baaa7e62b755e7e561fcd8018e2b61213503e 100644 (file)
@@ -27,6 +27,13 @@ struct pid_namespace {
        struct idr idr;
        struct rcu_head rcu;
        unsigned int pid_allocated;
+#ifdef CONFIG_SYSCTL
+#if defined(CONFIG_MEMFD_CREATE)
+       int memfd_noexec_scope;
+#endif
+       struct ctl_table_set    set;
+       struct ctl_table_header *sysctls;
+#endif
        struct task_struct *child_reaper;
        struct kmem_cache *pid_cachep;
        unsigned int level;
@@ -40,13 +47,6 @@ struct pid_namespace {
        int reboot;     /* group exit code if this pidns was rebooted */
        struct ns_common ns;
        struct work_struct      work;
-#ifdef CONFIG_SYSCTL
-       struct ctl_table_set    set;
-       struct ctl_table_header *sysctls;
-#if defined(CONFIG_MEMFD_CREATE)
-       int memfd_noexec_scope;
-#endif
-#endif
 } __randomize_layout;
 
 extern struct pid_namespace init_pid_ns;