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>
* 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 {
* 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;
__u64 h_cookie;
const char *h_owner;
refcount_t h_ref;
/* newly added fields to handle the RCU issue. -jxiong */
struct rcu_head h_rcu;
spinlock_t h_lock;
/* newly added fields to handle the RCU issue. -jxiong */
struct rcu_head h_rcu;
spinlock_t h_lock;
lprocfs_counter_incr(ldlm_res_to_ns(resource)->ns_stats,
LDLM_NSS_LOCKS);
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);
class_handle_hash(&lock->l_handle, lock_handle_owner);
lu_ref_init(&lock->l_reference);
OBD_ALLOC_PTR(mfd);
if (mfd != NULL) {
refcount_set(&mfd->mfd_open_handle.h_ref, 1);
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);
mfd->mfd_owner = med;
INIT_LIST_HEAD(&mfd->mfd_list);
class_handle_hash(&mfd->mfd_open_handle, mfd_open_handle_owner);
spin_lock_init(&export->exp_uncommitted_replies_lock);
INIT_LIST_HEAD(&export->exp_uncommitted_replies);
INIT_LIST_HEAD(&export->exp_req_replay_queue);
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);
INIT_LIST_HEAD(&export->exp_hp_rpcs);
INIT_LIST_HEAD(&export->exp_reg_rpcs);
class_handle_hash(&export->exp_handle, export_handle_owner);
static struct handle_bucket {
spinlock_t lock;
static struct handle_bucket {
spinlock_t lock;
+ struct hlist_head head;
} *handle_hash;
#define HANDLE_HASH_SIZE (1 << 16)
} *handle_hash;
#define HANDLE_HASH_SIZE (1 << 16)
ENTRY;
LASSERT(h != NULL);
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
/*
* This is fast, but simplistic cookie generation algorithm, it will
bucket = &handle_hash[h->h_cookie & HANDLE_HASH_MASK];
spin_lock(&bucket->lock);
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",
spin_unlock(&bucket->lock);
CDEBUG(D_INFO, "added object %p with handle %#llx to hash\n",
static void class_handle_unhash_nolock(struct portals_handle *h)
{
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;
CERROR("removing an already-removed handle (%#llx)\n",
h->h_cookie);
return;
h, h->h_cookie);
spin_lock(&h->h_lock);
h, h->h_cookie);
spin_lock(&h->h_lock);
+ if (hlist_unhashed(&h->h_link)) {
spin_unlock(&h->h_lock);
return;
}
spin_unlock(&h->h_lock);
return;
}
+ hlist_del_init_rcu(&h->h_link);
- list_del_rcu(&h->h_link);
}
void class_handle_unhash(struct portals_handle *h)
}
void class_handle_unhash(struct portals_handle *h)
bucket = handle_hash + (cookie & HANDLE_HASH_MASK);
rcu_read_lock();
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;
if (h->h_cookie != cookie || h->h_owner != owner)
continue;
for (bucket = handle_hash + HANDLE_HASH_SIZE - 1; bucket >= handle_hash;
bucket--) {
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);
}
spin_lock_init(&bucket->lock);
}
struct portals_handle *h;
spin_lock(&handle_hash[i].lock);
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);
CERROR("force clean handle %#llx addr %p owner %p\n",
h->h_cookie, h, h->h_owner);