From: Christian Brauner <brauner@kernel.org>
To: linux-fsdevel@vger.kernel.org, Josef Bacik <josef@toxicpanda.com>,
Jeff Layton <jlayton@kernel.org>
Cc: "Jann Horn" <jannh@google.com>, "Mike Yuan" <me@yhndnzj.com>,
"Zbigniew Jędrzejewski-Szmek" <zbyszek@in.waw.pl>,
"Lennart Poettering" <mzxreary@0pointer.de>,
"Daan De Meyer" <daan.j.demeyer@gmail.com>,
"Aleksa Sarai" <cyphar@cyphar.com>,
"Amir Goldstein" <amir73il@gmail.com>,
"Tejun Heo" <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Jan Kara" <jack@suse.cz>,
linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
bpf@vger.kernel.org, "Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
netdev@vger.kernel.org, "Arnd Bergmann" <arnd@arndb.de>,
"Christian Brauner" <brauner@kernel.org>
Subject: [PATCH 12/17] ns: make all reference counts on initial namespace a nop
Date: Mon, 10 Nov 2025 16:08:24 +0100 [thread overview]
Message-ID: <20251110-work-namespace-nstree-fixes-v1-12-e8a9264e0fb9@kernel.org> (raw)
In-Reply-To: <20251110-work-namespace-nstree-fixes-v1-0-e8a9264e0fb9@kernel.org>
They are always active so no need to needlessly cacheline ping-pong.
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
include/linux/ns_common.h | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/include/linux/ns_common.h b/include/linux/ns_common.h
index b9e8f21a6984..5b8f2f0163d7 100644
--- a/include/linux/ns_common.h
+++ b/include/linux/ns_common.h
@@ -62,6 +62,8 @@ static __always_inline __must_check int __ns_ref_active_read(const struct ns_com
static __always_inline __must_check bool __ns_ref_put(struct ns_common *ns)
{
+ if (is_ns_init_id(ns))
+ return false;
if (refcount_dec_and_test(&ns->__ns_ref)) {
VFS_WARN_ON_ONCE(__ns_ref_active_read(ns));
return true;
@@ -71,6 +73,8 @@ static __always_inline __must_check bool __ns_ref_put(struct ns_common *ns)
static __always_inline __must_check bool __ns_ref_get(struct ns_common *ns)
{
+ if (is_ns_init_id(ns))
+ return true;
if (refcount_inc_not_zero(&ns->__ns_ref))
return true;
VFS_WARN_ON_ONCE(__ns_ref_active_read(ns));
@@ -82,12 +86,27 @@ static __always_inline __must_check int __ns_ref_read(const struct ns_common *ns
return refcount_read(&ns->__ns_ref);
}
+static __always_inline void __ns_ref_inc(struct ns_common *ns)
+{
+ if (is_ns_init_id(ns))
+ return;
+ refcount_inc(&ns->__ns_ref);
+}
+
+static __always_inline __must_check bool __ns_ref_dec_and_lock(struct ns_common *ns,
+ spinlock_t *ns_lock)
+{
+ if (is_ns_init_id(ns))
+ return false;
+ return refcount_dec_and_lock(&ns->__ns_ref, ns_lock);
+}
+
#define ns_ref_read(__ns) __ns_ref_read(to_ns_common((__ns)))
-#define ns_ref_inc(__ns) refcount_inc(&to_ns_common((__ns))->__ns_ref)
+#define ns_ref_inc(__ns) __ns_ref_inc(to_ns_common((__ns)))
#define ns_ref_get(__ns) __ns_ref_get(to_ns_common((__ns)))
#define ns_ref_put(__ns) __ns_ref_put(to_ns_common((__ns)))
-#define ns_ref_put_and_lock(__ns, __lock) \
- refcount_dec_and_lock(&to_ns_common((__ns))->__ns_ref, (__lock))
+#define ns_ref_put_and_lock(__ns, __ns_lock) \
+ __ns_ref_dec_and_lock(to_ns_common((__ns)), __ns_lock)
#define ns_ref_active_read(__ns) \
((__ns) ? __ns_ref_active_read(to_ns_common(__ns)) : 0)
--
2.47.3
next prev parent reply other threads:[~2025-11-10 15:09 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-10 15:08 [PATCH 00/17] ns: header cleanups and initial namespace reference count improvements Christian Brauner
2025-11-10 15:08 ` [PATCH 01/17] ns: move namespace types into separate header Christian Brauner
2025-11-10 15:08 ` [PATCH 02/17] nstree: decouple from ns_common header Christian Brauner
2025-11-10 15:08 ` [PATCH 03/17] nstree: move nstree types into separate header Christian Brauner
2025-11-10 15:08 ` [PATCH 04/17] nstree: add helper to operate on struct ns_tree_{node,root} Christian Brauner
2025-11-10 15:08 ` [PATCH 05/17] nstree: switch to new structures Christian Brauner
2025-11-10 15:08 ` [PATCH 06/17] nstree: simplify owner list iteration Christian Brauner
2025-11-10 15:08 ` [PATCH 07/17] nstree: use guards for ns_tree_lock Christian Brauner
2025-11-10 15:08 ` [PATCH 08/17] ns: make is_initial_namespace() argument const Christian Brauner
2025-11-10 15:08 ` [PATCH 09/17] ns: rename is_initial_namespace() Christian Brauner
2025-11-10 15:08 ` [PATCH 10/17] fs: use boolean to indicate anonymous mount namespace Christian Brauner
2025-11-10 15:08 ` [PATCH 11/17] ipc: enable is_ns_init_id() assertions Christian Brauner
2025-11-10 15:08 ` Christian Brauner [this message]
2025-11-10 15:08 ` [PATCH 13/17] ns: add asserts for initial namespace reference counts Christian Brauner
2025-11-10 15:08 ` [PATCH 14/17] ns: add asserts for initial namespace active " Christian Brauner
2025-11-10 15:08 ` [PATCH 15/17] pid: rely on common reference count behavior Christian Brauner
2025-11-10 15:08 ` [PATCH 16/17] ns: drop custom reference count initialization for initial namespaces Christian Brauner
2025-11-14 19:27 ` Thomas Gleixner
2025-11-10 15:08 ` [PATCH 17/17] selftests/namespaces: fix nsid tests Christian Brauner
2025-11-13 11:03 ` [PATCH 00/17] ns: header cleanups and initial namespace reference count improvements Jan Kara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251110-work-namespace-nstree-fixes-v1-12-e8a9264e0fb9@kernel.org \
--to=brauner@kernel.org \
--cc=amir73il@gmail.com \
--cc=arnd@arndb.de \
--cc=bpf@vger.kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=cyphar@cyphar.com \
--cc=daan.j.demeyer@gmail.com \
--cc=edumazet@google.com \
--cc=hannes@cmpxchg.org \
--cc=jack@suse.cz \
--cc=jannh@google.com \
--cc=jlayton@kernel.org \
--cc=josef@toxicpanda.com \
--cc=kuba@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=me@yhndnzj.com \
--cc=mzxreary@0pointer.de \
--cc=netdev@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=zbyszek@in.waw.pl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).