Dcache Fastwalk
Subsystems (4)
PATCH 1/1 Dcache Fastwalk
Hi Marcelo,
This patch is a backport of the work Al Viro and I did
in 2.5 to decrease cacheline bouncing during dcache lookup. This also removes path_init and replaces it with path_lookup (hence the changes in intermezzo and nfsd) as it is in 2.5.
Please consider this for inclusion in the next 2.4.2* release.
This patch is no different than the 2.4.20 patch, it simply applies with no fuzz.
Thanks.
Hanna Linder
IBM Linux Technology Center
-------
fs/dcache.c +13 -4
@@ -702,13 +702,25 @@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 @@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
@@ -617,8 +617,7 @@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
@@ -53,8 +53,7 @@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
@@ -702,8 +702,7 @@/* 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 @@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 @@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 @@ 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 @@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 @@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 @@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 @@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 +4 -11
@@ -23,14 +23,13 @@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); +extern int __init init_rootfs (void );void kill_super (struct super_block *sb);static struct list_head *mount_hashtable;static int hash_mask, hash_bits;static kmem_cache_t *mnt_cache; -extern void init_rootfs (void ); -static inline unsigned long hash (struct vfsmount *mnt,struct dentry *dentry) {unsigned long tmp = ((unsigned long ) mnt /L1_CACHE_BYTES );
@@ -1023,15 +1022,9 @@if (!mnt_cache)panic ("Cannot create vfsmount cache" ); - mempages >>= (16 -PAGE_SHIFT ); - mempages *=sizeof (struct list_head ); -for (order =0 ; ((1UL << order) <<PAGE_SHIFT ) < mempages; order++) - ; - -do { - mount_hashtable = (struct list_head *) -__get_free_pages (GFP_ATOMIC , order); - }while (mount_hashtable ==NULL && --order >=0 ); + order =0 ; + mount_hashtable = (struct list_head *) +__get_free_pages (GFP_ATOMIC , order);if (!mount_hashtable)panic ("Failed to allocate mount hash table\n" );
fs/nfsd/export.c +2 -4
@@ -214,8 +214,7 @@/* 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 @@ 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
@@ -219,6 +219,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 -1
@@ -657,6 +657,8 @@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 */
@@ -1325,6 +1327,7 @@* - 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)
@@ -1332,6 +1335,7 @@#define LOOKUP_POSITIVE (8)#define LOOKUP_PARENT (16)#define LOOKUP_NOALT (32) +/* * Type of the last component on LOOKUP_PARENT */
@@ -1359,7 +1363,6 @@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
@@ -32,10 +32,12 @@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 @@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
@@ -147,8 +147,8 @@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
@@ -590,9 +590,8 @@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 @@* 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;/*