]> git.baikalelectronics.ru Git - kernel.git/commitdiff
nfs: optimise readdir cache page invalidation
authorDai Ngo <dai.ngo@oracle.com>
Thu, 23 Jan 2020 01:45:39 +0000 (20:45 -0500)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Tue, 4 Feb 2020 15:50:44 +0000 (10:50 -0500)
When the directory is large and it's being modified by one client
while another client is doing the 'ls -l' on the same directory then
the cache page invalidation from nfs_force_use_readdirplus causes
the reading client to keep restarting READDIRPLUS from cookie 0
which causes the 'ls -l' to take a very long time to complete,
possibly never completing.

Currently when nfs_force_use_readdirplus is called to switch from
READDIR to READDIRPLUS, it invalidates all the cached pages of the
directory. This cache page invalidation causes the next nfs_readdir
to re-read the directory content from cookie 0.

This patch is to optimise the cache invalidation in
nfs_force_use_readdirplus by only truncating the cached pages from
last page index accessed to the end the file. It also marks the
inode to delay invalidating all the cached page of the directory
until the next initial nfs_readdir of the next 'ls' instance.

Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
Reviewed-by: Trond Myklebust <trond.myklebust@hammerspace.com>
[Anna - Fix conflicts with Trond's readdir patches]
[Anna - Remove redundant call to nfs_zap_mapping()]
[Anna - Replace d_inode(file_dentry(desc->file)) with file_inode(desc->file)]
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
fs/nfs/dir.c
include/linux/nfs_fs.h

index 88f6cf1ccf8c28af015d8d728097354270bdb99f..1320288ff9ec9c7d50d207908d77f3899c7def3b 100644 (file)
@@ -449,7 +449,8 @@ void nfs_force_use_readdirplus(struct inode *dir)
        if (nfs_server_capable(dir, NFS_CAP_READDIRPLUS) &&
            !list_empty(&nfsi->open_files)) {
                set_bit(NFS_INO_ADVISE_RDPLUS, &nfsi->flags);
-               invalidate_mapping_pages(dir->i_mapping, 0, -1);
+               invalidate_mapping_pages(dir->i_mapping,
+                       nfsi->page_index + 1, -1);
        }
 }
 
@@ -720,6 +721,8 @@ struct page *get_cache_page(nfs_readdir_descriptor_t *desc)
 static
 int find_and_lock_cache_page(nfs_readdir_descriptor_t *desc)
 {
+       struct inode *inode = file_inode(desc->file);
+       struct nfs_inode *nfsi = NFS_I(inode);
        int res;
 
        desc->page = get_cache_page(desc);
@@ -731,8 +734,10 @@ int find_and_lock_cache_page(nfs_readdir_descriptor_t *desc)
        res = -EAGAIN;
        if (desc->page->mapping != NULL) {
                res = nfs_readdir_search_array(desc);
-               if (res == 0)
+               if (res == 0) {
+                       nfsi->page_index = desc->page_index;
                        return 0;
+               }
        }
        unlock_page(desc->page);
 error:
index c06b1fd130f33cf6a64554c7de1e8c3e8f11f29b..a5f8f03ecd59e1f6dce820247cd18b69a157be11 100644 (file)
@@ -168,6 +168,9 @@ struct nfs_inode {
        struct rw_semaphore     rmdir_sem;
        struct mutex            commit_mutex;
 
+       /* track last access to cached pages */
+       unsigned long           page_index;
+
 #if IS_ENABLED(CONFIG_NFS_V4)
        struct nfs4_cached_acl  *nfs4_acl;
         /* NFSv4 state */