• Miklos Szeredi's avatar
    mounts: keep list of mounts in an rbtree · 2eea9ce4
    Miklos Szeredi authored
    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: default avatarMiklos Szeredi <mszeredi@redhat.com>
    Link: https://lore.kernel.org/r/20231025140205.3586473-3-mszeredi@redhat.comReviewed-by: default avatarIan Kent <raven@themaw.net>
    Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
    2eea9ce4
mount.h 4.16 KB