Skip to content

Commit

Permalink
fs: dcache reduce branches in lookup path
Browse files Browse the repository at this point in the history
Reduce some branches and memory accesses in dcache lookup by adding dentry
flags to indicate common d_ops are set, rather than having to check them.
This saves a pointer memory access (dentry->d_op) in common path lookup
situations, and saves another pointer load and branch in cases where we
have d_op but not the particular operation.

Patched with:

git grep -E '[.>]([[:space:]])*d_op([[:space:]])*=' | xargs sed -e 's/\([^\t ]*\)->d_op = \(.*\);/d_set_d_op(\1, \2);/' -e 's/\([^\t ]*\)\.d_op = \(.*\);/d_set_d_op(\&\1, \2);/' -i

Signed-off-by: Nick Piggin <[email protected]>
  • Loading branch information
Nick Piggin committed Jan 7, 2011
1 parent 5f57cbc commit fb045ad
Show file tree
Hide file tree
Showing 63 changed files with 174 additions and 137 deletions.
2 changes: 1 addition & 1 deletion arch/ia64/kernel/perfmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -2233,7 +2233,7 @@ pfm_alloc_file(pfm_context_t *ctx)
}
path.mnt = mntget(pfmfs_mnt);

path.dentry->d_op = &pfmfs_dentry_operations;
d_set_d_op(path.dentry, &pfmfs_dentry_operations);
d_add(path.dentry, inode);

file = alloc_file(&path, FMODE_READ, &pfm_file_ops);
Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/autofs/root.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static struct dentry *autofs_root_lookup(struct inode *dir, struct dentry *dentr
*
* We need to do this before we release the directory semaphore.
*/
dentry->d_op = &autofs_dentry_operations;
d_set_d_op(dentry, &autofs_dentry_operations);
dentry->d_flags |= DCACHE_AUTOFS_PENDING;
d_add(dentry, NULL);

Expand Down
8 changes: 4 additions & 4 deletions drivers/staging/smbfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,9 @@ smb_new_dentry(struct dentry *dentry)
struct smb_sb_info *server = server_from_dentry(dentry);

if (server->mnt->flags & SMB_MOUNT_CASE)
dentry->d_op = &smbfs_dentry_operations_case;
d_set_d_op(dentry, &smbfs_dentry_operations_case);
else
dentry->d_op = &smbfs_dentry_operations;
d_set_d_op(dentry, &smbfs_dentry_operations);
dentry->d_time = jiffies;
}

Expand Down Expand Up @@ -462,9 +462,9 @@ smb_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
add_entry:
server = server_from_dentry(dentry);
if (server->mnt->flags & SMB_MOUNT_CASE)
dentry->d_op = &smbfs_dentry_operations_case;
d_set_d_op(dentry, &smbfs_dentry_operations_case);
else
dentry->d_op = &smbfs_dentry_operations;
d_set_d_op(dentry, &smbfs_dentry_operations);

d_add(dentry, inode);
smb_renew_times(dentry);
Expand Down
26 changes: 13 additions & 13 deletions fs/9p/vfs_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,9 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
}

if (v9ses->cache)
dentry->d_op = &v9fs_cached_dentry_operations;
d_set_d_op(dentry, &v9fs_cached_dentry_operations);
else
dentry->d_op = &v9fs_dentry_operations;
d_set_d_op(dentry, &v9fs_dentry_operations);

d_instantiate(dentry, inode);
err = v9fs_fid_add(dentry, fid);
Expand Down Expand Up @@ -749,7 +749,7 @@ v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode,
err);
goto error;
}
dentry->d_op = &v9fs_cached_dentry_operations;
d_set_d_op(dentry, &v9fs_cached_dentry_operations);
d_instantiate(dentry, inode);
err = v9fs_fid_add(dentry, fid);
if (err < 0)
Expand All @@ -767,7 +767,7 @@ v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode,
err = PTR_ERR(inode);
goto error;
}
dentry->d_op = &v9fs_dentry_operations;
d_set_d_op(dentry, &v9fs_dentry_operations);
d_instantiate(dentry, inode);
}
/* Now set the ACL based on the default value */
Expand Down Expand Up @@ -956,7 +956,7 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir,
err);
goto error;
}
dentry->d_op = &v9fs_cached_dentry_operations;
d_set_d_op(dentry, &v9fs_cached_dentry_operations);
d_instantiate(dentry, inode);
err = v9fs_fid_add(dentry, fid);
if (err < 0)
Expand All @@ -973,7 +973,7 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir,
err = PTR_ERR(inode);
goto error;
}
dentry->d_op = &v9fs_dentry_operations;
d_set_d_op(dentry, &v9fs_dentry_operations);
d_instantiate(dentry, inode);
}
/* Now set the ACL based on the default value */
Expand Down Expand Up @@ -1041,9 +1041,9 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,

