mounts: keep list of mounts in an rbtree
authorMiklos Szeredi <mszeredi@redhat.com>
Wed, 25 Oct 2023 14:02:00 +0000 (16:02 +0200)
committerChristian Brauner <brauner@kernel.org>
Sat, 18 Nov 2023 13:56:16 +0000 (14:56 +0100)
commit2eea9ce4310d8c0f8ef1dbe7b0e7d9219ff02b97
tree6e1759ae01554e15a6d7b92d4a243f469deaa5b2
parent98d2b43081972abeb5bb5a087bc3e3197531c46e
mounts: keep list of mounts in an rbtree

When adding a mount to a namespace insert it into an rbtree rooted in the
mnt_namespace instead of a linear list.

The mnt.mnt_list is still used to set up the mount tree and for
propagation, but not after the mount has been added to a namespace.  Hence
mnt_list can live in union with rb_node.  Use MNT_ONRB mount flag to
validate that the mount is on the correct list.

This allows removing the cursor used for reading /proc/$PID/mountinfo.  The
mnt_id_unique of the next mount can be used as an index into the seq file.

Tested by inserting 100k bind mounts, unsharing the mount namespace, and
unmounting.  No performance regressions have been observed.

For the last mount in the 100k list the statmount() call was more than 100x
faster due to the mount ID lookup not having to do a linear search.  This
patch makes the overhead of mount ID lookup non-observable in this range.

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Link: https://lore.kernel.org/r/20231025140205.3586473-3-mszeredi@redhat.com
Reviewed-by: Ian Kent <raven@themaw.net>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/mount.h
fs/namespace.c
fs/pnode.c
fs/proc_namespace.c
include/linux/mount.h