diff options
author | Jeff Layton <jlayton@redhat.com> | 2013-03-27 10:15:38 -0400 |
---|---|---|
committer | J. Bruce Fields <bfields@redhat.com> | 2013-04-03 11:47:23 -0400 |
commit | 6c6910cd4d0cdb905fbba8c751afd143696930f2 (patch) | |
tree | aa0693b81ed491499a5f8a2f0b0057d0c25967d6 | |
parent | 9dc56143c298692276231735ec6546c1fac596e0 (diff) |
nfsd: track memory utilization by the DRC
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
-rw-r--r-- | fs/nfsd/nfscache.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c index 48f5ef944234..1f45b3353bb1 100644 --- a/fs/nfsd/nfscache.c +++ b/fs/nfsd/nfscache.c | |||
@@ -38,6 +38,9 @@ static unsigned int num_drc_entries; | |||
38 | /* cache misses due only to checksum comparison failures */ | 38 | /* cache misses due only to checksum comparison failures */ |
39 | static unsigned int payload_misses; | 39 | static unsigned int payload_misses; |
40 | 40 | ||
41 | /* amount of memory (in bytes) currently consumed by the DRC */ | ||
42 | static unsigned int drc_mem_usage; | ||
43 | |||
41 | /* | 44 | /* |
42 | * Calculate the hash index from an XID. | 45 | * Calculate the hash index from an XID. |
43 | */ | 46 | */ |
@@ -112,12 +115,15 @@ nfsd_reply_cache_alloc(void) | |||
112 | static void | 115 | static void |
113 | nfsd_reply_cache_free_locked(struct svc_cacherep *rp) | 116 | nfsd_reply_cache_free_locked(struct svc_cacherep *rp) |
114 | { | 117 | { |
115 | if (rp->c_type == RC_REPLBUFF) | 118 | if (rp->c_type == RC_REPLBUFF && rp->c_replvec.iov_base) { |
119 | drc_mem_usage -= rp->c_replvec.iov_len; | ||
116 | kfree(rp->c_replvec.iov_base); | 120 | kfree(rp->c_replvec.iov_base); |
121 | } | ||
117 | if (!hlist_unhashed(&rp->c_hash)) | 122 | if (!hlist_unhashed(&rp->c_hash)) |
118 | hlist_del(&rp->c_hash); | 123 | hlist_del(&rp->c_hash); |
119 | list_del(&rp->c_lru); | 124 | list_del(&rp->c_lru); |
120 | --num_drc_entries; | 125 | --num_drc_entries; |
126 | drc_mem_usage -= sizeof(*rp); | ||
121 | kmem_cache_free(drc_slab, rp); | 127 | kmem_cache_free(drc_slab, rp); |
122 | } | 128 | } |
123 | 129 | ||
@@ -372,8 +378,10 @@ nfsd_cache_lookup(struct svc_rqst *rqstp) | |||
372 | spin_unlock(&cache_lock); | 378 | spin_unlock(&cache_lock); |
373 | rp = nfsd_reply_cache_alloc(); | 379 | rp = nfsd_reply_cache_alloc(); |
374 | spin_lock(&cache_lock); | 380 | spin_lock(&cache_lock); |
375 | if (likely(rp)) | 381 | if (likely(rp)) { |
376 | ++num_drc_entries; | 382 | ++num_drc_entries; |
383 | drc_mem_usage += sizeof(*rp); | ||
384 | } | ||
377 | 385 | ||
378 | search_cache: | 386 | search_cache: |
379 | found = nfsd_cache_search(rqstp, csum); | 387 | found = nfsd_cache_search(rqstp, csum); |
@@ -415,6 +423,7 @@ search_cache: | |||
415 | 423 | ||
416 | /* release any buffer */ | 424 | /* release any buffer */ |
417 | if (rp->c_type == RC_REPLBUFF) { | 425 | if (rp->c_type == RC_REPLBUFF) { |
426 | drc_mem_usage -= rp->c_replvec.iov_len; | ||
418 | kfree(rp->c_replvec.iov_base); | 427 | kfree(rp->c_replvec.iov_base); |
419 | rp->c_replvec.iov_base = NULL; | 428 | rp->c_replvec.iov_base = NULL; |
420 | } | 429 | } |
@@ -483,6 +492,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp) | |||
483 | struct svc_cacherep *rp = rqstp->rq_cacherep; | 492 | struct svc_cacherep *rp = rqstp->rq_cacherep; |
484 | struct kvec *resv = &rqstp->rq_res.head[0], *cachv; | 493 | struct kvec *resv = &rqstp->rq_res.head[0], *cachv; |
485 | int len; | 494 | int len; |
495 | size_t bufsize = 0; | ||
486 | 496 | ||
487 | if (!rp) | 497 | if (!rp) |
488 | return; | 498 | return; |
@@ -504,19 +514,21 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp) | |||
504 | break; | 514 | break; |
505 | case RC_REPLBUFF: | 515 | case RC_REPLBUFF: |
506 | cachv = &rp->c_replvec; | 516 | cachv = &rp->c_replvec; |
507 | cachv->iov_base = kmalloc(len << 2, GFP_KERNEL); | 517 | bufsize = len << 2; |
518 | cachv->iov_base = kmalloc(bufsize, GFP_KERNEL); | ||
508 | if (!cachv->iov_base) { | 519 | if (!cachv->iov_base) { |
509 | nfsd_reply_cache_free(rp); | 520 | nfsd_reply_cache_free(rp); |
510 | return; | 521 | return; |
511 | } | 522 | } |
512 | cachv->iov_len = len << 2; | 523 | cachv->iov_len = bufsize; |
513 | memcpy(cachv->iov_base, statp, len << 2); | 524 | memcpy(cachv->iov_base, statp, bufsize); |
514 | break; | 525 | break; |
515 | case RC_NOCACHE: | 526 | case RC_NOCACHE: |
516 | nfsd_reply_cache_free(rp); | 527 | nfsd_reply_cache_free(rp); |
517 | return; | 528 | return; |
518 | } | 529 | } |
519 | spin_lock(&cache_lock); | 530 | spin_lock(&cache_lock); |
531 | drc_mem_usage += bufsize; | ||
520 | lru_put_end(rp); | 532 | lru_put_end(rp); |
521 | rp->c_secure = rqstp->rq_secure; | 533 | rp->c_secure = rqstp->rq_secure; |
522 | rp->c_type = cachetype; | 534 | rp->c_type = cachetype; |