Whamcloud - gitweb
LU-12542 handle: use hlist for hash lists. 62/35862/5
authorNeilBrown <neilb@suse.com>
Fri, 13 Dec 2019 15:47:35 +0000 (10:47 -0500)
committerOleg Drokin <green@whamcloud.com>
Tue, 28 Jan 2020 06:03:07 +0000 (06:03 +0000)
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 <neilb@suse.com>
Reviewed-on: https://review.whamcloud.com/35862
Reviewed-by: Neil Brown <neilb@suse.de>
Reviewed-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Reviewed-by: Yang Sheng <ys@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/lustre_handles.h
lustre/ldlm/ldlm_lock.c
lustre/mdt/mdt_open.c
lustre/obdclass/genops.c
lustre/obdclass/lustre_handles.c

index 41670d5..9da8985 100644 (file)
@@ -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 */
index c2fd190..c918339 100644 (file)
@@ -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);
index 7b1b1f3..ae3cb8e 100644 (file)
@@ -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);
index d472ba3..14ab1ed 100644 (file)
@@ -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);
index 8a6bd97..1f93ed5 100644 (file)
@@ -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);