Your suggestions for fast path walk
Subsystems (2)
RFC PATCH 1/1 Your suggestions for fast path walk
Hello,
Following is the first cut at a patch implementing
some suggestions you made on IRC recently. It attempts to decrease cacheline bouncing of d_count by replacing dget/dput with taking the dcache_lock for dentries already in the cache. I have also combined path_init and path_walk in places where they are always called together.
I would appreciate you comments on this patch, and any
suggestions you have on any benchmarks or specific workloads that might stress this area of the filesystem. Do you have any further suggestions that might help?
Thank you.
Hanna Linder
[email protected]
IBM Linux Technology Center
-----
fs/dcache.c +39 -33
@@ -703,39 +703,45 @@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); -if (tmp == head) -break ; - tmp = tmp->next; -if (dentry->d_name.hash != hash) -continue ; -if (dentry->d_parent != parent) -continue ; -if (parent->d_op && parent->d_op->d_compare) { -if (parent->d_op->d_compare (parent, &dentry->d_name, name)) -continue ; - }else { -if (dentry->d_name.len != len) -continue ; -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 ; +struct dentry *dentry =NULL ; + +spin_lock (&dcache_lock); + dentry =__d_lookup (parent, name); +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; + + tmp = head->next; +for (;;) { + struct dentry * dentry = list_entry(tmp, struct dentry, d_hash); +if (tmp == head) +return NULL ; + tmp = tmp->next; +if (dentry->d_name.hash != hash) +continue ; +if (dentry->d_parent != parent) +continue ; +if (parent->d_op && parent->d_op->d_compare) { +if (parent->d_op->d_compare (parent, &dentry->d_name, name)) +continue ; + }else { +if (dentry->d_name.len != len) +continue ; +if (memcmp (dentry->d_name.name, str, len)) +continue ; + } +__dget_locked (dentry); + dentry->d_vfs_flags |=DCACHE_REFERENCED ; +return dentry; + } }/**
fs/exec.c +1 -2
@@ -343,8 +343,7 @@struct file *file;int err =0 ; -if (path_init (name,LOOKUP_FOLLOW |LOOKUP_POSITIVE , &nd)) - err =path_walk (name, &nd); + err =path_init_walk (name,LOOKUP_FOLLOW |LOOKUP_POSITIVE , &nd); file =ERR_PTR (err);if (!err) { inode = nd.dentry->d_inode;
fs/namei.c +92 -22
211 lines not on this page · raw message
fs/namespace.c +7 -14
@@ -375,8 +375,7 @@if (IS_ERR (kname)) goto out; retval =0 ; -if (path_init (kname,LOOKUP_POSITIVE |LOOKUP_FOLLOW , &nd)) - retval =path_walk (kname, &nd); + retval =path_init_walk (kname,LOOKUP_POSITIVE |LOOKUP_FOLLOW , &nd);putname (kname);if (retval) goto out;
@@ -505,8 +504,7 @@return err;if (!old_name || !*old_name)return -EINVAL ; -if (path_init (old_name,LOOKUP_POSITIVE |LOOKUP_FOLLOW , &old_nd)) - err =path_walk (old_name, &old_nd); + err =path_init_walk (old_name,LOOKUP_POSITIVE |LOOKUP_FOLLOW , &old_nd);if (err)return err;
@@ -669,8 +667,7 @@ flags &= ~(MS_NOSUID |MS_NOEXEC |MS_NODEV );/* ... and get the mountpoint */ -if (path_init (dir_name,LOOKUP_FOLLOW |LOOKUP_POSITIVE , &nd)) - retval =path_walk (dir_name, &nd); + retval =path_init_walk (dir_name,LOOKUP_FOLLOW |LOOKUP_POSITIVE , &nd);if (retval)return retval;
@@ -780,8 +777,7 @@if (IS_ERR (name)) goto out0; error =0 ; -if (path_init (name,LOOKUP_POSITIVE |LOOKUP_FOLLOW |LOOKUP_DIRECTORY , &new_nd)) - error =path_walk (name, &new_nd); + error =path_init_walk (name,LOOKUP_POSITIVE |LOOKUP_FOLLOW |LOOKUP_DIRECTORY , &new_nd);putname (name);if (error) goto out0;
@@ -794,8 +790,7 @@if (IS_ERR (name)) goto out1; error =0 ; -if (path_init (name,LOOKUP_POSITIVE |LOOKUP_FOLLOW |LOOKUP_DIRECTORY , &old_nd)) - error =path_walk (name, &old_nd); + error =path_init_walk (name,LOOKUP_POSITIVE |LOOKUP_FOLLOW |LOOKUP_DIRECTORY , &old_nd);putname (name);if (error) goto out1;
@@ -985,8 +980,7 @@ old_rootmnt =mntget (current->fs->rootmnt);read_unlock (¤t->fs->lock);/* First unmount devfs if mounted */ -if (path_init ("/dev" ,LOOKUP_FOLLOW |LOOKUP_POSITIVE , &devfs_nd)) - error =path_walk ("/dev" , &devfs_nd); + error =path_init_walk ("/dev" ,LOOKUP_FOLLOW |LOOKUP_POSITIVE , &devfs_nd);if (!error) {if (devfs_nd.mnt->mnt_sb->s_magic ==DEVFS_SUPER_MAGIC && devfs_nd.dentry == devfs_nd.mnt->mnt_root) {
@@ -1009,8 +1003,7 @@* Get the new mount directory */ error =0 ; -if (path_init (put_old,LOOKUP_FOLLOW |LOOKUP_POSITIVE |LOOKUP_DIRECTORY , &nd)) - error =path_walk (put_old, &nd); + error =path_init_walk (put_old,LOOKUP_FOLLOW |LOOKUP_POSITIVE |LOOKUP_DIRECTORY , &nd);if (error) {int blivet;struct block_device *ramdisk = old_rootmnt->mnt_sb->s_bdev;
fs/open.c +2 -4
@@ -368,8 +368,7 @@ goto out; error =0 ; -if (path_init (name,LOOKUP_POSITIVE |LOOKUP_FOLLOW |LOOKUP_DIRECTORY ,&nd)) - error =path_walk (name, &nd); + error =path_init_walk (name,LOOKUP_POSITIVE |LOOKUP_FOLLOW |LOOKUP_DIRECTORY ,&nd);putname (name);if (error) goto out;
@@ -427,9 +426,8 @@if (IS_ERR (name)) goto out; -path_init (name,LOOKUP_POSITIVE |LOOKUP_FOLLOW | + error =path_init_walk (name,LOOKUP_POSITIVE |LOOKUP_FOLLOW |LOOKUP_DIRECTORY |LOOKUP_NOALT , &nd); - error =path_walk (name, &nd);putname (name);if (error) goto out;
fs/super.c +1 -2
@@ -548,8 +548,7 @@/* What device it is? */ if (!dev_name || !*dev_name)return ERR_PTR (-EINVAL ); -if (path_init (dev_name,LOOKUP_FOLLOW |LOOKUP_POSITIVE , &nd)) - error =path_walk (dev_name, &nd); + error =path_init_walk (dev_name,LOOKUP_FOLLOW |LOOKUP_POSITIVE , &nd);if (error)return ERR_PTR (error); inode = nd.dentry->d_inode;
include/linux/dcache.h +1 -0
@@ -218,6 +218,7 @@/* 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 -0
@@ -1270,6 +1270,7 @@* - require a directory * - ending slashes ok even for nonexistent files * - internal "there are more path compnents" flag +* - locked on when the dcache_lock is held */ #define LOOKUP_FOLLOW (1)#define LOOKUP_DIRECTORY (2)
@@ -1277,6 +1278,8 @@#define LOOKUP_POSITIVE (8)#define LOOKUP_PARENT (16)#define LOOKUP_NOALT (32) +#define LOOKUP_LOCKED (64) +/* * Type of the last component on LOOKUP_PARENT */
@@ -1306,6 +1309,7 @@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_init_walk (const char *,unsigned ,struct nameidata *));extern int FASTCALL (link_path_walk (const char *,struct nameidata *));extern void path_release (struct nameidata *);extern int follow_down (struct vfsmount **,struct dentry **);
kernel/ksyms.c +1 -0
@@ -144,6 +144,7 @@EXPORT_SYMBOL (lookup_mnt);EXPORT_SYMBOL (path_init);EXPORT_SYMBOL (path_walk); +EXPORT_SYMBOL (path_init_walk);EXPORT_SYMBOL (path_release);EXPORT_SYMBOL (__user_walk);EXPORT_SYMBOL (lookup_one_len);
Hi,
fs/dcache.c line 706
Quoted 2 lines · Hanna Linder
fs/dcache.c +1
-1-return NULL ; +struct dentry *dentry =NULL ;
Could you please configure your editor to use tabs instead of spaces? It would make the patch smaller and easier to read.
fs/namei.c line 265
Quoted 1 line
fs/namei.c +1
-0+if (flags &LOOKUP_LOCKED ){
IMO it would be better to use a count, which limits to number of lookups done with the spinlock held. This count could be put into nameidata, this would change the prototype of cached_lookup/lookup_hash into using a pointer to struct nameidata, but AFAICS it's not a really problem, as most of the time the data is already available in a nameidata struct. Since spinlocks are a dummy on UP, it would make sense to make this test a inline function/macro, where it could be made a dummy as well.
bye, Roman
Quoted 2 lines · --On Thursday, February 14, 2002 12:13:38 +0100 Roman Zippel…
Could you please configure your editor to use tabs instead of spaces? It would make the patch smaller and easier to read.
That happens when I cut and paste. I will make sure to fix it when I submit the patch.
Quoted 2 lines
IMO it would be better to use a count, which limits to number of lookups done with the spinlock held.
Thanks for taking a look at the patch and giving me your input. I will need to think about your suggestions.
Take Care,
Hanna