vfs: make rename_lock per-sb
Subsystems (5)
RFC PATCH 1/1 vfs: make rename_lock per-sb
Overlayfs uses rename to atomically move copied up files into place. This can result in heavier than usual rename load, which in turn might result in cross-filesystem serialization of tree walking and rename operations.
One notable case where this seems to have been manifesting itself is shrink_dcache_for_umount(), where otherwise there would be no contention at all.
Turning rename_lock into a per-sb lock mitigates the above issues.
--- fs/autofs/waitq.c | 6 ++--- fs/ceph/mds_client.c | 4 +-- fs/cifs/dir.c | 8 ++++--- fs/d_path.c | 14 +++++++----- fs/dcache.c | 55 +++++++++++++++++++++++++++---------------------- fs/nfs/namespace.c | 7 +++--- fs/super.c | 1 include/linux/dcache.h | 2 - include/linux/fs.h | 2 + kernel/auditsc.c | 5 ++-- 10 files changed, 59 insertions(+), 45 deletions(-)
fs/autofs/waitq.c +3 -3
@@ -189,7 +189,7 @@ static int autofs_getpath(struct autofs_ buf = name; len =0 ; - seq =read_seqbegin (&rename_lock); + seq =read_seqbegin (&sbi->sb->rename_lock);rcu_read_lock ();spin_lock (&sbi->fs_lock);for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent)
@@ -198,7 +198,7 @@ static int autofs_getpath(struct autofs_if (!len || --len >NAME_MAX ) {spin_unlock (&sbi->fs_lock);rcu_read_unlock (); -if (read_seqretry (&rename_lock, seq)) +if (read_seqretry (&sbi->sb->rename_lock, seq)) goto rename_retry;return 0 ; }
@@ -214,7 +214,7 @@ static int autofs_getpath(struct autofs_ }spin_unlock (&sbi->fs_lock);rcu_read_unlock (); -if (read_seqretry (&rename_lock, seq)) +if (read_seqretry (&sbi->sb->rename_lock, seq)) goto rename_retry;return len;
fs/ceph/mds_client.c +2 -2
@@ -2143,7 +2143,7 @@ char *ceph_mdsc_build_path(struct dentry pos =PATH_MAX -1 ; path[pos] ='\0' ; - seq =read_seqbegin (&rename_lock); + seq =read_seqbegin (&dentry->d_sb->rename_lock);rcu_read_lock (); temp = dentry;for (;;) {
@@ -2182,7 +2182,7 @@ char *ceph_mdsc_build_path(struct dentry } base =ceph_ino (d_inode (temp));rcu_read_unlock (); -if (pos <0 ||read_seqretry (&rename_lock, seq)) { +if (pos <0 ||read_seqretry (&dentry->d_sb->rename_lock, seq)) {pr_err ("build_path did not end path lookup where " "expected, pos is %d\n" , pos);/* presumably this is only possible if racing with a
fs/cifs/dir.c +5 -3
@@ -97,7 +97,8 @@ build_path_from_dentry_optional_prefix(sint pplen =0 ;char *full_path;char dirsep; -struct cifs_sb_info *cifs_sb =CIFS_SB (direntry->d_sb); +struct super_block *sb = direntry->d_sb; +struct cifs_sb_info *cifs_sb =CIFS_SB (sb);struct cifs_tcon *tcon =cifs_sb_master_tcon (cifs_sb);unsigned seq;
@@ -112,7 +113,7 @@ build_path_from_dentry_optional_prefix(s cifs_bp_rename_retry: namelen = dfsplen + pplen; - seq =read_seqbegin (&rename_lock); + seq =read_seqbegin (&sb->rename_lock);rcu_read_lock ();for (temp = direntry; !IS_ROOT (temp);) { namelen += (1 + temp->d_name.len);
@@ -152,7 +153,8 @@ build_path_from_dentry_optional_prefix(s } }rcu_read_unlock (); -if (namelen != dfsplen + pplen ||read_seqretry (&rename_lock, seq)) { +if (namelen != dfsplen + pplen || +read_seqretry (&sb->rename_lock, seq)) {cifs_dbg (FYI ,"did not end path lookup where expected. namelen=%ddfsplen=%d\n" , namelen, dfsplen);/* presumably this is only possible if racing with a rename
fs/d_path.c +8 -6
@@ -76,6 +76,7 @@ static int prepend_path(const struct patconst struct path *root, char **buffer, int *buflen) { + struct super_block *sb = root->mnt->mnt_sb;struct dentry *dentry;struct vfsmount *vfsmnt;struct mount *mnt;
@@ -96,7 +97,7 @@ static int prepend_path(const struct pat dentry = path->dentry; vfsmnt = path->mnt; mnt =real_mount (vfsmnt); -read_seqbegin_or_lock (&rename_lock, &seq); +read_seqbegin_or_lock (&sb->rename_lock, &seq);while (dentry != root->dentry || vfsmnt != root->mnt) {struct dentry * parent;
@@ -132,11 +133,11 @@ static int prepend_path(const struct pat }if (!(seq &1 ))rcu_read_unlock (); -if (need_seqretry (&rename_lock, seq)) { +if (need_seqretry (&sb->rename_lock, seq)) { seq =1 ; goto restart; } -done_seqretry (&rename_lock, seq); +done_seqretry (&sb->rename_lock, seq);if (!(m_seq &1 ))rcu_read_unlock ();
@@ -324,6 +325,7 @@ char *simple_dname(struct dentry *dentry*/ static char *__dentry_path (struct dentry *d,char *buf,int buflen) { +struct super_block *sb = d->d_sb;struct dentry *dentry;char *end, *retval;int len, seq =0 ;
@@ -341,7 +343,7 @@ static char *__dentry_path(struct dentry/* Get '/' right */ retval = end-1 ; *retval ='/' ; -read_seqbegin_or_lock (&rename_lock, &seq); +read_seqbegin_or_lock (&sb->rename_lock, &seq);while (!IS_ROOT (dentry)) {struct dentry *parent = dentry->d_parent;
@@ -355,11 +357,11 @@ static char *__dentry_path(struct dentry }if (!(seq &1 ))rcu_read_unlock (); -if (need_seqretry (&rename_lock, seq)) { +if (need_seqretry (&sb->rename_lock, seq)) { seq =1 ; goto restart; } -done_seqretry (&rename_lock, seq); +done_seqretry (&sb->rename_lock, seq);if (error) goto Elong;return retval;
fs/dcache.c +31 -24
197 lines not on this page · raw message
fs/nfs/namespace.c +4 -3
@@ -51,6 +51,7 @@ int nfs_mountpoint_expiry_timeout = 500char *nfs_path (char **p,struct dentry *dentry,char *buffer,ssize_t buflen,unsigned flags) { +struct super_block *sb = dentry->d_sb;char *end;int namelen;unsigned seq;
@@ -61,7 +62,7 @@ char *nfs_path(char **p, struct dentry * *--end ='\0' ; buflen--; - seq =read_seqbegin (&rename_lock); + seq =read_seqbegin (&sb->rename_lock);rcu_read_lock ();while (1 ) {spin_lock (&dentry->d_lock);
@@ -77,7 +78,7 @@ char *nfs_path(char **p, struct dentry *spin_unlock (&dentry->d_lock); dentry = dentry->d_parent; } -if (read_seqretry (&rename_lock, seq)) { +if (read_seqretry (&sb->rename_lock, seq)) {spin_unlock (&dentry->d_lock);rcu_read_unlock (); goto rename_retry;
@@ -118,7 +119,7 @@ char *nfs_path(char **p, struct dentry * Elong_unlock:spin_unlock (&dentry->d_lock);rcu_read_unlock (); -if (read_seqretry (&rename_lock, seq)) +if (read_seqretry (&sb->rename_lock, seq)) goto rename_retry; Elong:return ERR_PTR (-ENAMETOOLONG );
fs/super.c +1 -0
@@ -249,6 +249,7 @@ static struct super_block *alloc_super(sspin_lock_init (&s->s_inode_list_lock);INIT_LIST_HEAD (&s->s_inodes_wb);spin_lock_init (&s->s_inode_wblist_lock); +seqlock_init (&s->rename_lock); s->s_count =1 ;atomic_set (&s->s_active,1 );
include/linux/dcache.h +0 -2
@@ -218,8 +218,6 @@ struct dentry_operations {#define DCACHE_DENTRY_CURSOR 0x20000000#define DCACHE_NORCU 0x40000000/* No RCU delay for freeing */ -extern seqlock_t rename_lock; -/* * These are the low-level FS interfaces to the dcache.. */
include/linux/fs.h +2 -0
@@ -1548,6 +1548,8 @@ struct super_block {spinlock_t s_inode_wblist_lock;struct list_head s_inodes_wb;/* writeback inodes */ + +seqlock_t rename_lock____cacheline_aligned_in_smp ; } __randomize_layout;/* Helper functions so that in most cases filesystems will
kernel/auditsc.c +3 -2
@@ -1763,6 +1763,7 @@ static inline void handle_one(const strustatic void handle_path (const struct dentry *dentry) { +struct super_block *sb = dentry->d_sb;struct audit_context *context;struct audit_tree_refs *p;const struct dentry *d, *parent;
@@ -1777,7 +1778,7 @@ static void handle_path(const struct den drop =NULL ; d = dentry;rcu_read_lock (); - seq =read_seqbegin (&rename_lock); + seq =read_seqbegin (&sb->rename_lock);for (;;) {struct inode *inode =d_backing_inode (d);if (inode &&unlikely (inode->i_fsnotify_marks)) {
@@ -1795,7 +1796,7 @@ static void handle_path(const struct denbreak ; d = parent; } -if (unlikely (read_seqretry (&rename_lock, seq) || drop)) {/* in this order */ +if (unlikely (read_seqretry (&sb->rename_lock, seq) || drop)) {/* in this order */ rcu_read_unlock ();if (!drop) {/* just a race with rename */
Quoted 1 line · Miklos Szeredi
Turning
rename_lockinto a per-sb lock mitigates the above issues.
... and completely fucks d_lookup(), since false negative can be caused by rename of *ANYTHING* you've encountered while walking a hash chain.
NAK.
Quoted 8 lines · Al Viro
Quoted 1 line · Miklos Szeredi
Turning
rename_lockinto a per-sb lock mitigates the above issues.... and completely fucks
d_lookup(), since false negative can be caused by rename of *ANYTHING* you've encountered while walking a hash chain.
Drat.
Could we use the bitlock in the hash chain head for verification of a negative? Seems like much finer grained than having to rely on a global seqlock for hash integrity.
Thanks,
Miklos