Skip to content

Commit

Permalink
nfsd: add a new struct file caching facility to nfsd
Browse files Browse the repository at this point in the history
Currently, NFSv2/3 reads and writes have to open a file, do the read or
write and then close it again for each RPC. This is highly inefficient,
especially when the underlying filesystem has a relatively slow open
routine.

This patch adds a new open file cache to knfsd. Rather than doing an
open for each RPC, the read/write handlers can call into this cache to
see if there is one already there for the correct filehandle and
NFS_MAY_READ/WRITE flags.

If there isn't an entry, then we create a new one and attempt to
perform the open. If there is, then we wait until the entry is fully
instantiated and return it if it is at the end of the wait. If it's
not, then we attempt to take over construction.

Since the main goal is to speed up NFSv2/3 I/O, we don't want to
close these files on last put of these objects. We need to keep them
around for a little while since we never know when the next READ/WRITE
will come in.

Cache entries have a hardcoded 1s timeout, and we have a recurring
workqueue job that walks the cache and purges any entries that have
expired.

Signed-off-by: Jeff Layton <[email protected]>
Signed-off-by: Weston Andros Adamson <[email protected]>
Signed-off-by: Richard Sharpe <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
Signed-off-by: J. Bruce Fields <[email protected]>
  • Loading branch information
Jeff Layton authored and J. Bruce Fields committed Aug 19, 2019
1 parent 7239a40 commit 65294c1
Show file tree
Hide file tree
Showing 9 changed files with 1,155 additions and 24 deletions.
1 change: 1 addition & 0 deletions fs/nfsd/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ config NFSD
tristate "NFS server support"
depends on INET
depends on FILE_LOCKING
depends on FSNOTIFY
select LOCKD
select SUNRPC
select EXPORTFS
Expand Down
3 changes: 2 additions & 1 deletion fs/nfsd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ obj-$(CONFIG_NFSD) += nfsd.o
nfsd-y += trace.o

nfsd-y += nfssvc.o nfsctl.o nfsproc.o nfsfh.o vfs.o \
export.o auth.o lockd.o nfscache.o nfsxdr.o stats.o
export.o auth.o lockd.o nfscache.o nfsxdr.o \
stats.o filecache.o
nfsd-$(CONFIG_NFSD_FAULT_INJECTION) += fault_inject.o
nfsd-$(CONFIG_NFSD_V2_ACL) += nfs2acl.o
nfsd-$(CONFIG_NFSD_V3) += nfs3proc.o nfs3xdr.o
Expand Down
13 changes: 13 additions & 0 deletions fs/nfsd/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "nfsfh.h"
#include "netns.h"
#include "pnfs.h"
#include "filecache.h"

#define NFSDDBG_FACILITY NFSDDBG_EXPORT

Expand Down Expand Up @@ -232,6 +233,17 @@ static struct cache_head *expkey_alloc(void)
return NULL;
}

static void expkey_flush(void)
{
/*
* Take the nfsd_mutex here to ensure that the file cache is not
* destroyed while we're in the middle of flushing.
*/
mutex_lock(&nfsd_mutex);
nfsd_file_cache_purge();
mutex_unlock(&nfsd_mutex);
}

static const struct cache_detail svc_expkey_cache_template = {
.owner = THIS_MODULE,
.hash_size = EXPKEY_HASHMAX,
Expand All @@ -244,6 +256,7 @@ static const struct cache_detail svc_expkey_cache_template = {
.init = expkey_init,
.update = expkey_update,
.alloc = expkey_alloc,
.flush = expkey_flush,
};

static int
Expand Down
Loading

0 comments on commit 65294c1

Please sign in to comment.