nfs: optimise readdir cache page invalidation
Subsystems (2)
Dai Ngo
reviewerRFC PATCH 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 | 14 +++++++++++++- include/linux/nfs_fs.h | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-)
fs/nfs/dir.c +13 -1
@@ -437,7 +437,10 @@ 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); +if (NFS_PROTO (dir)->version ==3 ) +invalidate_mapping_pages (dir->i_mapping, + nfsi->page_index +1 ,-1 ); } }
@@ -709,6 +712,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 +723,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 30 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.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]>--- fs/nfs/dir.c | 14 +++++++++++++- include/linux/nfs_fs.h | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-)fs/nfs/dir.c +0
-0
fs/nfs/dir.c void nfs_force_use_readdirplus(struct inode · line 444
Quoted 9 lines
fs/nfs/dir.c +4
-1@@ -437,7 +437,10 @@ 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); +if (NFS_PROTO (dir)->version ==3 ) +invalidate_mapping_pages (dir->i_mapping, + nfsi->page_index +1 ,-1 );
Let's do this for NFSv4 as well. The motivation is the same: to allow us to replace a series of GETATTR calls to one or more READDIRPLUS calls.
Quoted 33 lines
fs/nfs/dir.c +3
-0} }@@ -709,6 +712,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 +723,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 +0
-0
include/linux/nfs_fs.h struct nfs_inode { · line 176
Quoted 9 lines
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 */
Otherwise, the patch looks good to me.
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
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 62 lines
--- fs/nfs/dir.c | 14 +++++++++++++- include/linux/nfs_fs.h | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-)fs/nfs/dir.c +7
-1@@ -437,7 +437,10 @@ 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); +if (NFS_PROTO (dir)->version ==3 ) +invalidate_mapping_pages (dir->i_mapping, + nfsi->page_index +1 ,-1 ); } }@@ -709,6 +712,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 +723,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]
Quoted 20 lines · Trond Myklebust
Quoted 19 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 fromnfs_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.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.
Quoted 3 lines
Quoted 1 line
Signed-off-by Dai Ngo <[email protected]>Reviewed-by Trond Myklebust <[email protected]>
Sorry I intended this for the PATCHv2... I've looked through that version and it looks OK to me.
Anna, please apply the later v2 instead of this one...
Quoted 62 lines
Quoted 62 lines
--- fs/nfs/dir.c | 14 +++++++++++++- include/linux/nfs_fs.h | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-)fs/nfs/dir.c +7
-1@@ -437,7 +437,10 @@ 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); +if (NFS_PROTO (dir)->version ==3 ) +invalidate_mapping_pages (dir->i_mapping, + nfsi->page_index +1 ,-1 ); } }@@ -709,6 +712,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 +723,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 · 5 lines
Trond Myklebust CTO, Hammerspace Inc 4300 El Camino Real, Suite 105 Los Altos, CA 94022 www.hammer.space
Quoted 27 lines · Trond Myklebust
NetApp Security WARNING: This is an external email. Do not click links or open attachments unless you recognize the sender and know the content is safe.
Quoted 20 lines · Trond Myklebust
Quoted 19 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 fromnfs_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.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.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Dai Ngo <[email protected]>Reviewed-by Trond Myklebust <[email protected]>Sorry I intended this for the PATCHv2... I've looked through that version and it looks OK to me.
Anna, please apply the later v2 instead of this one...
I applied the v2 about 5 minutes before you sent this. I'll make sure your Reviewed-by gets added to it, too :)
Anna
Quoted 70 lines
Quoted 56 lines
Quoted 56 lines
--- fs/nfs/dir.c | 14 +++++++++++++- include/linux/nfs_fs.h | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-)fs/nfs/dir.c +7
-1@@ -437,7 +437,10 @@ 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); +if (NFS_PROTO (dir)->version ==3 ) +invalidate_mapping_pages (dir->i_mapping, + nfsi->page_index +1 ,-1 ); } }@@ -709,6 +712,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))fs/nfs/dir.c +6
-0@@ -717,6 +723,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 +0
-0@@ -168,6 +168,9 @@ struct nfs_inode {struct rw_semaphore rmdir_sem;struct mutex commit_mutex;Quoted 6 lines
include/linux/nfs_fs.h struct nfs_inode { · line 176
Quoted 6 lines
include/linux/nfs_fs.h +3
-0+/* track last access to cached pages */ +unsigned long page_index; +#if IS_ENABLED (CONFIG_NFS_V4 )struct nfs4_cached_acl *nfs4_acl;/* NFSv4 state */ --
Trond Myklebust
CTO, Hammerspace Inc
4300 El Camino Real, Suite 105
Los Altos, CA 94022
www.hammer.space