From: NeilBrown Date: Tue, 17 Sep 2019 19:34:39 +0000 (-0400) Subject: LU-8130 ldlm: add a counter to the per-namespace data X-Git-Tag: 2.13.51~33 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=refs%2Fchanges%2F19%2F36219%2F5;p=fs%2Flustre-release.git LU-8130 ldlm: add a counter to the per-namespace data 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. Change-Id: Ic79e96f95d5cacfb5e7bb02350f5f4fafb207b44 Signed-off-by: NeilBrown Reviewed-on: https://review.whamcloud.com/36219 Reviewed-by: Neil Brown Reviewed-by: Shaun Tancheff Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- diff --git a/lustre/include/lustre_dlm.h b/lustre/include/lustre_dlm.h index c3a7928..4f285f8 100644 --- a/lustre/include/lustre_dlm.h +++ b/lustre/include/lustre_dlm.h @@ -333,6 +333,8 @@ struct ldlm_ns_bucket { * Which res in the bucket should we start with the reclaim. */ int nsb_reclaim_start; + /* counter of entries in this bucket */ + atomic_t nsb_count; }; enum { diff --git a/lustre/ldlm/ldlm_resource.c b/lustre/ldlm/ldlm_resource.c index a65a75c..d5f93fd 100644 --- a/lustre/ldlm/ldlm_resource.c +++ b/lustre/ldlm/ldlm_resource.c @@ -285,12 +285,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 consistant */ - 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); @@ -942,6 +941,7 @@ struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obd, char *name, at_init(&nsb->nsb_at_estimate, ldlm_enqueue_min, 0); nsb->nsb_namespace = ns; nsb->nsb_reclaim_start = 0; + atomic_set(&nsb->nsb_count, 0); } ns->ns_obd = obd; @@ -1530,7 +1530,7 @@ found: } /* 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); @@ -1579,7 +1579,7 @@ static void __ldlm_resource_putref_final(struct cfs_hash_bd *bd, cfs_hash_bd_del_locked(nsb->nsb_namespace->ns_rs_hash, bd, &res->lr_hash); lu_ref_fini(&res->lr_reference); - if (cfs_hash_bd_count_get(bd) == 0) + if (atomic_dec_and_test(&nsb->nsb_count)) ldlm_namespace_put(nsb->nsb_namespace); }