All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Dilger <adilger@whamcloud.com>
To: lustre-devel@lists.lustre.org
Subject: [lustre-devel] [PATCH 16/28] lustre: portals_handle: use hlist for hash lists.
Date: Wed, 3 Apr 2019 19:52:24 +0000	[thread overview]
Message-ID: <2B0C5EE1-53F9-4DE2-B885-2E64E50D6369@whamcloud.com> (raw)
In-Reply-To: <155168109865.31333.6317453468559898261.stgit@noble.brown>

On Mar 3, 2019, at 23:31, NeilBrown <neilb@suse.com> wrote:
> 
> 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.
> 
> Signed-off-by: NeilBrown <neilb@suse.com>

Reviewed-by: Andreas Dilger <adilger@whamcloud.com>

> ---
> .../staging/lustre/lustre/include/lustre_handles.h |    3 +--
> drivers/staging/lustre/lustre/ldlm/ldlm_lock.c     |    2 +-
> drivers/staging/lustre/lustre/obdclass/genops.c    |    4 ++--
> .../lustre/lustre/obdclass/lustre_handles.c        |   20 +++++++++-----------
> 4 files changed, 13 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/staging/lustre/lustre/include/lustre_handles.h b/drivers/staging/lustre/lustre/include/lustre_handles.h
> index ebbbb01710e7..cc433f48d367 100644
> --- a/drivers/staging/lustre/lustre/include/lustre_handles.h
> +++ b/drivers/staging/lustre/lustre/include/lustre_handles.h
> @@ -58,7 +58,7 @@
>  * 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;
> 	char				*h_owner;
> 	refcount_t			h_ref;
> @@ -66,7 +66,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/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
> index 56a2d1dcd663..5ac77238e5f2 100644
> --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
> +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
> @@ -402,7 +402,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(&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/drivers/staging/lustre/lustre/obdclass/genops.c b/drivers/staging/lustre/lustre/obdclass/genops.c
> index e0da46e7d355..562e8a9f35c9 100644
> --- a/drivers/staging/lustre/lustre/obdclass/genops.c
> +++ b/drivers/staging/lustre/lustre/obdclass/genops.c
> @@ -858,7 +858,7 @@ static 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(&export->exp_handle.h_link);
> +	INIT_HLIST_NODE(&export->exp_handle.h_link);
> 	INIT_LIST_HEAD(&export->exp_hp_rpcs);
> 	class_handle_hash(&export->exp_handle, export_handle_owner);
> 	spin_lock_init(&export->exp_lock);
> @@ -1046,7 +1046,7 @@ struct obd_import *class_new_import(struct obd_device *obd)
> 	atomic_set(&imp->imp_replay_inflight, 0);
> 	atomic_set(&imp->imp_inval_count, 0);
> 	INIT_LIST_HEAD(&imp->imp_conn_list);
> -	INIT_LIST_HEAD(&imp->imp_handle.h_link);
> +	INIT_HLIST_NODE(&imp->imp_handle.h_link);
> 	class_handle_hash(&imp->imp_handle, import_handle_owner);
> 	init_imp_at(&imp->imp_at);
> 
> diff --git a/drivers/staging/lustre/lustre/obdclass/lustre_handles.c b/drivers/staging/lustre/lustre/obdclass/lustre_handles.c
> index 45e5eac47292..72de668c879b 100644
> --- a/drivers/staging/lustre/lustre/obdclass/lustre_handles.c
> +++ b/drivers/staging/lustre/lustre/obdclass/lustre_handles.c
> @@ -48,7 +48,7 @@ static spinlock_t 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)
> @@ -63,7 +63,7 @@ void class_handle_hash(struct portals_handle *h, char *owner)
> 	struct handle_bucket *bucket;
> 
> 	LASSERT(h);
> -	LASSERT(list_empty(&h->h_link));
> +	LASSERT(hlist_unhashed(&h->h_link));
> 
> 	/*
> 	 * This is fast, but simplistic cookie generation algorithm, it will
> @@ -89,8 +89,7 @@ void class_handle_hash(struct portals_handle *h, 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",
> @@ -100,7 +99,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;
> @@ -110,13 +109,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)
> @@ -145,7 +143,7 @@ void *class_handle2object(u64 cookie, 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;
> 
> @@ -176,7 +174,7 @@ int class_handle_init(void)
> 	spin_lock_init(&handle_base_lock);
> 	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);
> 	}
> 
> @@ -195,7 +193,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);
> 
> 
> 

Cheers, Andreas
---
Andreas Dilger
Principal Lustre Architect
Whamcloud

  reply	other threads:[~2019-04-03 19:52 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-04  6:31 [lustre-devel] [PATCH 00/28] More lustre patches NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 12/28] lustre: handle: move refcount into the lustre_handle NeilBrown
2019-04-03 19:48   ` Andreas Dilger
2019-03-04  6:31 ` [lustre-devel] [PATCH 23/28] lustre: obdclass: remove unnecessary code from lustre_init_lsi() NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 15/28] lustre: portals_handle: remove locking from class_handle2object() NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 22/28] lustre: obdclass: discard process_quota_config NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 19/28] lustre: obd_sysfs: error-check value stored in jobid_var NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 18/28] lustre: remove unused fields from struct obd_device NeilBrown
2019-04-03 19:59   ` Andreas Dilger
2019-04-03 23:44     ` NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 07/28] lustre: obdclass: fix module load locking NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 16/28] lustre: portals_handle: use hlist for hash lists NeilBrown
2019-04-03 19:52   ` Andreas Dilger [this message]
2019-03-04  6:31 ` [lustre-devel] [PATCH 09/28] lustre: ldlm: discard varname in ldlm_pool NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 20/28] lustre: lov: use GFP_NOFS to allocate lo_entries NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 14/28] lustre: portals_handle: rename ops to owner NeilBrown
2019-04-03 19:50   ` Andreas Dilger
2019-04-03 23:39     ` NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 13/28] lustre: discard OBD_FREE_RCU NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 08/28] lustre: convert rsi_sem to a spinlock NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 17/28] lustre: portals_handle: discard h_lock NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 11/28] lustre: handles: discard h_owner in favour of h_ops NeilBrown
2019-04-03 19:45   ` Andreas Dilger
2019-04-03 23:37     ` NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 24/28] lustre: ldlm: discard l_lock from struct ldlm_lock NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 02/28] lustre: collect all resource releasing for obj_type NeilBrown
2019-03-22  3:49   ` James Simmons
2019-03-04  6:31 ` [lustre-devel] [PATCH 21/28] lustre: vvp_dev; increment *pos in .next NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 03/28] lustre: obd_type: use typ_kobj.name as typ_name NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 06/28] lustre: obdclass: don't copy ops structures in to new type NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 10/28] lustre: lprocfs: use log2.h macros instead of shift loop NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 05/28] lustre: obd_type: discard obd_type_lock NeilBrown
2019-03-22  3:53   ` James Simmons
2019-03-24 23:37     ` NeilBrown
2019-03-25  5:56       ` Andreas Dilger
2019-03-04  6:31 ` [lustre-devel] [PATCH 01/28] lustre: embed typ_kobj in obd_type NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 04/28] lustre: obd_type: discard obd_types linked list NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 27/28] lustre: ldlm: simplify lock_mode_to_index() NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 26/28] lustre: ldlm: drop SLAB_TYPESAFE_BY_RCU from ldlm_lock slab NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 28/28] lustre: use list_move where appropriate NeilBrown
2019-03-04  6:31 ` [lustre-devel] [PATCH 25/28] lustre: ldlm: don't access l_resource when not locked NeilBrown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2B0C5EE1-53F9-4DE2-B885-2E64E50D6369@whamcloud.com \
    --to=adilger@whamcloud.com \
    --cc=lustre-devel@lists.lustre.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.