Skip to content

Commit 65294c1

Browse files
Jeff LaytonJ. Bruce Fields
Jeff Layton
authored and
J. Bruce Fields
committed
nfsd: add a new struct file caching facility to nfsd
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]>
1 parent 7239a40 commit 65294c1

File tree

9 files changed

+1155
-24
lines changed

9 files changed

+1155
-24
lines changed

fs/nfsd/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ config NFSD
33
tristate "NFS server support"
44
depends on INET
55
depends on FILE_LOCKING
6+
depends on FSNOTIFY
67
select LOCKD
78
select SUNRPC
89
select EXPORTFS

fs/nfsd/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ obj-$(CONFIG_NFSD) += nfsd.o
1111
nfsd-y += trace.o
1212

1313
nfsd-y += nfssvc.o nfsctl.o nfsproc.o nfsfh.o vfs.o \
14-
export.o auth.o lockd.o nfscache.o nfsxdr.o stats.o
14+
export.o auth.o lockd.o nfscache.o nfsxdr.o \
15+
stats.o filecache.o
1516
nfsd-$(CONFIG_NFSD_FAULT_INJECTION) += fault_inject.o
1617
nfsd-$(CONFIG_NFSD_V2_ACL) += nfs2acl.o
1718
nfsd-$(CONFIG_NFSD_V3) += nfs3proc.o nfs3xdr.o

fs/nfsd/export.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "nfsfh.h"
2323
#include "netns.h"
2424
#include "pnfs.h"
25+
#include "filecache.h"
2526

2627
#define NFSDDBG_FACILITY NFSDDBG_EXPORT
2728

@@ -232,6 +233,17 @@ static struct cache_head *expkey_alloc(void)
232233
return NULL;
233234
}
234235

236+
static void expkey_flush(void)
237+
{
238+
/*
239+
* Take the nfsd_mutex here to ensure that the file cache is not
240+
* destroyed while we're in the middle of flushing.
241+
*/
242+
mutex_lock(&nfsd_mutex);
243+
nfsd_file_cache_purge();
244+
mutex_unlock(&nfsd_mutex);
245+
}
246+
235247
static const struct cache_detail svc_expkey_cache_template = {
236248
.owner = THIS_MODULE,
237249
.hash_size = EXPKEY_HASHMAX,
@@ -244,6 +256,7 @@ static const struct cache_detail svc_expkey_cache_template = {
244256
.init = expkey_init,
245257
.update = expkey_update,
246258
.alloc = expkey_alloc,
259+
.flush = expkey_flush,
247260
};
248261

249262
static int

0 commit comments

Comments
 (0)