NFS: Reduce use of uncached readdir
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Thu, 17 Feb 2022 18:02:37 +0000 (13:02 -0500)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Wed, 2 Mar 2022 13:43:38 +0000 (08:43 -0500)
When reading a very large directory, we want to try to keep the page
cache up to date if doing so is inexpensive. With the change to allow
readdir to continue reading even when the cache is incomplete, we no
longer need to fall back to uncached readdir in order to scale to large
directories.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/dir.c

index 9d086ab..dc6acfd 100644 (file)
@@ -999,28 +999,11 @@ static int find_and_lock_cache_page(struct nfs_readdir_descriptor *desc)
        return res;
 }
 
-static bool nfs_readdir_dont_search_cache(struct nfs_readdir_descriptor *desc)
-{
-       struct address_space *mapping = desc->file->f_mapping;
-       struct inode *dir = file_inode(desc->file);
-       unsigned int dtsize = NFS_SERVER(dir)->dtsize;
-       loff_t size = i_size_read(dir);
-
-       /*
-        * Default to uncached readdir if the page cache is empty, and
-        * we're looking for a non-zero cookie in a large directory.
-        */
-       return desc->dir_cookie != 0 && mapping->nrpages == 0 && size > dtsize;
-}
-
 /* Search for desc->dir_cookie from the beginning of the page cache */
 static int readdir_search_pagecache(struct nfs_readdir_descriptor *desc)
 {
        int res;
 
-       if (nfs_readdir_dont_search_cache(desc))
-               return -EBADCOOKIE;
-
        do {
                if (desc->page_index == 0) {
                        desc->current_index = 0;
@@ -1273,10 +1256,10 @@ static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int whence)
        }
        if (offset != filp->f_pos) {
                filp->f_pos = offset;
-               if (!nfs_readdir_use_cookie(filp)) {
+               dir_ctx->page_index = 0;
+               if (!nfs_readdir_use_cookie(filp))
                        dir_ctx->dir_cookie = 0;
-                       dir_ctx->page_index = 0;
-               } else
+               else
                        dir_ctx->dir_cookie = offset;
                if (offset == 0)
                        memset(dir_ctx->verf, 0, sizeof(dir_ctx->verf));