Commit edd9a007 authored by Neil Brown's avatar Neil Brown Committed by Linus Torvalds

[PATCH] nfsd: change nfsd reply cache to use list.h lists

also kmalloc the cache one entry at a time, instead of in one big slab.
Signed-off-by: default avatarNeil Brown <neilb@cse.unsw.edu.au>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent dd074e20
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/list.h>
#include <linux/sunrpc/svc.h> #include <linux/sunrpc/svc.h>
#include <linux/nfsd/nfsd.h> #include <linux/nfsd/nfsd.h>
...@@ -30,15 +31,8 @@ ...@@ -30,15 +31,8 @@
#define HASHSIZE 64 #define HASHSIZE 64
#define REQHASH(xid) ((((xid) >> 24) ^ (xid)) & (HASHSIZE-1)) #define REQHASH(xid) ((((xid) >> 24) ^ (xid)) & (HASHSIZE-1))
struct nfscache_head { static struct hlist_head * hash_list;
struct svc_cacherep * next; static struct list_head lru_head;
struct svc_cacherep * prev;
};
static struct nfscache_head * hash_list;
static struct svc_cacherep * lru_head;
static struct svc_cacherep * lru_tail;
static struct svc_cacherep * nfscache;
static int cache_disabled = 1; static int cache_disabled = 1;
static int nfsd_cache_append(struct svc_rqst *rqstp, struct kvec *vec); static int nfsd_cache_append(struct svc_rqst *rqstp, struct kvec *vec);
...@@ -54,46 +48,32 @@ void ...@@ -54,46 +48,32 @@ void
nfsd_cache_init(void) nfsd_cache_init(void)
{ {
struct svc_cacherep *rp; struct svc_cacherep *rp;
struct nfscache_head *rh; int i;
size_t i;
unsigned long order; INIT_LIST_HEAD(&lru_head);
i = CACHESIZE;
while(i) {
i = CACHESIZE * sizeof (struct svc_cacherep); rp = kmalloc(sizeof(*rp), GFP_KERNEL);
for (order = 0; (PAGE_SIZE << order) < i; order++) if (!rp) break;
; list_add(&rp->c_lru, &lru_head);
nfscache = (struct svc_cacherep *) rp->c_state = RC_UNUSED;
__get_free_pages(GFP_KERNEL, order); rp->c_type = RC_NOCACHE;
if (!nfscache) { INIT_HLIST_NODE(&rp->c_hash);
printk (KERN_ERR "nfsd: cannot allocate %Zd bytes for reply cache\n", i); i--;
return;
} }
memset(nfscache, 0, i);
i = HASHSIZE * sizeof (struct nfscache_head); if (i)
hash_list = kmalloc (i, GFP_KERNEL); printk (KERN_ERR "nfsd: cannot allocate all %d cache entries, only got %d\n",
CACHESIZE, CACHESIZE-i);
hash_list = kmalloc (HASHSIZE * sizeof(struct hlist_head), GFP_KERNEL);
if (!hash_list) { if (!hash_list) {
free_pages ((unsigned long)nfscache, order); nfsd_cache_shutdown();
nfscache = NULL; printk (KERN_ERR "nfsd: cannot allocate %Zd bytes for hash list\n",
printk (KERN_ERR "nfsd: cannot allocate %Zd bytes for hash list\n", i); HASHSIZE * sizeof(struct hlist_head));
return; return;
} }
memset(hash_list, 0, HASHSIZE * sizeof(struct hlist_head));
for (i = 0, rh = hash_list; i < HASHSIZE; i++, rh++)
rh->next = rh->prev = (struct svc_cacherep *) rh;
for (i = 0, rp = nfscache; i < CACHESIZE; i++, rp++) {
rp->c_state = RC_UNUSED;
rp->c_type = RC_NOCACHE;
rp->c_hash_next =
rp->c_hash_prev = rp;
rp->c_lru_next = rp + 1;
rp->c_lru_prev = rp - 1;
}
lru_head = nfscache;
lru_tail = nfscache + CACHESIZE - 1;
lru_head->c_lru_prev = NULL;
lru_tail->c_lru_next = NULL;
cache_disabled = 0; cache_disabled = 0;
} }
...@@ -102,48 +82,30 @@ void ...@@ -102,48 +82,30 @@ void
nfsd_cache_shutdown(void) nfsd_cache_shutdown(void)
{ {
struct svc_cacherep *rp; struct svc_cacherep *rp;
size_t i;
unsigned long order;
for (rp = lru_head; rp; rp = rp->c_lru_next) { while (!list_empty(&lru_head)) {
rp = list_entry(lru_head.next, struct svc_cacherep, c_lru);
if (rp->c_state == RC_DONE && rp->c_type == RC_REPLBUFF) if (rp->c_state == RC_DONE && rp->c_type == RC_REPLBUFF)
kfree(rp->c_replvec.iov_base); kfree(rp->c_replvec.iov_base);
list_del(&rp->c_lru);
kfree(rp);
} }
cache_disabled = 1; cache_disabled = 1;
i = CACHESIZE * sizeof (struct svc_cacherep); if (hash_list)
for (order = 0; (PAGE_SIZE << order) < i; order++) kfree (hash_list);
;
free_pages ((unsigned long)nfscache, order);
nfscache = NULL;
kfree (hash_list);
hash_list = NULL; hash_list = NULL;
} }
/* /*
* Move cache entry to front of LRU list * Move cache entry to end of LRU list
*/ */
static void static void
lru_put_front(struct svc_cacherep *rp) lru_put_end(struct svc_cacherep *rp)
{ {
struct svc_cacherep *prev = rp->c_lru_prev, list_del(&rp->c_lru);
*next = rp->c_lru_next; list_add_tail(&rp->c_lru, &lru_head);
if (prev)
prev->c_lru_next = next;
else
lru_head = next;
if (next)
next->c_lru_prev = prev;
else
lru_tail = prev;
rp->c_lru_next = lru_head;
rp->c_lru_prev = NULL;
if (lru_head)
lru_head->c_lru_prev = rp;
lru_head = rp;
} }
/* /*
...@@ -152,17 +114,8 @@ lru_put_front(struct svc_cacherep *rp) ...@@ -152,17 +114,8 @@ lru_put_front(struct svc_cacherep *rp)
static void static void
hash_refile(struct svc_cacherep *rp) hash_refile(struct svc_cacherep *rp)
{ {
struct svc_cacherep *prev = rp->c_hash_prev, hlist_del_init(&rp->c_hash);
*next = rp->c_hash_next; hlist_add_head(&rp->c_hash, hash_list + REQHASH(rp->c_xid));
struct nfscache_head *head = hash_list + REQHASH(rp->c_xid);
prev->c_hash_next = next;
next->c_hash_prev = prev;
rp->c_hash_next = head->next;
rp->c_hash_prev = (struct svc_cacherep *) head;
head->next->c_hash_prev = rp;
head->next = rp;
} }
/* /*
...@@ -173,7 +126,9 @@ hash_refile(struct svc_cacherep *rp) ...@@ -173,7 +126,9 @@ hash_refile(struct svc_cacherep *rp)
int int
nfsd_cache_lookup(struct svc_rqst *rqstp, int type) nfsd_cache_lookup(struct svc_rqst *rqstp, int type)
{ {
struct svc_cacherep *rh, *rp; struct hlist_node *hn;
struct hlist_head *rh;
struct svc_cacherep *rp;
u32 xid = rqstp->rq_xid, u32 xid = rqstp->rq_xid,
proto = rqstp->rq_prot, proto = rqstp->rq_prot,
vers = rqstp->rq_vers, vers = rqstp->rq_vers,
...@@ -190,8 +145,8 @@ nfsd_cache_lookup(struct svc_rqst *rqstp, int type) ...@@ -190,8 +145,8 @@ nfsd_cache_lookup(struct svc_rqst *rqstp, int type)
spin_lock(&cache_lock); spin_lock(&cache_lock);
rtn = RC_DOIT; rtn = RC_DOIT;
rp = rh = (struct svc_cacherep *) &hash_list[REQHASH(xid)]; rh = &hash_list[REQHASH(xid)];
while ((rp = rp->c_hash_next) != rh) { hlist_for_each_entry(rp, hn, rh, c_hash) {
if (rp->c_state != RC_UNUSED && if (rp->c_state != RC_UNUSED &&
xid == rp->c_xid && proc == rp->c_proc && xid == rp->c_xid && proc == rp->c_proc &&
proto == rp->c_prot && vers == rp->c_vers && proto == rp->c_prot && vers == rp->c_vers &&
...@@ -206,7 +161,7 @@ nfsd_cache_lookup(struct svc_rqst *rqstp, int type) ...@@ -206,7 +161,7 @@ nfsd_cache_lookup(struct svc_rqst *rqstp, int type)
/* This loop shouldn't take more than a few iterations normally */ /* This loop shouldn't take more than a few iterations normally */
{ {
int safe = 0; int safe = 0;
for (rp = lru_tail; rp; rp = rp->c_lru_prev) { list_for_each_entry(rp, &lru_head, c_lru) {
if (rp->c_state != RC_INPROG) if (rp->c_state != RC_INPROG)
break; break;
if (safe++ > CACHESIZE) { if (safe++ > CACHESIZE) {
...@@ -254,7 +209,7 @@ nfsd_cache_lookup(struct svc_rqst *rqstp, int type) ...@@ -254,7 +209,7 @@ nfsd_cache_lookup(struct svc_rqst *rqstp, int type)
/* We found a matching entry which is either in progress or done. */ /* We found a matching entry which is either in progress or done. */
age = jiffies - rp->c_timestamp; age = jiffies - rp->c_timestamp;
rp->c_timestamp = jiffies; rp->c_timestamp = jiffies;
lru_put_front(rp); lru_put_end(rp);
rtn = RC_DROPIT; rtn = RC_DROPIT;
/* Request being processed or excessive rexmits */ /* Request being processed or excessive rexmits */
...@@ -343,7 +298,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, u32 *statp) ...@@ -343,7 +298,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, u32 *statp)
break; break;
} }
spin_lock(&cache_lock); spin_lock(&cache_lock);
lru_put_front(rp); lru_put_end(rp);
rp->c_secure = rqstp->rq_secure; rp->c_secure = rqstp->rq_secure;
rp->c_type = cachetype; rp->c_type = cachetype;
rp->c_state = RC_DONE; rp->c_state = RC_DONE;
......
...@@ -19,10 +19,9 @@ ...@@ -19,10 +19,9 @@
* be hash_next and hash_prev. * be hash_next and hash_prev.
*/ */
struct svc_cacherep { struct svc_cacherep {
struct svc_cacherep * c_hash_next; struct hlist_node c_hash;
struct svc_cacherep * c_hash_prev; struct list_head c_lru;
struct svc_cacherep * c_lru_next;
struct svc_cacherep * c_lru_prev;
unsigned char c_state, /* unused, inprog, done */ unsigned char c_state, /* unused, inprog, done */
c_type, /* status, buffer */ c_type, /* status, buffer */
c_secure : 1; /* req came from port < 1024 */ c_secure : 1; /* req came from port < 1024 */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment