Skip to contentSkip to conversation

Fastwalk

2.4.22-pre2 Hanna Linder 1 participant 1 message Jul 3, 2003

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Marcelo,

Here is the dcache fastwalk patch to reduce cacheline bouncing of the d_count reference counter while traversing paths that are already in the dcache. The testing I have done this year shows a small increase in throughput on a 2-way system. I expect the benefit to be greatest on slower SMP systems which could suffer from cacheline problems.

Please consider it for inclusion.

Thanks.

Hanna

-----

 fs/dcache.c               |   17 +-
 fs/intermezzo/journal.c   |    3
 fs/intermezzo/presto.c    |    3
 fs/intermezzo/vfs.c       |   31 +---
 fs/namei.c                |  330 ++++++++++++++++++++++++++++++----------------
 fs/namespace.c            |    1
 fs/nfsd/export.c          |    6
 include/linux/dcache.h    |    1
 include/linux/fs.h        |    5
 include/linux/fs_struct.h |    4
 kernel/ksyms.c            |    2
 net/unix/af_unix.c        |    8 -
 12 files changed, 258 insertions(+), 153 deletions(-)
fs/dcache.c +13 -4
diff -Nrup -Xdontdiff linux-2.4.22-pre2/fs/dcache.c linux-fastwalk/fs/dcache.c
@@ -702,13 +702,25 @@ static inline struct list_head * d_hash(
  
 struct dentry * d_lookup(struct dentry * parent, struct qstr * name)
 {
+	struct dentry *dentry = NULL;
+
+	spin_lock(&dcache_lock);
+	dentry = __d_lookup(parent,name);
+	if (dentry)
+		__dget_locked(dentry);
+	spin_unlock(&dcache_lock);
+	return dentry;
+}
+
+struct dentry * __d_lookup(struct dentry * parent, struct qstr * name)  
+{
+
 	unsigned int len = name->len;
 	unsigned int hash = name->hash;
 	const unsigned char *str = name->name;
 	struct list_head *head = d_hash(parent,hash);
 	struct list_head *tmp;
 
-	spin_lock(&dcache_lock);
 	tmp = head->next;
 	for (;;) {
 		struct dentry * dentry = list_entry(tmp, struct dentry, d_hash);
@@ -728,12 +740,9 @@ struct dentry * d_lookup(struct dentry *
 			if (memcmp(dentry->d_name.name, str, len))
 				continue;
 		}
-		__dget_locked(dentry);
 		dentry->d_vfs_flags |= DCACHE_REFERENCED;
-		spin_unlock(&dcache_lock);
 		return dentry;
 	}
-	spin_unlock(&dcache_lock);
 	return NULL;
 }
 
fs/intermezzo/journal.c +1 -2
diff -Nrup -Xdontdiff linux-2.4.22-pre2/fs/intermezzo/journal.c linux-fastwalk/fs/intermezzo/journal.c
@@ -617,8 +617,7 @@ int izo_lookup_file(struct presto_file_s
 
         CDEBUG(D_CACHE, "looking up: %s\n", path);
 
-        if (path_init(path, LOOKUP_PARENT, nd))
-                error = path_walk(path, nd);
+        error = path_lookup(path, LOOKUP_PARENT, nd);
         if (error) {
                 EXIT;
                 return error;
fs/intermezzo/presto.c +1 -2
diff -Nrup -Xdontdiff linux-2.4.22-pre2/fs/intermezzo/presto.c linux-fastwalk/fs/intermezzo/presto.c
@@ -53,8 +53,7 @@ int presto_walk(const char *name, struct
 
         ENTRY;
         err = 0;
-        if (path_init(name, flags, nd)) 
-                err = path_walk(name, nd);
+        err = path_lookup(name, flags, nd);
         return err;
 }
 
fs/intermezzo/vfs.c +10 -21
diff -Nrup -Xdontdiff linux-2.4.22-pre2/fs/intermezzo/vfs.c linux-fastwalk/fs/intermezzo/vfs.c
@@ -702,8 +702,7 @@ int lento_create(const char *name, int m
 
         /* this looks up the parent */
 //        if (path_init(pathname, LOOKUP_FOLLOW | LOOKUP_POSITIVE, &nd))
-        if (path_init(pathname,  LOOKUP_PARENT, &nd))
-                error = path_walk(pathname, &nd);
+        error = path_lookup(pathname,  LOOKUP_PARENT, &nd);
         if (error) {
                 EXIT;
                 goto exit;
@@ -855,12 +854,10 @@ int lento_link(const char * oldname, con
                 struct nameidata nd, old_nd;
 
                 error = 0;
-                if (path_init(from, LOOKUP_POSITIVE, &old_nd))
-                        error = path_walk(from, &old_nd);
+                error = path_lookup(from, LOOKUP_POSITIVE, &old_nd);
                 if (error)
                         goto exit;
-                if (path_init(to, LOOKUP_PARENT, &nd))
-                        error = path_walk(to, &nd);
+                error = path_lookup(to, LOOKUP_PARENT, &nd);
                 if (error)
                         goto out;
                 error = -EXDEV;
@@ -1062,8 +1059,7 @@ int lento_unlink(const char *pathname, s
         if(IS_ERR(name))
                 return PTR_ERR(name);
 
-        if (path_init(name, LOOKUP_PARENT, &nd))
-                error = path_walk(name, &nd);
+        error = path_lookup(name, LOOKUP_PARENT, &nd);
         if (error)
                 goto exit;
         error = -EISDIR;
@@ -1223,8 +1219,7 @@ int lento_symlink(const char *oldname, c
                 goto exit_from;
         }
 
-        if (path_init(to, LOOKUP_PARENT, &nd)) 
-                error = path_walk(to, &nd);
+        error = path_lookup(to, LOOKUP_PARENT, &nd);
         if (error) {
                 EXIT;
                 goto exit_to;
@@ -1381,8 +1376,7 @@ int lento_mkdir(const char *name, int mo
                 return error;
         }
 
-        if (path_init(pathname, LOOKUP_PARENT, &nd))
-                error = path_walk(pathname, &nd);
+        error = path_lookup(pathname, LOOKUP_PARENT, &nd);
         if (error)
                 goto out_name;
 
@@ -1527,8 +1521,7 @@ int lento_rmdir(const char *pathname, st
                 return PTR_ERR(name);
         }
 
-        if (path_init(name, LOOKUP_PARENT, &nd))
-                error = path_walk(name, &nd);
+        error = path_lookup(name, LOOKUP_PARENT, &nd);
         if (error) {
                 EXIT;
                 goto exit;
@@ -1693,8 +1686,7 @@ int lento_mknod(const char *filename, in
         if (IS_ERR(tmp))
                 return PTR_ERR(tmp);
 
-        if (path_init(tmp, LOOKUP_PARENT, &nd))
-                error = path_walk(tmp, &nd);
+        error = path_lookup(tmp, LOOKUP_PARENT, &nd);
         if (error)
                 goto out;
         dentry = lookup_create(&nd, 0);
@@ -1973,14 +1965,11 @@ int lento_do_rename(const char *oldname,
 
         ENTRY;
 
-        if (path_init(oldname, LOOKUP_PARENT, &oldnd))
-                error = path_walk(oldname, &oldnd);
-
+        error = path_lookup(oldname, LOOKUP_PARENT, &oldnd);
         if (error)
                 goto exit;
 
-        if (path_init(newname, LOOKUP_PARENT, &newnd))
-                error = path_walk(newname, &newnd);
+        error = path_lookup(newname, LOOKUP_PARENT, &newnd);
         if (error)
                 goto exit1;
 
fs/namei.c +217 -113

486 lines not on this page · raw message

fs/namespace.c +1 -0
diff -Nrup -Xdontdiff linux-2.4.22-pre2/fs/namespace.c linux-fastwalk/fs/namespace.c
@@ -23,6 +23,7 @@
 
 struct vfsmount *do_kern_mount(const char *type, int flags, char *name, void *data);
 int do_remount_sb(struct super_block *sb, int flags, void * data);
+int __init init_rootfs(void);
 void kill_super(struct super_block *sb);
 extern int __init init_rootfs(void);
 
fs/nfsd/export.c +2 -4
diff -Nrup -Xdontdiff linux-2.4.22-pre2/fs/nfsd/export.c linux-fastwalk/fs/nfsd/export.c
@@ -214,8 +214,7 @@ exp_export(struct nfsctl_export *nxp)
 
 	/* Look up the dentry */
 	err = 0;
-	if (path_init(nxp->ex_path, LOOKUP_POSITIVE, &nd))
-		err = path_walk(nxp->ex_path, &nd);
+	err = path_lookup(nxp->ex_path, LOOKUP_POSITIVE, &nd);
 	if (err)
 		goto out_unlock;
 
@@ -411,8 +410,7 @@ exp_rootfh(struct svc_client *clp, kdev_
 
 	err = -EPERM;
 	if (path) {
-		if (path_init(path, LOOKUP_POSITIVE, &nd) &&
-		    path_walk(path, &nd)) {
+		if (path_lookup(path, LOOKUP_POSITIVE, &nd))  {
 			printk("nfsd: exp_rootfh path not found %s", path);
 			return err;
 		}
include/linux/dcache.h +1 -0
diff -Nrup -Xdontdiff linux-2.4.22-pre2/include/linux/dcache.h linux-fastwalk/include/linux/dcache.h
@@ -219,6 +219,7 @@ extern void d_move(struct dentry *, stru
 
 /* appendix may either be NULL or be used for transname suffixes */
 extern struct dentry * d_lookup(struct dentry *, struct qstr *);
+extern struct dentry * __d_lookup(struct dentry *, struct qstr *);
 
 /* validate "insecure" dentry pointer */
 extern int d_validate(struct dentry *, struct dentry *);
include/linux/fs.h +4 -1
diff -Nrup -Xdontdiff linux-2.4.22-pre2/include/linux/fs.h linux-fastwalk/include/linux/fs.h
@@ -659,6 +659,8 @@ struct nameidata {
 	struct qstr last;
 	unsigned int flags;
 	int last_type;
+	struct dentry *old_dentry;
+	struct vfsmount *old_mnt;
 };
 
 #define DQUOT_USR_ENABLED	0x01		/* User diskquotas enabled */
@@ -1328,6 +1330,7 @@ static inline long IS_ERR(const void *pt
  *  - require a directory
  *  - ending slashes ok even for nonexistent files
  *  - internal "there are more path compnents" flag
+ *  - locked when lookup done with dcache_lock held
  */
 #define LOOKUP_FOLLOW		(1)
 #define LOOKUP_DIRECTORY	(2)
@@ -1335,6 +1338,7 @@ static inline long IS_ERR(const void *pt
 #define LOOKUP_POSITIVE		(8)
 #define LOOKUP_PARENT		(16)
 #define LOOKUP_NOALT		(32)
+
 /*
  * Type of the last component on LOOKUP_PARENT
  */
@@ -1362,7 +1366,6 @@ typedef int (*read_actor_t)(read_descrip
 extern loff_t default_llseek(struct file *file, loff_t offset, int origin);
 
 extern int FASTCALL(__user_walk(const char *, unsigned, struct nameidata *));
-extern int FASTCALL(path_init(const char *, unsigned, struct nameidata *));
 extern int FASTCALL(path_walk(const char *, struct nameidata *));
 extern int FASTCALL(path_lookup(const char *, unsigned, struct nameidata *));
 extern int FASTCALL(link_path_walk(const char *, struct nameidata *));
include/linux/fs_struct.h +4 -0
diff -Nrup -Xdontdiff linux-2.4.22-pre2/include/linux/fs_struct.h linux-fastwalk/include/linux/fs_struct.h
@@ -32,10 +32,12 @@ static inline void set_fs_root(struct fs
 	struct dentry *old_root;
 	struct vfsmount *old_rootmnt;
 	write_lock(&fs->lock);
+	spin_lock(&dcache_lock);
 	old_root = fs->root;
 	old_rootmnt = fs->rootmnt;
 	fs->rootmnt = mntget(mnt);
 	fs->root = dget(dentry);
+	spin_unlock(&dcache_lock);
 	write_unlock(&fs->lock);
 	if (old_root) {
 		dput(old_root);
@@ -55,10 +57,12 @@ static inline void set_fs_pwd(struct fs_
 	struct dentry *old_pwd;
 	struct vfsmount *old_pwdmnt;
 	write_lock(&fs->lock);
+	spin_lock(&dcache_lock);
 	old_pwd = fs->pwd;
 	old_pwdmnt = fs->pwdmnt;
 	fs->pwdmnt = mntget(mnt);
 	fs->pwd = dget(dentry);
+	spin_unlock(&dcache_lock);
 	write_unlock(&fs->lock);
 	if (old_pwd) {
 		dput(old_pwd);
kernel/ksyms.c +1 -1
diff -Nrup -Xdontdiff linux-2.4.22-pre2/kernel/ksyms.c linux-fastwalk/kernel/ksyms.c
@@ -149,8 +149,8 @@ EXPORT_SYMBOL(force_delete);
 EXPORT_SYMBOL(follow_up);
 EXPORT_SYMBOL(follow_down);
 EXPORT_SYMBOL(lookup_mnt);
-EXPORT_SYMBOL(path_init);
 EXPORT_SYMBOL(path_walk);
+EXPORT_SYMBOL(path_lookup);
 EXPORT_SYMBOL(path_release);
 EXPORT_SYMBOL(__user_walk);
 EXPORT_SYMBOL(lookup_one_len);
net/unix/af_unix.c +3 -5
diff -Nrup -Xdontdiff linux-2.4.22-pre2/net/unix/af_unix.c linux-fastwalk/net/unix/af_unix.c
@@ -590,9 +590,8 @@ static unix_socket *unix_find_other(stru
 	int err = 0;
 	
 	if (sunname->sun_path[0]) {
-		if (path_init(sunname->sun_path, 
-			      LOOKUP_POSITIVE|LOOKUP_FOLLOW, &nd))
-			err = path_walk(sunname->sun_path, &nd);
+		err = path_lookup(sunname->sun_path, 
+			      LOOKUP_POSITIVE|LOOKUP_FOLLOW, &nd);
 		if (err)
 			goto fail;
 		err = permission(nd.dentry->d_inode,MAY_WRITE);
@@ -685,8 +684,7 @@ static int unix_bind(struct socket *sock
 		 * Get the parent directory, calculate the hash for last
 		 * component.
 		 */
-		if (path_init(sunaddr->sun_path, LOOKUP_PARENT, &nd))
-			err = path_walk(sunaddr->sun_path, &nd);
+		err = path_lookup(sunaddr->sun_path, LOOKUP_PARENT, &nd);
 		if (err)
 			goto out_mknod_parent;
 		/*