NFS: Readdir plus in v4
Subsystems (2)
PATCH 10/10 NFS: Readdir plus in v4
By requsting more attributes during a readdir, we can mimic the readdir plus operation that was in NFSv3.
To test, I ran the command ls -lU --color=none on directories with various numbers of files. Without readdir plus, I see this:
n files | 100 | 1,000 | 10,000 | 100,000 | 1,000,000
--------+-----------+-----------+-----------+-----------+----------
real | 0m00.153s | 0m00.589s | 0m05.601s | 0m56.691s | 9m59.128s user | 0m00.007s | 0m00.007s | 0m00.077s | 0m00.703s | 0m06.800s sys | 0m00.010s | 0m00.070s | 0m00.633s | 0m06.423s | 1m10.005s access | 3 | 1 | 1 | 4 | 31 getattr | 2 | 1 | 1 | 1 | 1 lookup | 104 | 1,003 | 10,003 | 100,003 | 1,000,003 readdir | 2 | 16 | 158 | 1,575 | 15,749 total | 111 | 1,021 | 10,163 | 101,583 | 1,015,784
With readdir plus enabled, I see this:
n files | 100 | 1,000 | 10,000 | 100,000 | 1,000,000
--------+-----------+-----------+-----------+-----------+----------
real | 0m00.115s | 0m00.206s | 0m01.079s | 0m12.521s | 2m07.528s user | 0m00.003s | 0m00.003s | 0m00.040s | 0m00.290s | 0m03.296s sys | 0m00.007s | 0m00.020s | 0m00.120s | 0m01.357s | 0m17.556s access | 3 | 1 | 1 | 1 | 7 getattr | 2 | 1 | 1 | 1 | 1 lookup | 4 | 3 | 3 | 3 | 3 readdir | 6 | 62 | 630 | 6,300 | 62,993 total | 15 | 67 | 635 | 6,305 | 63,004
Readdir plus disabled has about a 16x increase in the number of rpc calls and is 4 - 5 times slower on large directories.
Signed-off-by Bryan Schumaker <[email protected]>
Signed-off-by Trond Myklebust <[email protected]>
--- fs/nfs/client.c | 5 ++- fs/nfs/dir.c | 4 +- fs/nfs/internal.h | 6 ++-- fs/nfs/nfs2xdr.c | 2 +- fs/nfs/nfs3xdr.c | 2 +- fs/nfs/nfs4_fs.h | 2 +- fs/nfs/nfs4proc.c | 1 + fs/nfs/nfs4xdr.c | 55 +++++++++++++++++++++++------------------------ include/linux/nfs_xdr.h | 3 +- 9 files changed, 41 insertions(+), 39 deletions(-)
fs/nfs/client.c +3 -2
@@ -1358,8 +1358,9 @@ static int nfs4_init_server(struct nfs_server *server,/* Initialise the client representation from the mount data */ server->flags = data->flags; - server->caps |=NFS_CAP_ATOMIC_OPEN |NFS_CAP_CHANGE_ATTR | -NFS_CAP_POSIX_LOCK ; + server->caps |=NFS_CAP_ATOMIC_OPEN |NFS_CAP_CHANGE_ATTR |NFS_CAP_POSIX_LOCK ; +if (!(data->flags &NFS_MOUNT_NORDIRPLUS )) + server->caps |=NFS_CAP_READDIRPLUS ; server->options = data->options;/* Get a client record */
fs/nfs/dir.c +2 -2
@@ -172,7 +172,7 @@ struct nfs_cache_array {#define MAX_READDIR_ARRAY ((PAGE_SIZE - sizeof(struct nfs_cache_array)) / sizeof(struct nfs_cache_array_entry)) -typedef __be32 * (*decode_dirent_t )(struct xdr_stream *,struct nfs_entry *,int ); +typedef __be32 * (*decode_dirent_t )(struct xdr_stream *,struct nfs_entry *,struct nfs_server *,int ); typedef struct { struct file *file; struct page *page;
@@ -360,7 +360,7 @@ error:static int xdr_decode (nfs_readdir_descriptor_t *desc,struct nfs_entry *entry,struct xdr_stream *stream) { -__be32 *p = desc->decode (stream, entry, desc->plus); +__be32 *p = desc->decode (stream, entry,NFS_SERVER (desc->file->f_path.dentry->d_inode), desc->plus);if (IS_ERR (p))return PTR_ERR (p);
fs/nfs/internal.h +3 -3
@@ -187,15 +187,15 @@ extern void nfs_destroy_directcache(void);/* nfs2xdr.c */ extern int nfs_stat_to_errno (int );extern struct rpc_procinfo nfs_procedures[]; -extern __be32 *nfs_decode_dirent (struct xdr_stream *,struct nfs_entry *,int ); +extern __be32 *nfs_decode_dirent (struct xdr_stream *,struct nfs_entry *,struct nfs_server *,int );/* nfs3xdr.c */ extern struct rpc_procinfo nfs3_procedures[]; -extern __be32 *nfs3_decode_dirent (struct xdr_stream *,struct nfs_entry *,int ); +extern __be32 *nfs3_decode_dirent (struct xdr_stream *,struct nfs_entry *,struct nfs_server *,int );/* nfs4xdr.c */ #ifdef CONFIG_NFS_V4 -extern __be32 *nfs4_decode_dirent (struct xdr_stream *,struct nfs_entry *entry,int plus); +extern __be32 *nfs4_decode_dirent (struct xdr_stream *,struct nfs_entry *,struct nfs_server *,int );#endif #ifdef CONFIG_NFS_V4_1 extern const u32 nfs41_maxread_overhead;
fs/nfs/nfs2xdr.c +1 -1
@@ -454,7 +454,7 @@ static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) }__be32 * -nfs_decode_dirent (struct xdr_stream *xdr,struct nfs_entry *entry,int plus) +nfs_decode_dirent (struct xdr_stream *xdr,struct nfs_entry *entry,struct nfs_server *server,int plus) {__be32 *p; p =xdr_inline_decode (xdr,4 );
fs/nfs/nfs3xdr.c +1 -1
@@ -590,7 +590,7 @@ nfs3_xdr_readdirres(struct rpc_rqst *req, __be32 *p, struct nfs3_readdirres *res }__be32 * -nfs3_decode_dirent (struct xdr_stream *xdr,struct nfs_entry *entry,int plus) +nfs3_decode_dirent (struct xdr_stream *xdr,struct nfs_entry *entry,struct nfs_server *server,int plus) {__be32 *p;struct nfs_entry old = *entry;
fs/nfs/nfs4_fs.h +1 -1
@@ -331,7 +331,7 @@ extern void nfs_free_seqid(struct nfs_seqid *seqid);extern const nfs4_stateid zero_stateid;/* nfs4xdr.c */ -extern __be32 *nfs4_decode_dirent (struct xdr_stream *,struct nfs_entry *entry,int plus); +extern __be32 *nfs4_decode_dirent (struct xdr_stream *,struct nfs_entry *,struct nfs_server *,int );extern struct rpc_procinfo nfs4_procedures[];struct nfs4_mount_data ;
fs/nfs/nfs4proc.c +1 -0
@@ -2832,6 +2832,7 @@ static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, .pgbase = 0, .count = count, .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, + .plus = plus, };struct nfs4_readdir_res res;struct rpc_message msg = {
fs/nfs/nfs4xdr.c +27 -28
81 lines not on this page · raw message
include/linux/nfs_xdr.h +2 -1
@@ -778,6 +778,7 @@ struct nfs4_readdir_arg {struct page ** pages;/* zero-copy data */ unsigned int pgbase;/* zero-copy data */ const u32 * bitmask; +int plus;struct nfs4_sequence_args seq_args; };
@@ -1036,7 +1037,7 @@ struct nfs_rpc_ops {int (*pathconf) (struct nfs_server *,struct nfs_fh *,struct nfs_pathconf *);int (*set_capabilities)(struct nfs_server *,struct nfs_fh *); -__be32 *(*decode_dirent)(struct xdr_stream *,struct nfs_entry *,int plus); +__be32 *(*decode_dirent)(struct xdr_stream *,struct nfs_entry *,struct nfs_server *,int plus);void (*read_setup) (struct nfs_read_data *,struct rpc_message *);int (*read_done) (struct rpc_task *,struct nfs_read_data *);void (*write_setup) (struct nfs_write_data *,struct rpc_message *);