Skip to content

Commit 85aa8dd

Browse files
bcodding-rhTrond Myklebust
authored andcommitted
NFS: Trigger the "ls -l" readdir heuristic sooner
Since commit 1a34c8c ("NFS: Support larger readdir buffers") has updated dtsize, and with recent improvements to the READDIRPLUS helper heuristic, the heuristic may not trigger until many dentries are emitted to userspace. This will cause many thousands of GETATTR calls for "ls -l" when the directory's pagecache has already been populated. This manifests as poor performance for long directory listings after an initially fast "ls -l". Fix this by emitting only 17 entries for any first pass through the NFS directory's ->iterate_shared(), which allows userpace to prime the counters for the heuristic. Signed-off-by: Benjamin Coddington <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent c528f70 commit 85aa8dd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

fs/nfs/dir.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,8 @@ static int readdir_search_pagecache(struct nfs_readdir_descriptor *desc)
10741074
return res;
10751075
}
10761076

1077+
#define NFS_READDIR_CACHE_MISS_THRESHOLD (16UL)
1078+
10771079
/*
10781080
* Once we've found the start of the dirent within a page: fill 'er up...
10791081
*/
@@ -1083,6 +1085,7 @@ static void nfs_do_filldir(struct nfs_readdir_descriptor *desc,
10831085
struct file *file = desc->file;
10841086
struct nfs_cache_array *array;
10851087
unsigned int i;
1088+
bool first_emit = !desc->dir_cookie;
10861089

10871090
array = kmap_local_page(desc->page);
10881091
for (i = desc->cache_entry_index; i < array->size; i++) {
@@ -1106,6 +1109,10 @@ static void nfs_do_filldir(struct nfs_readdir_descriptor *desc,
11061109
desc->ctx->pos = desc->dir_cookie;
11071110
else
11081111
desc->ctx->pos++;
1112+
if (first_emit && i > NFS_READDIR_CACHE_MISS_THRESHOLD + 1) {
1113+
desc->eob = true;
1114+
break;
1115+
}
11091116
}
11101117
if (array->page_is_eof)
11111118
desc->eof = !desc->eob;
@@ -1187,8 +1194,6 @@ static int uncached_readdir(struct nfs_readdir_descriptor *desc)
11871194
return status;
11881195
}
11891196

1190-
#define NFS_READDIR_CACHE_MISS_THRESHOLD (16UL)
1191-
11921197
static bool nfs_readdir_handle_cache_misses(struct inode *inode,
11931198
struct nfs_readdir_descriptor *desc,
11941199
unsigned int cache_misses,

0 commit comments

Comments
 (0)