inst_out:
if (v9ses->cache)
dentry->d_op = &v9fs_cached_dentry_operations;
d_set_d_op(dentry, &v9fs_cached_dentry_operations);
else
dentry->d_op = &v9fs_dentry_operations;
d_set_d_op(dentry, &v9fs_dentry_operations);

d_add(dentry, inode);
return NULL;
Expand Down Expand Up @@ -1709,7 +1709,7 @@ v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
err);
goto error;
}
dentry->d_op = &v9fs_cached_dentry_operations;
d_set_d_op(dentry, &v9fs_cached_dentry_operations);
d_instantiate(dentry, inode);
err = v9fs_fid_add(dentry, fid);
if (err < 0)
Expand All @@ -1722,7 +1722,7 @@ v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
err = PTR_ERR(inode);
goto error;
}
dentry->d_op = &v9fs_dentry_operations;
d_set_d_op(dentry, &v9fs_dentry_operations);
d_instantiate(dentry, inode);
}

Expand Down Expand Up @@ -1856,7 +1856,7 @@ v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
ihold(old_dentry->d_inode);
}

dentry->d_op = old_dentry->d_op;
d_set_d_op(dentry, old_dentry->d_op);
d_instantiate(dentry, old_dentry->d_inode);

return err;
Expand Down Expand Up @@ -1980,7 +1980,7 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode,
err);
goto error;
}
dentry->d_op = &v9fs_cached_dentry_operations;
d_set_d_op(dentry, &v9fs_cached_dentry_operations);
d_instantiate(dentry, inode);
err = v9fs_fid_add(dentry, fid);
if (err < 0)
Expand All @@ -1996,7 +1996,7 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode,
err = PTR_ERR(inode);
goto error;
}
dentry->d_op = &v9fs_dentry_operations;
d_set_d_op(dentry, &v9fs_dentry_operations);
d_instantiate(dentry, inode);
}
/* Now set the ACL based on the default value */
Expand Down
2 changes: 1 addition & 1 deletion fs/adfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ adfs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
struct object_info obj;
int error;

dentry->d_op = &adfs_dentry_operations;
d_set_d_op(dentry, &adfs_dentry_operations);
lock_kernel();
error = adfs_dir_lookup_byname(dir, &dentry->d_name, &obj);
if (error == 0) {
Expand Down
2 changes: 1 addition & 1 deletion fs/adfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent)
adfs_error(sb, "get root inode failed\n");
goto error;
} else
sb->s_root->d_op = &adfs_dentry_operations;
d_set_d_op(sb->s_root, &adfs_dentry_operations);
unlock_kernel();
return 0;

Expand Down
2 changes: 1 addition & 1 deletion fs/affs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ affs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
if (IS_ERR(inode))
return ERR_CAST(inode);
}
dentry->d_op = AFFS_SB(sb)->s_flags & SF_INTL ? &affs_intl_dentry_operations : &affs_dentry_operations;
d_set_d_op(dentry, AFFS_SB(sb)->s_flags & SF_INTL ? &affs_intl_dentry_operations : &affs_dentry_operations);
d_add(dentry, inode);
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion fs/affs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
printk(KERN_ERR "AFFS: Get root inode failed\n");
goto out_error;
}
sb->s_root->d_op = &affs_dentry_operations;
d_set_d_op(sb->s_root, &affs_dentry_operations);

pr_debug("AFFS: s_flags=%lX\n",sb->s_flags);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion fs/afs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
}

success:
dentry->d_op = &afs_fs_dentry_operations;
d_set_d_op(dentry, &afs_fs_dentry_operations);

