NFS: Don't ask for readdirplus unless it can help nfs_getattr()
If attribute caching is turned off, then use of readdirplus is not going to help stat() performance. Readdirplus also doesn't help if a file is being written to, since we will have to flush those writes in order to sync the mtime/ctime. Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
This commit is contained in:
@@ -780,27 +780,33 @@ void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr,
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(nfs_setattr_update_inode);
|
EXPORT_SYMBOL_GPL(nfs_setattr_update_inode);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Don't request help from readdirplus if the file is being written to,
|
||||||
|
* or if attribute caching is turned off
|
||||||
|
*/
|
||||||
|
static bool nfs_getattr_readdirplus_enable(const struct inode *inode)
|
||||||
|
{
|
||||||
|
return nfs_server_capable(inode, NFS_CAP_READDIRPLUS) &&
|
||||||
|
!nfs_have_writebacks(inode) && NFS_MAXATTRTIMEO(inode) > 5 * HZ;
|
||||||
|
}
|
||||||
|
|
||||||
static void nfs_readdirplus_parent_cache_miss(struct dentry *dentry)
|
static void nfs_readdirplus_parent_cache_miss(struct dentry *dentry)
|
||||||
{
|
{
|
||||||
struct dentry *parent;
|
if (!IS_ROOT(dentry)) {
|
||||||
|
struct dentry *parent = dget_parent(dentry);
|
||||||
if (!nfs_server_capable(d_inode(dentry), NFS_CAP_READDIRPLUS))
|
|
||||||
return;
|
|
||||||
parent = dget_parent(dentry);
|
|
||||||
nfs_readdir_record_entry_cache_miss(d_inode(parent));
|
nfs_readdir_record_entry_cache_miss(d_inode(parent));
|
||||||
dput(parent);
|
dput(parent);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void nfs_readdirplus_parent_cache_hit(struct dentry *dentry)
|
static void nfs_readdirplus_parent_cache_hit(struct dentry *dentry)
|
||||||
{
|
{
|
||||||
struct dentry *parent;
|
if (!IS_ROOT(dentry)) {
|
||||||
|
struct dentry *parent = dget_parent(dentry);
|
||||||
if (!nfs_server_capable(d_inode(dentry), NFS_CAP_READDIRPLUS))
|
|
||||||
return;
|
|
||||||
parent = dget_parent(dentry);
|
|
||||||
nfs_readdir_record_entry_cache_hit(d_inode(parent));
|
nfs_readdir_record_entry_cache_hit(d_inode(parent));
|
||||||
dput(parent);
|
dput(parent);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static u32 nfs_get_valid_attrmask(struct inode *inode)
|
static u32 nfs_get_valid_attrmask(struct inode *inode)
|
||||||
{
|
{
|
||||||
@@ -835,6 +841,7 @@ int nfs_getattr(struct user_namespace *mnt_userns, const struct path *path,
|
|||||||
int err = 0;
|
int err = 0;
|
||||||
bool force_sync = query_flags & AT_STATX_FORCE_SYNC;
|
bool force_sync = query_flags & AT_STATX_FORCE_SYNC;
|
||||||
bool do_update = false;
|
bool do_update = false;
|
||||||
|
bool readdirplus_enabled = nfs_getattr_readdirplus_enable(inode);
|
||||||
|
|
||||||
trace_nfs_getattr_enter(inode);
|
trace_nfs_getattr_enter(inode);
|
||||||
|
|
||||||
@@ -843,6 +850,7 @@ int nfs_getattr(struct user_namespace *mnt_userns, const struct path *path,
|
|||||||
STATX_INO | STATX_SIZE | STATX_BLOCKS;
|
STATX_INO | STATX_SIZE | STATX_BLOCKS;
|
||||||
|
|
||||||
if ((query_flags & AT_STATX_DONT_SYNC) && !force_sync) {
|
if ((query_flags & AT_STATX_DONT_SYNC) && !force_sync) {
|
||||||
|
if (readdirplus_enabled)
|
||||||
nfs_readdirplus_parent_cache_hit(path->dentry);
|
nfs_readdirplus_parent_cache_hit(path->dentry);
|
||||||
goto out_no_revalidate;
|
goto out_no_revalidate;
|
||||||
}
|
}
|
||||||
@@ -893,15 +901,12 @@ int nfs_getattr(struct user_namespace *mnt_userns, const struct path *path,
|
|||||||
do_update |= cache_validity & NFS_INO_INVALID_BLOCKS;
|
do_update |= cache_validity & NFS_INO_INVALID_BLOCKS;
|
||||||
|
|
||||||
if (do_update) {
|
if (do_update) {
|
||||||
/* Update the attribute cache */
|
if (readdirplus_enabled)
|
||||||
if (!(server->flags & NFS_MOUNT_NOAC))
|
|
||||||
nfs_readdirplus_parent_cache_miss(path->dentry);
|
nfs_readdirplus_parent_cache_miss(path->dentry);
|
||||||
else
|
|
||||||
nfs_readdirplus_parent_cache_hit(path->dentry);
|
|
||||||
err = __nfs_revalidate_inode(server, inode);
|
err = __nfs_revalidate_inode(server, inode);
|
||||||
if (err)
|
if (err)
|
||||||
goto out;
|
goto out;
|
||||||
} else
|
} else if (readdirplus_enabled)
|
||||||
nfs_readdirplus_parent_cache_hit(path->dentry);
|
nfs_readdirplus_parent_cache_hit(path->dentry);
|
||||||
out_no_revalidate:
|
out_no_revalidate:
|
||||||
/* Only return attributes that were revalidated. */
|
/* Only return attributes that were revalidated. */
|
||||||
|
|||||||
Reference in New Issue
Block a user