aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorTrond Myklebust <trond.myklebust@primarydata.com>2016-11-19 10:54:55 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-01-19 14:18:05 -0500
commite331f2f2b1fbb5157dfb4f0a977bc8c3737e5927 (patch)
tree1d970ceea252cf4de04bbb1d4d02f020de6d3624 /fs
parent4c4d4bec6c904fc050847f977b13052be5745ae1 (diff)
NFS: Fix a performance regression in readdir
commit 79f687a3de9e3ba2518b4ea33f38ca6cbe9133eb upstream. Ben Coddington reports that commit 311324ad1713, by adding the function nfs_dir_mapping_need_revalidate() that checks page cache validity on each call to nfs_readdir() causes a performance regression when the directory is being modified. If the directory is changing while we're iterating through the directory, POSIX does not require us to invalidate the page cache unless the user calls rewinddir(). However, we still do want to ensure that we use readdirplus in order to avoid a load of stat() calls when the user is doing an 'ls -l' workload. The fix should be to invalidate the page cache immediately when we're setting the NFS_INO_ADVISE_RDPLUS bit. Reported-by: Benjamin Coddington <bcodding@redhat.com> Fixes: 311324ad1713 ("NFS: Be more aggressive in using readdirplus...") Reviewed-by: Benjamin Coddington <bcodding@redhat.com> Tested-by: Benjamin Coddington <bcodding@redhat.com> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/nfs/dir.c15
1 files changed, 2 insertions, 13 deletions
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 5f1af4cd1a33..53e02b8bd9bd 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -477,7 +477,7 @@ void nfs_force_use_readdirplus(struct inode *dir)
477{ 477{
478 if (!list_empty(&NFS_I(dir)->open_files)) { 478 if (!list_empty(&NFS_I(dir)->open_files)) {
479 nfs_advise_use_readdirplus(dir); 479 nfs_advise_use_readdirplus(dir);
480 nfs_zap_mapping(dir, dir->i_mapping); 480 invalidate_mapping_pages(dir->i_mapping, 0, -1);
481 } 481 }
482} 482}
483 483
@@ -886,17 +886,6 @@ int uncached_readdir(nfs_readdir_descriptor_t *desc)
886 goto out; 886 goto out;
887} 887}
888 888
889static bool nfs_dir_mapping_need_revalidate(struct inode *dir)
890{
891 struct nfs_inode *nfsi = NFS_I(dir);
892
893 if (nfs_attribute_cache_expired(dir))
894 return true;
895 if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
896 return true;
897 return false;
898}
899
900/* The file offset position represents the dirent entry number. A 889/* The file offset position represents the dirent entry number. A
901 last cookie cache takes care of the common case of reading the 890 last cookie cache takes care of the common case of reading the
902 whole directory. 891 whole directory.
@@ -928,7 +917,7 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx)
928 desc->decode = NFS_PROTO(inode)->decode_dirent; 917 desc->decode = NFS_PROTO(inode)->decode_dirent;
929 desc->plus = nfs_use_readdirplus(inode, ctx) ? 1 : 0; 918 desc->plus = nfs_use_readdirplus(inode, ctx) ? 1 : 0;
930 919
931 if (ctx->pos == 0 || nfs_dir_mapping_need_revalidate(inode)) 920 if (ctx->pos == 0 || nfs_attribute_cache_expired(inode))
932 res = nfs_revalidate_mapping(inode, file->f_mapping); 921 res = nfs_revalidate_mapping(inode, file->f_mapping);
933 if (res < 0) 922 if (res < 0)
934 goto out; 923 goto out;