d_add(dentry, inode);
_leave(" = 0 { vn=%u u=%u } -> { ino=%lu v=%llu }",
Expand Down
2 changes: 1 addition & 1 deletion fs/anon_inodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ struct file *anon_inode_getfile(const char *name,
*/
ihold(anon_inode_inode);

path.dentry->d_op = &anon_inodefs_dentry_operations;
d_set_d_op(path.dentry, &anon_inodefs_dentry_operations);
d_instantiate(path.dentry, anon_inode_inode);

error = -ENFILE;
Expand Down
2 changes: 1 addition & 1 deletion fs/autofs4/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
goto fail_iput;
pipe = NULL;

root->d_op = &autofs4_sb_dentry_operations;
d_set_d_op(root, &autofs4_sb_dentry_operations);
root->d_fsdata = ino;

/* Can this call block? */
Expand Down
10 changes: 5 additions & 5 deletions fs/autofs4/root.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
* we check for the hashed dentry and return the newly
* hashed dentry.
*/
dentry->d_op = &autofs4_root_dentry_operations;
d_set_d_op(dentry, &autofs4_root_dentry_operations);

/*
* And we need to ensure that the same dentry is used for
Expand Down Expand Up @@ -710,9 +710,9 @@ static int autofs4_dir_symlink(struct inode *dir,
d_add(dentry, inode);

if (dir == dir->i_sb->s_root->d_inode)
dentry->d_op = &autofs4_root_dentry_operations;
d_set_d_op(dentry, &autofs4_root_dentry_operations);
else
dentry->d_op = &autofs4_dentry_operations;
d_set_d_op(dentry, &autofs4_dentry_operations);

dentry->d_fsdata = ino;
ino->dentry = dget(dentry);
Expand Down Expand Up @@ -845,9 +845,9 @@ static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode)
d_add(dentry, inode);

if (dir == dir->i_sb->s_root->d_inode)
dentry->d_op = &autofs4_root_dentry_operations;
d_set_d_op(dentry, &autofs4_root_dentry_operations);
else
dentry->d_op = &autofs4_dentry_operations;
d_set_d_op(dentry, &autofs4_dentry_operations);

dentry->d_fsdata = ino;
ino->dentry = dget(dentry);
Expand Down
4 changes: 2 additions & 2 deletions fs/btrfs/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static struct dentry *btrfs_get_dentry(struct super_block *sb, u64 objectid,

dentry = d_obtain_alias(inode);
if (!IS_ERR(dentry))
dentry->d_op = &btrfs_dentry_operations;
d_set_d_op(dentry, &btrfs_dentry_operations);
return dentry;
fail:
srcu_read_unlock(&fs_info->subvol_srcu, index);
Expand Down Expand Up @@ -225,7 +225,7 @@ static struct dentry *btrfs_get_parent(struct dentry *child)
key.offset = 0;
dentry = d_obtain_alias(btrfs_iget(root->fs_info->sb, &key, root, NULL));
if (!IS_ERR(dentry))
dentry->d_op = &btrfs_dentry_operations;
d_set_d_op(dentry, &btrfs_dentry_operations);
return dentry;
fail:
btrfs_free_path(path);
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -4084,7 +4084,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
int index;
int ret;

dentry->d_op = &btrfs_dentry_operations;
d_set_d_op(dentry, &btrfs_dentry_operations);

if (dentry->d_name.len > BTRFS_NAME_LEN)
return ERR_PTR(-ENAMETOOLONG);
Expand Down
6 changes: 3 additions & 3 deletions fs/ceph/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ int ceph_init_dentry(struct dentry *dentry)

if (dentry->d_parent == NULL || /* nfs fh_to_dentry */
ceph_snap(dentry->d_parent->d_inode) == CEPH_NOSNAP)
dentry->d_op = &ceph_dentry_ops;
d_set_d_op(dentry, &ceph_dentry_ops);
else if (ceph_snap(dentry->d_parent->d_inode) == CEPH_SNAPDIR)
dentry->d_op = &ceph_snapdir_dentry_ops;
d_set_d_op(dentry, &ceph_snapdir_dentry_ops);
else
dentry->d_op = &ceph_snap_dentry_ops;
d_set_d_op(dentry, &ceph_snap_dentry_ops);

di = kmem_cache_alloc(ceph_dentry_cachep, GFP_NOFS | __GFP_ZERO);
if (!di)
Expand Down
16 changes: 8 additions & 8 deletions fs/cifs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ static void setup_cifs_dentry(struct cifsTconInfo *tcon,
struct inode *newinode)
{
if (tcon->nocase)
direntry->d_op = &cifs_ci_dentry_ops;
d_set_d_op(direntry, &cifs_ci_dentry_ops);
else
direntry->d_op = &cifs_dentry_ops;
d_set_d_op(direntry, &cifs_dentry_ops);
d_instantiate(direntry, newinode);
}

Expand Down Expand Up @@ -421,9 +421,9 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode,
rc = cifs_get_inode_info_unix(&newinode, full_path,
inode->i_sb, xid);
if (pTcon->nocase)
direntry->d_op = &cifs_ci_dentry_ops;
d_set_d_op(direntry, &cifs_ci_dentry_ops);
else
direntry->d_op = &cifs_dentry_ops;
d_set_d_op(direntry, &cifs_dentry_ops);

if (rc == 0)
d_instantiate(direntry, newinode);
Expand Down Expand Up @@ -604,9 +604,9 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,

if ((rc == 0) && (newInode != NULL)) {
if (pTcon->nocase)
direntry->d_op = &cifs_ci_dentry_ops;
d_set_d_op(direntry, &cifs_ci_dentry_ops);
else
direntry->d_op = &cifs_dentry_ops;
d_set_d_op(direntry, &cifs_dentry_ops);
d_add(direntry, newInode);
if (posix_open) {
filp = lookup_instantiate_filp(nd, direntry,
Expand Down Expand Up @@ -634,9 +634,9 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
rc = 0;
direntry->d_time = jiffies;
if (pTcon->nocase)
direntry->d_op = &cifs_ci_dentry_ops;
d_set_d_op(direntry, &cifs_ci_dentry_ops);
else
direntry->d_op = &cifs_dentry_ops;
d_set_d_op(direntry, &cifs_dentry_ops);
d_add(direntry, NULL);
/* if it was once a directory (but how can we tell?) we could do
shrink_dcache_parent(direntry); */
Expand Down
8 changes: 4 additions & 4 deletions fs/cifs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1319,9 +1319,9 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
to set uid/gid */
inc_nlink(inode);
if (pTcon->nocase)
direntry->d_op = &cifs_ci_dentry_ops;
d_set_d_op(direntry, &cifs_ci_dentry_ops);
else
direntry->d_op = &cifs_dentry_ops;
d_set_d_op(direntry, &cifs_dentry_ops);

cifs_unix_basic_to_fattr(&fattr, pInfo, cifs_sb);
cifs_fill_uniqueid(inode->i_sb, &fattr);
Expand Down Expand Up @@ -1363,9 +1363,9 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
inode->i_sb, xid, NULL);

if (pTcon->nocase)
direntry->d_op = &cifs_ci_dentry_ops;
d_set_d_op(direntry, &cifs_ci_dentry_ops);
else
direntry->d_op = &cifs_dentry_ops;
d_set_d_op(direntry, &cifs_dentry_ops);
d_instantiate(direntry, newinode);
/* setting nlink not necessary except in cases where we
* failed to get it from the server or was set bogus */
Expand Down
4 changes: 2 additions & 2 deletions fs/cifs/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,9 @@ cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
rc);
} else {
if (pTcon->nocase)
direntry->d_op = &cifs_ci_dentry_ops;
d_set_d_op(direntry, &cifs_ci_dentry_ops);
else
direntry->d_op = &cifs_dentry_ops;
d_set_d_op(direntry, &cifs_dentry_ops);
d_instantiate(direntry, newinode);
}
}
Expand Down
4 changes: 2 additions & 2 deletions fs/cifs/readdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ cifs_readdir_lookup(struct dentry *parent, struct qstr *name,
}

if (cifs_sb_master_tcon(CIFS_SB(sb))->nocase)
dentry->d_op = &cifs_ci_dentry_ops;
d_set_d_op(dentry, &cifs_ci_dentry_ops);
else
dentry->d_op = &cifs_dentry_ops;
d_set_d_op(dentry, &cifs_dentry_ops);

alias = d_materialise_unique(dentry, inode);
if (alias != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion fs/coda/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static struct dentry *coda_lookup(struct inode *dir, struct dentry *entry, struc
return ERR_PTR(error);

exit:
entry->d_op = &coda_dentry_operations;
d_set_d_op(entry, &coda_dentry_operations);

if (inode && (type & CODA_NOCACHE))
coda_flag_inode(inode, C_VATTR | C_PURGE);
Expand Down
Loading

0 comments on commit fb045ad

Please sign in to comment.