| From: |
| Christian Brauner <brauner-AT-kernel.org> |
| To: |
| Josef Bacik <josef-AT-toxicpanda.com>, Jeff Layton <jlayton-AT-kernel.org> |
| Subject: |
| [PATCH v2 0/8] fs: lockless mntns lookup |
| Date: |
| Thu, 12 Dec 2024 12:55:59 +0100 |
| Message-ID: |
| <20241212-work-mount-rbtree-lockless-v2-0-4fe6cef02534@kernel.org> |
| Cc: |
| "Paul E. McKenney" <paulmck-AT-kernel.org>, Peter Ziljstra <peterz-AT-infradead.org>, linux-fsdevel-AT-vger.kernel.org, Christian Brauner <brauner-AT-kernel.org> |
| Archive-link: |
| Article |
Hey,
Currently we take the read lock when looking for a mount namespace to
list mounts in. We can make this lockless. The simple search case can
just use a sequence counter to detect concurrent changes to the rbtree.
For walking the list of mount namespaces sequentially via nsfs we keep a
separate rcu list as rb_prev() and rb_next() aren't usable safely with
rcu.
Since creating mount namespaces is a relatively rare event compared with
querying mounts in a foreign mount namespace this is worth it. Once
libmount and systemd pick up this mechanism to list mounts in foreign
mount namespaces this will be used very frequently.
doing.
Thanks!
Christian
---
Changes in v2:
- Remove mnt_ns_find_it_at() by switching to rb_find_rcu().
- Add separate list to lookup sequential mount namespaces.
- Link to v1: https://lore.kernel.org/r/20241210-work-mount-rbtree-lock...
---
Christian Brauner (8):
mount: remove inlude/nospec.h include
fs: add mount namespace to rbtree late
fs: lockless mntns rbtree lookup
rculist: add list_bidir_{del,prev}_rcu()
fs: lockless mntns lookup for nsfs
fs: simplify rwlock to spinlock
selftests: remove unneeded include
samples: add test-list-all-mounts
fs/mount.h | 20 +--
fs/namespace.c | 158 ++++++++++++++---------
fs/nsfs.c | 5 +-
include/linux/rculist.h | 43 +++++++
samples/vfs/.gitignore | 1 +
samples/vfs/Makefile | 2 +-
samples/vfs/test-list-all-mounts.c | 235 ++++++++++++++++++++++++++++++++++
tools/testing/selftests/pidfd/pidfd.h | 1 -
8 files changed, 387 insertions(+), 78 deletions(-)
---
base-commit: 40384c840ea1944d7c5a392e8975ed088ecf0b37
change-id: 20241207-work-mount-rbtree-lockless-7d4071b74f18