Received: by 10.192.165.156 with SMTP id m28csp1226433imm; Wed, 11 Apr 2018 15:01:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx49O+DAytvT+onNkPbwLd7aNVhWOffRIVNReWNGYBMG8V9ZV0uJnez70ag1HM5l6Yi0p3FLP X-Received: by 10.101.93.2 with SMTP id e2mr4663490pgr.100.1523484100503; Wed, 11 Apr 2018 15:01:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523484100; cv=none; d=google.com; s=arc-20160816; b=wQLhT3iq0BzvgCgEquIo4/TWBt8DQC6rhYafCWsi7FtSLctM6rydRGRZYqP6VD33C1 YoK8ZE9l5A5RBkjcrg4syq3Qfzvk3DCNtdtUmg7kCt+u4FaQU2KlGI4RtdhZC9qFdd5f NMauDKa7vqCbm/Ll2L+1Q5plmKNzwHfxb4livO6lOevpRw3BQlVMouhVEuUzc4tyuthy 0uW7EeIDlqmPunYDcOzWzvt3v5OCTuY+oMDL17ccwWHcywFsUdgA7dInBVetGMVfUKgU 30Rg2wFimDVHY6OBXXYmgkFCIE3hB/n8Ub+0fpDcSFAKx1BoSxjFc4odDl7lljzB0AFu ogCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:cc:subject:date:to :from:arc-authentication-results; bh=PAg+NIKRlUGBcqhQ936cYdfqNDNWCMq5Hgqv4/+ARX8=; b=0d4EHJjPjBll16ZVTssgbO0O71JjuJuMF6CKhniyZtEJ/RVy36LXo7F2ThfomUzert 9nprYeUxwm0rOhdQ63zagP7mb+MEZJApIQ0+fPaGPEEajF1VSUHJRwftBvaPQSBOMXsR ZjMRw+Uec9DfEEyDSDNGTO/GrAHOJ0Du9epYdh6YlIjVO8VteiOkM7RTUWAlFnl9Q4cS KiNfXRJlPMkUM+OBgCXUWW0hhK9bNYd9aM/FnThDLExIm2P7GW66c7HgEmdfx+gzK9HW qejvlgGZPb55oJmQqSFrUVuFHwIegLoqvBh1F1WntGgUxRfoCrgDR2ckZjrIHAvfFk+o L8Lg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n8si1308683pgf.755.2018.04.11.15.01.03; Wed, 11 Apr 2018 15:01:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754057AbeDKV4B (ORCPT + 99 others); Wed, 11 Apr 2018 17:56:01 -0400 Received: from mx2.suse.de ([195.135.220.15]:45839 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753921AbeDKV4A (ORCPT ); Wed, 11 Apr 2018 17:56:00 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D0F4FAFAF; Wed, 11 Apr 2018 21:55:58 +0000 (UTC) From: NeilBrown To: Oleg Drokin , Greg Kroah-Hartman , James Simmons , Andreas Dilger Date: Thu, 12 Apr 2018 07:54:48 +1000 Subject: [PATCH 06/20] staging: lustre: ldlm: add a counter to the per-namespace data Cc: Linux Kernel Mailing List , Lustre Development List Message-ID: <152348368872.12394.16831797606945626384.stgit@noble> In-Reply-To: <152348312863.12394.11915752362061083241.stgit@noble> References: <152348312863.12394.11915752362061083241.stgit@noble> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we change the resource hash to rhashtable we won't have a per-bucket counter. We could use the nelems global counter, but ldlm_resource goes to some trouble to avoid having any table-wide atomics, and hopefully rhashtable will grow the ability to disable the global counter in the near future. Having a counter we control makes it easier to manage the back-reference to the namespace when there is anything in the hash table. So add a counter to the ldlm_ns_bucket. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/include/lustre_dlm.h | 2 ++ drivers/staging/lustre/lustre/ldlm/ldlm_resource.c | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h index 395d50160dcc..ab90abe1c2d8 100644 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h @@ -309,6 +309,8 @@ struct ldlm_ns_bucket { * fact the network or overall system load is at fault */ struct adaptive_timeout nsb_at_estimate; + /* counter of entries in this bucket */ + atomic_t nsb_count; }; enum { diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c index 927544f01adc..669556420bdf 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c @@ -181,12 +181,11 @@ static ssize_t resource_count_show(struct kobject *kobj, struct attribute *attr, struct ldlm_namespace *ns = container_of(kobj, struct ldlm_namespace, ns_kobj); __u64 res = 0; - struct cfs_hash_bd bd; int i; /* result is not strictly consistent */ - cfs_hash_for_each_bucket(ns->ns_rs_hash, &bd, i) - res += cfs_hash_bd_count_get(&bd); + for (i = 0; i < (1 << ns->ns_bucket_bits); i++) + res += atomic_read(&ns->ns_rs_buckets[i].nsb_count); return sprintf(buf, "%lld\n", res); } LUSTRE_RO_ATTR(resource_count); @@ -668,6 +667,7 @@ struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obd, char *name, struct ldlm_ns_bucket *nsb = &ns->ns_rs_buckets[idx]; at_init(&nsb->nsb_at_estimate, ldlm_enqueue_min, 0); nsb->nsb_namespace = ns; + atomic_set(&nsb->nsb_count, 0); } ns->ns_obd = obd; @@ -1144,7 +1144,7 @@ ldlm_resource_get(struct ldlm_namespace *ns, struct ldlm_resource *parent, } /* We won! Let's add the resource. */ cfs_hash_bd_add_locked(ns->ns_rs_hash, &bd, &res->lr_hash); - if (cfs_hash_bd_count_get(&bd) == 1) + if (atomic_inc_return(&res->lr_ns_bucket->nsb_count) == 1) ns_refcount = ldlm_namespace_get_return(ns); cfs_hash_bd_unlock(ns->ns_rs_hash, &bd, 1); @@ -1202,7 +1202,7 @@ static void __ldlm_resource_putref_final(struct cfs_hash_bd *bd, cfs_hash_bd_unlock(ns->ns_rs_hash, bd, 1); if (ns->ns_lvbo && ns->ns_lvbo->lvbo_free) ns->ns_lvbo->lvbo_free(res); - if (cfs_hash_bd_count_get(bd) == 0) + if (atomic_dec_and_test(&nsb->nsb_count)) ldlm_namespace_put(ns); kmem_cache_free(ldlm_resource_slab, res); }