nfs: optimise readdir cache page invalidation
Subsystems (2)
Dai Ngo
reviewerPATCH v2 1/1 nfs: optimise readdir cache page invalidation
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.
--- fs/nfs/dir.c | 13 ++++++++++++- include/linux/nfs_fs.h | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-)
fs/nfs/dir.c +12 -1
@@ -437,7 +437,9 @@ 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 ); +nfs_zap_mapping (dir, dir->i_mapping); +invalidate_mapping_pages (dir->i_mapping, + nfsi->page_index +1 ,-1 ); } }
@@ -709,6 +711,9 @@ struct page *get_cache_page(nfs_readdir_descriptor_t *desc)int find_cache_page (nfs_readdir_descriptor_t *desc) {int res; +struct inode *inode; +struct nfs_inode *nfsi; +struct dentry *dentry; desc->page =get_cache_page (desc);if (IS_ERR (desc->page))
@@ -717,6 +722,12 @@ int find_cache_page(nfs_readdir_descriptor_t *desc) res =nfs_readdir_search_array (desc);if (res !=0 )cache_page_release (desc); + + dentry =file_dentry (desc->file); + inode =d_inode (dentry); + nfsi =NFS_I (inode); + nfsi->page_index = desc->page_index; +return res; }
include/linux/nfs_fs.h +3 -0
@@ -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 */
Signature · 1 line
1.8.3.1
Quoted 12 lines · Dai Ngo
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_readdirpluscauses 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_readdirplusis called to switch from READDIR to READDIRPLUS, it invalidates all the cached pages of the directory. This cache page invalidation causes the nextnfs_readdirto re-read the directory content from cookie 0.
Quoted 7 lines
This patch is to optimise the cache invalidation in
nfs_force_use_readdirplusby 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 initialnfs_readdirof the next 'ls' instance.Signed-off-by Dai Ngo <[email protected]>
Quoted 60 lines
--- fs/nfs/dir.c | 13 ++++++++++++- include/linux/nfs_fs.h | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-)fs/nfs/dir.c +6
-1@@ -437,7 +437,9 @@ 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 ); +nfs_zap_mapping (dir, dir->i_mapping); +invalidate_mapping_pages (dir->i_mapping, + nfsi->page_index +1 ,-1 ); } }@@ -709,6 +711,9 @@ struct page *get_cache_page(nfs_readdir_descriptor_t *desc)int find_cache_page (nfs_readdir_descriptor_t *desc) {int res; +struct inode *inode; +struct nfs_inode *nfsi; +struct dentry *dentry; desc->page =get_cache_page (desc);fs/nfs/dir.c +6
-0if (IS_ERR (desc->page))@@ -717,6 +722,12 @@ int find_cache_page(nfs_readdir_descriptor_t *desc) res =nfs_readdir_search_array (desc);if (res !=0 )cache_page_release (desc); + + dentry =file_dentry (desc->file); + inode =d_inode (dentry); + nfsi =NFS_I (inode); + nfsi->page_index = desc->page_index; +return res; }include/linux/nfs_fs.h +3
-0@@ -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 */
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]