From patchwork Sun Aug 3 17:06:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 4666081 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4620FC0338 for ; Sun, 3 Aug 2014 17:06:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6CB9E2018A for ; Sun, 3 Aug 2014 17:06:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8F965200E5 for ; Sun, 3 Aug 2014 17:06:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753101AbaHCRGM (ORCPT ); Sun, 3 Aug 2014 13:06:12 -0400 Received: from mail-qg0-f52.google.com ([209.85.192.52]:40028 "EHLO mail-qg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753096AbaHCRGL (ORCPT ); Sun, 3 Aug 2014 13:06:11 -0400 Received: by mail-qg0-f52.google.com with SMTP id f51so7743257qge.25 for ; Sun, 03 Aug 2014 10:06:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vR/Wl8SkCUx02LVzKSdzs8/oxBy0XfiHYbAEmgs5AWc=; b=Z8gWMgVh43FLQUX3eYEpfVUguniC9vENVXFI1pQNCcD5lZQw4kkD6ody7IgTf6UYAi h6kweWzNGQl2xxI3cSrf7U58cYF+dF3OHKYpE8BBJhDO6Ri56PvFheveR7P8CvBGIWUG 8gjfOedT9shwR6ppP0+Zd/sACG7WrFA/uhjS33twKiiX/Xo2opAydOWsU58Q8nMb9Wd5 mZLTAbY0S/tWwh870nHjg3fS9t3JfFSWa6Vd3CoefkB02waE6rGfP1UfcU5wxWVkkvgw xa+dsteJ3wlaR/nP+uxLJ+CtEyv8FtBa4jB5j+TW1ZnATxVQGOnGMrGKQMvkMWhsClB+ E4hg== X-Gm-Message-State: ALoCoQnPSKC6Qp27HsKVUwrMD5iuVChcgnNYrogmLEc+MbrpMHj8s+yH4cTk9MOXGu3Ml/RGuTzS X-Received: by 10.224.123.80 with SMTP id o16mr29228761qar.21.1407085570968; Sun, 03 Aug 2014 10:06:10 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (50-33-225-239.drr02.mskg.mi.frontiernet.net. [50.33.225.239]) by mx.google.com with ESMTPSA id g35sm16473060qgf.49.2014.08.03.10.06.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Aug 2014 10:06:10 -0700 (PDT) From: Trond Myklebust To: Bruce Fields Cc: linux-nfs@vger.kernel.org Subject: [PATCH 4/6] nfsd: convert num_drc_entries to an atomic_t Date: Sun, 3 Aug 2014 13:06:02 -0400 Message-Id: <1407085564-3227-5-git-send-email-trond.myklebust@primarydata.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1407085564-3227-4-git-send-email-trond.myklebust@primarydata.com> References: <1407085564-3227-1-git-send-email-trond.myklebust@primarydata.com> <1407085564-3227-2-git-send-email-trond.myklebust@primarydata.com> <1407085564-3227-3-git-send-email-trond.myklebust@primarydata.com> <1407085564-3227-4-git-send-email-trond.myklebust@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ...so we can remove the spinlocking around it. Signed-off-by: Trond Myklebust --- fs/nfsd/nfscache.c | 28 ++++++++++++---------------- 1 file 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; */ /* total number of entries */ -static unsigned int num_drc_entries; +static atomic_t num_drc_entries; /* cache misses due only to checksum comparison failures */ static unsigned int payload_misses; @@ -148,7 +148,7 @@ nfsd_reply_cache_free_locked(struct svc_cacherep *rp) kfree(rp->c_replvec.iov_base); } list_del(&rp->c_lru); - --num_drc_entries; + atomic_dec(&num_drc_entries); drc_mem_usage -= sizeof(*rp); kmem_cache_free(drc_slab, rp); } @@ -167,7 +167,7 @@ int nfsd_reply_cache_init(void) unsigned int i; max_drc_entries = nfsd_cache_size_limit(); - num_drc_entries = 0; + atomic_set(&num_drc_entries, 0); hashsize = nfsd_hashsize(max_drc_entries); maskbits = ilog2(hashsize); @@ -242,7 +242,7 @@ prune_bucket(struct nfsd_drc_bucket *b) */ if (rp->c_state == RC_INPROG) continue; - if (num_drc_entries <= max_drc_entries && + if (atomic_read(&num_drc_entries) <= max_drc_entries && time_before(jiffies, rp->c_timestamp + RC_EXPIRE)) break; nfsd_reply_cache_free_locked(rp); @@ -290,13 +290,7 @@ cache_cleaner_func(struct work_struct *unused) static unsigned long nfsd_reply_cache_count(struct shrinker *shrink, struct shrink_control *sc) { - unsigned long num; - - spin_lock(&cache_lock); - num = num_drc_entries; - spin_unlock(&cache_lock); - - return num; + return atomic_read(&num_drc_entries); } static unsigned long @@ -386,11 +380,12 @@ nfsd_cache_search(struct nfsd_drc_bucket *b, struct svc_rqst *rqstp, /* tally hash chain length stats */ if (entries > longest_chain) { longest_chain = entries; - longest_chain_cachesize = num_drc_entries; + longest_chain_cachesize = atomic_read(&num_drc_entries); } else if (entries == longest_chain) { /* prefer to keep the smallest cachesize possible here */ - longest_chain_cachesize = min(longest_chain_cachesize, - num_drc_entries); + longest_chain_cachesize = min_t(unsigned int, + longest_chain_cachesize, + atomic_read(&num_drc_entries)); } return ret; @@ -433,7 +428,7 @@ nfsd_cache_lookup(struct svc_rqst *rqstp) rp = nfsd_reply_cache_alloc(); spin_lock(&cache_lock); if (likely(rp)) { - ++num_drc_entries; + atomic_inc(&num_drc_entries); drc_mem_usage += sizeof(*rp); } @@ -617,7 +612,8 @@ static int nfsd_reply_cache_stats_show(struct seq_file *m, void *v) { spin_lock(&cache_lock); seq_printf(m, "max entries: %u\n", max_drc_entries); - seq_printf(m, "num entries: %u\n", num_drc_entries); + seq_printf(m, "num entries: %u\n", + atomic_read(&num_drc_entries)); seq_printf(m, "hash buckets: %u\n", 1 << maskbits); seq_printf(m, "mem usage: %u\n", drc_mem_usage); seq_printf(m, "cache hits: %u\n", nfsdstats.rchits);