aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrond Myklebust <trond.myklebust@primarydata.com>2014-08-06 13:44:23 -0400
committerJ. Bruce Fields <bfields@redhat.com>2014-08-17 12:00:12 -0400
commit31e60f52224197dc989a82237905dfe643183f7c (patch)
treefbcb544e5890c8078531bbe94fb74bb9fbfe385c
parent11acf6ef3b58abd1c5eb94eaa38ed3b9dbc387f7 (diff)
nfsd: convert num_drc_entries to an atomic_t
...so we can remove the spinlocking around it. Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
-rw-r--r--fs/nfsd/nfscache.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
index 8abec475f80f..dc909091349b 100644
--- a/fs/nfsd/nfscache.c
+++ b/fs/nfsd/nfscache.c
@@ -47,7 +47,7 @@ static unsigned int drc_hashsize;
47 */ 47 */
48 48
49/* total number of entries */ 49/* total number of entries */
50static unsigned int num_drc_entries; 50static atomic_t num_drc_entries;
51 51
52/* cache misses due only to checksum comparison failures */ 52/* cache misses due only to checksum comparison failures */
53static unsigned int payload_misses; 53static unsigned int payload_misses;
@@ -148,7 +148,7 @@ nfsd_reply_cache_free_locked(struct svc_cacherep *rp)
148 kfree(rp->c_replvec.iov_base); 148 kfree(rp->c_replvec.iov_base);
149 } 149 }
150 list_del(&rp->c_lru); 150 list_del(&rp->c_lru);
151 --num_drc_entries; 151 atomic_dec(&num_drc_entries);
152 drc_mem_usage -= sizeof(*rp); 152 drc_mem_usage -= sizeof(*rp);
153 kmem_cache_free(drc_slab, rp); 153 kmem_cache_free(drc_slab, rp);
154} 154}
@@ -167,7 +167,7 @@ int nfsd_reply_cache_init(void)
167 unsigned int i; 167 unsigned int i;
168 168
169 max_drc_entries = nfsd_cache_size_limit(); 169 max_drc_entries = nfsd_cache_size_limit();
170 num_drc_entries = 0; 170 atomic_set(&num_drc_entries, 0);
171 hashsize = nfsd_hashsize(max_drc_entries); 171 hashsize = nfsd_hashsize(max_drc_entries);
172 maskbits = ilog2(hashsize); 172 maskbits = ilog2(hashsize);
173 173
@@ -242,7 +242,7 @@ prune_bucket(struct nfsd_drc_bucket *b)
242 */ 242 */
243 if (rp->c_state == RC_INPROG) 243 if (rp->c_state == RC_INPROG)
244 continue; 244 continue;
245 if (num_drc_entries <= max_drc_entries && 245 if (atomic_read(&num_drc_entries) <= max_drc_entries &&
246 time_before(jiffies, rp->c_timestamp + RC_EXPIRE)) 246 time_before(jiffies, rp->c_timestamp + RC_EXPIRE))
247 break; 247 break;
248 nfsd_reply_cache_free_locked(rp); 248 nfsd_reply_cache_free_locked(rp);
@@ -290,13 +290,7 @@ cache_cleaner_func(struct work_struct *unused)
290static unsigned long 290static unsigned long
291nfsd_reply_cache_count(struct shrinker *shrink, struct shrink_control *sc) 291nfsd_reply_cache_count(struct shrinker *shrink, struct shrink_control *sc)
292{ 292{
293 unsigned long num; 293 return atomic_read(&num_drc_entries);
294
295 spin_lock(&cache_lock);
296 num = num_drc_entries;
297 spin_unlock(&cache_lock);
298
299 return num;
300} 294}
301 295
302static unsigned long 296static unsigned long
@@ -386,11 +380,12 @@ nfsd_cache_search(struct nfsd_drc_bucket *b, struct svc_rqst *rqstp,
386 /* tally hash chain length stats */ 380 /* tally hash chain length stats */
387 if (entries > longest_chain) { 381 if (entries > longest_chain) {
388 longest_chain = entries; 382 longest_chain = entries;
389 longest_chain_cachesize = num_drc_entries; 383 longest_chain_cachesize = atomic_read(&num_drc_entries);
390 } else if (entries == longest_chain) { 384 } else if (entries == longest_chain) {
391 /* prefer to keep the smallest cachesize possible here */ 385 /* prefer to keep the smallest cachesize possible here */
392 longest_chain_cachesize = min(longest_chain_cachesize, 386 longest_chain_cachesize = min_t(unsigned int,
393 num_drc_entries); 387 longest_chain_cachesize,
388 atomic_read(&num_drc_entries));
394 } 389 }
395 390
396 return ret; 391 return ret;
@@ -433,7 +428,7 @@ nfsd_cache_lookup(struct svc_rqst *rqstp)
433 rp = nfsd_reply_cache_alloc(); 428 rp = nfsd_reply_cache_alloc();
434 spin_lock(&cache_lock); 429 spin_lock(&cache_lock);
435 if (likely(rp)) { 430 if (likely(rp)) {
436 ++num_drc_entries; 431 atomic_inc(&num_drc_entries);
437 drc_mem_usage += sizeof(*rp); 432 drc_mem_usage += sizeof(*rp);
438 } 433 }
439 434
@@ -617,7 +612,8 @@ static int nfsd_reply_cache_stats_show(struct seq_file *m, void *v)
617{ 612{
618 spin_lock(&cache_lock); 613 spin_lock(&cache_lock);
619 seq_printf(m, "max entries: %u\n", max_drc_entries); 614 seq_printf(m, "max entries: %u\n", max_drc_entries);
620 seq_printf(m, "num entries: %u\n", num_drc_entries); 615 seq_printf(m, "num entries: %u\n",
616 atomic_read(&num_drc_entries));
621 seq_printf(m, "hash buckets: %u\n", 1 << maskbits); 617 seq_printf(m, "hash buckets: %u\n", 1 << maskbits);
622 seq_printf(m, "mem usage: %u\n", drc_mem_usage); 618 seq_printf(m, "mem usage: %u\n", drc_mem_usage);
623 seq_printf(m, "cache hits: %u\n", nfsdstats.rchits); 619 seq_printf(m, "cache hits: %u\n", nfsdstats.rchits);