From 9c9ea6584cfb314aec693be2b03a0f55f60127a3 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Fri, 13 Dec 2019 10:47:35 -0500 Subject: [PATCH] LU-12542 handle: use hlist for hash lists. hlist_head/hlist_node is the preferred data structure for hash tables. Not only does it make the 'head' smaller, but is also provides hlist_unhashed() which can be used to check if an object is in the list. This means that we don't need h_in any more. Change-Id: I18e2799a6e719b96ed47747375e4e20675d9b7cc Signed-off-by: NeilBrown Reviewed-on: https://review.whamcloud.com/35862 Reviewed-by: Neil Brown Reviewed-by: Shaun Tancheff Reviewed-by: Yang Sheng Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/include/lustre_handles.h | 3 +-- lustre/ldlm/ldlm_lock.c | 2 +- lustre/mdt/mdt_open.c | 2 +- lustre/obdclass/genops.c | 2 +- lustre/obdclass/lustre_handles.c | 20 +++++++++----------- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lustre/include/lustre_handles.h b/lustre/include/lustre_handles.h index 41670d5..9da8985b 100644 --- a/lustre/include/lustre_handles.h +++ b/lustre/include/lustre_handles.h @@ -59,7 +59,7 @@ * ldlm_lock. If it's not at the top, you'll want to use container_of() * to compute the start of the structure based on the handle field. */ struct portals_handle { - struct list_head h_link; + struct hlist_node h_link; __u64 h_cookie; const char *h_owner; refcount_t h_ref; @@ -67,7 +67,6 @@ struct portals_handle { /* newly added fields to handle the RCU issue. -jxiong */ struct rcu_head h_rcu; spinlock_t h_lock; - unsigned int h_in:1; }; /* handles.c */ diff --git a/lustre/ldlm/ldlm_lock.c b/lustre/ldlm/ldlm_lock.c index c2fd190..c918339 100644 --- a/lustre/ldlm/ldlm_lock.c +++ b/lustre/ldlm/ldlm_lock.c @@ -489,7 +489,7 @@ static struct ldlm_lock *ldlm_lock_new(struct ldlm_resource *resource) lprocfs_counter_incr(ldlm_res_to_ns(resource)->ns_stats, LDLM_NSS_LOCKS); - INIT_LIST_HEAD_RCU(&lock->l_handle.h_link); + INIT_HLIST_NODE(&lock->l_handle.h_link); class_handle_hash(&lock->l_handle, lock_handle_owner); lu_ref_init(&lock->l_reference); diff --git a/lustre/mdt/mdt_open.c b/lustre/mdt/mdt_open.c index 7b1b1f3..ae3cb8e 100644 --- a/lustre/mdt/mdt_open.c +++ b/lustre/mdt/mdt_open.c @@ -56,7 +56,7 @@ struct mdt_file_data *mdt_mfd_new(const struct mdt_export_data *med) OBD_ALLOC_PTR(mfd); if (mfd != NULL) { refcount_set(&mfd->mfd_open_handle.h_ref, 1); - INIT_LIST_HEAD_RCU(&mfd->mfd_open_handle.h_link); + INIT_HLIST_NODE(&mfd->mfd_open_handle.h_link); mfd->mfd_owner = med; INIT_LIST_HEAD(&mfd->mfd_list); class_handle_hash(&mfd->mfd_open_handle, mfd_open_handle_owner); diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index d472ba3..14ab1ed 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -1056,7 +1056,7 @@ struct obd_export *__class_new_export(struct obd_device *obd, spin_lock_init(&export->exp_uncommitted_replies_lock); INIT_LIST_HEAD(&export->exp_uncommitted_replies); INIT_LIST_HEAD(&export->exp_req_replay_queue); - INIT_LIST_HEAD_RCU(&export->exp_handle.h_link); + INIT_HLIST_NODE(&export->exp_handle.h_link); INIT_LIST_HEAD(&export->exp_hp_rpcs); INIT_LIST_HEAD(&export->exp_reg_rpcs); class_handle_hash(&export->exp_handle, export_handle_owner); diff --git a/lustre/obdclass/lustre_handles.c b/lustre/obdclass/lustre_handles.c index 8a6bd97..1f93ed5 100644 --- a/lustre/obdclass/lustre_handles.c +++ b/lustre/obdclass/lustre_handles.c @@ -49,7 +49,7 @@ static DEFINE_SPINLOCK(handle_base_lock); static struct handle_bucket { spinlock_t lock; - struct list_head head; + struct hlist_head head; } *handle_hash; #define HANDLE_HASH_SIZE (1 << 16) @@ -66,7 +66,7 @@ void class_handle_hash(struct portals_handle *h, const char *owner) ENTRY; LASSERT(h != NULL); - LASSERT(list_empty(&h->h_link)); + LASSERT(hlist_unhashed(&h->h_link)); /* * This is fast, but simplistic cookie generation algorithm, it will @@ -92,8 +92,7 @@ void class_handle_hash(struct portals_handle *h, const char *owner) bucket = &handle_hash[h->h_cookie & HANDLE_HASH_MASK]; spin_lock(&bucket->lock); - list_add_rcu(&h->h_link, &bucket->head); - h->h_in = 1; + hlist_add_head_rcu(&h->h_link, &bucket->head); spin_unlock(&bucket->lock); CDEBUG(D_INFO, "added object %p with handle %#llx to hash\n", @@ -104,7 +103,7 @@ EXPORT_SYMBOL(class_handle_hash); static void class_handle_unhash_nolock(struct portals_handle *h) { - if (list_empty(&h->h_link)) { + if (hlist_unhashed(&h->h_link)) { CERROR("removing an already-removed handle (%#llx)\n", h->h_cookie); return; @@ -114,13 +113,12 @@ static void class_handle_unhash_nolock(struct portals_handle *h) h, h->h_cookie); spin_lock(&h->h_lock); - if (h->h_in == 0) { + if (hlist_unhashed(&h->h_link)) { spin_unlock(&h->h_lock); return; } - h->h_in = 0; + hlist_del_init_rcu(&h->h_link); spin_unlock(&h->h_lock); - list_del_rcu(&h->h_link); } void class_handle_unhash(struct portals_handle *h) @@ -151,7 +149,7 @@ void *class_handle2object(u64 cookie, const char *owner) bucket = handle_hash + (cookie & HANDLE_HASH_MASK); rcu_read_lock(); - list_for_each_entry_rcu(h, &bucket->head, h_link) { + hlist_for_each_entry_rcu(h, &bucket->head, h_link) { if (h->h_cookie != cookie || h->h_owner != owner) continue; @@ -181,7 +179,7 @@ int class_handle_init(void) for (bucket = handle_hash + HANDLE_HASH_SIZE - 1; bucket >= handle_hash; bucket--) { - INIT_LIST_HEAD(&bucket->head); + INIT_HLIST_HEAD(&bucket->head); spin_lock_init(&bucket->lock); } @@ -200,7 +198,7 @@ static int cleanup_all_handles(void) struct portals_handle *h; spin_lock(&handle_hash[i].lock); - list_for_each_entry_rcu(h, &(handle_hash[i].head), h_link) { + hlist_for_each_entry_rcu(h, &handle_hash[i].head, h_link) { CERROR("force clean handle %#llx addr %p owner %p\n", h->h_cookie, h, h->h_owner); -- 1.8.3.1