cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
* [Cluster-devel] [PATCH 0/2] GFS2 rhashtable cleanup
@ 2017-02-22 15:14 Andreas Gruenbacher
  2017-02-22 15:14 ` [Cluster-devel] [PATCH 1/2] rhashtable: Add rhashtable_lookup_get_insert_fast Andreas Gruenbacher
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Andreas Gruenbacher @ 2017-02-22 15:14 UTC (permalink / raw)
  To: cluster-devel.redhat.com

The first of these patches adds rhashtable_lookup_get_insert_fast, which is
modeled after rhashtable_lookup_get_insert_key and returns existing objects in
the hash table, other than rhashtable_lookup_insert_fast which returns -EEXIST.

The second of these patch cleans up the GFS2 gfs2 rhashtable code by using
rhashtable_lookup_get_insert_fast. 

Andreas Gruenbacher (2):
  rhashtable: Add rhashtable_lookup_get_insert_fast
  gfs2: Switch to rhashtable_lookup_get_insert_fast

 fs/gfs2/glock.c            | 45 +++++++++++++++++++++------------------------
 include/linux/rhashtable.h | 22 ++++++++++++++++++++++
 2 files changed, 43 insertions(+), 24 deletions(-)

-- 
2.7.4



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Cluster-devel] [PATCH 1/2] rhashtable: Add rhashtable_lookup_get_insert_fast
  2017-02-22 15:14 [Cluster-devel] [PATCH 0/2] GFS2 rhashtable cleanup Andreas Gruenbacher
@ 2017-02-22 15:14 ` Andreas Gruenbacher
  2017-02-24 14:22   ` Herbert Xu
  2017-02-22 15:14 ` [Cluster-devel] [PATCH 2/2] gfs2: Switch to rhashtable_lookup_get_insert_fast Andreas Gruenbacher
  2017-02-22 15:21 ` [Cluster-devel] [PATCH 0/2] GFS2 rhashtable cleanup Steven Whitehouse
  2 siblings, 1 reply; 5+ messages in thread
From: Andreas Gruenbacher @ 2017-02-22 15:14 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Add rhashtable_lookup_get_insert_fast for fixed keys, similar to
rhashtable_lookup_get_insert_key for explicit keys.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Thomas Graf <tgraf@suug.ch>
---
 include/linux/rhashtable.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index 5c132d3..a85c14f 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -882,6 +882,28 @@ static inline int rhashtable_lookup_insert_fast(
 }
 
 /**
+ * rhashtable_lookup_get_insert_fast - lookup and insert object into hash table
+ * @ht:		hash table
+ * @obj:	pointer to hash head inside object
+ * @params:	hash table parameters
+ *
+ * Just like rhashtable_lookup_insert_fast(), but this function returns the
+ * object if it exists, NULL if it did not and the insertion was successful,
+ * and an ERR_PTR otherwise.
+ */
+static inline void *rhashtable_lookup_get_insert_fast(
+	struct rhashtable *ht, struct rhash_head *obj,
+	const struct rhashtable_params params)
+{
+	const char *key = rht_obj(ht, obj);
+
+	BUG_ON(ht->p.obj_hashfn);
+
+	return __rhashtable_insert_fast(ht, key + ht->p.key_offset, obj, params,
+					false);
+}
+
+/**
  * rhashtable_lookup_insert_key - search and insert object to hash table
  *				  with explicit key
  * @ht:		hash table
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Cluster-devel] [PATCH 2/2] gfs2: Switch to rhashtable_lookup_get_insert_fast
  2017-02-22 15:14 [Cluster-devel] [PATCH 0/2] GFS2 rhashtable cleanup Andreas Gruenbacher
  2017-02-22 15:14 ` [Cluster-devel] [PATCH 1/2] rhashtable: Add rhashtable_lookup_get_insert_fast Andreas Gruenbacher
@ 2017-02-22 15:14 ` Andreas Gruenbacher
  2017-02-22 15:21 ` [Cluster-devel] [PATCH 0/2] GFS2 rhashtable cleanup Steven Whitehouse
  2 siblings, 0 replies; 5+ messages in thread
From: Andreas Gruenbacher @ 2017-02-22 15:14 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Switch from rhashtable_lookup_insert_fast + rhashtable_lookup_fast to
rhashtable_lookup_get_insert_fast, which is cleaner and avoids an extra
rhashtable lookup.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
 fs/gfs2/glock.c | 45 +++++++++++++++++++++------------------------
 1 file changed, 21 insertions(+), 24 deletions(-)

diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 1d60f5f..6dd834e4 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -653,10 +653,10 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
 	struct lm_lockname name = { .ln_number = number,
 				    .ln_type = glops->go_type,
 				    .ln_sbd = sdp };
-	struct gfs2_glock *gl, *tmp = NULL;
+	struct gfs2_glock *gl, *tmp;
 	struct address_space *mapping;
 	struct kmem_cache *cachep;
-	int ret, tries = 0;
+	int ret = 0;
 
 	rcu_read_lock();
 	gl = rhashtable_lookup_fast(&gl_hash_table, &name, ht_parms);
@@ -721,35 +721,32 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
 	}
 
 again:
-	ret = rhashtable_lookup_insert_fast(&gl_hash_table, &gl->gl_node,
-					    ht_parms);
-	if (ret == 0) {
+	rcu_read_lock();
+	tmp = rhashtable_lookup_get_insert_fast(&gl_hash_table, &gl->gl_node,
+						ht_parms);
+	if (!tmp) {
 		*glp = gl;
-		return 0;
+		goto out;
 	}
-
-	if (ret == -EEXIST) {
-		ret = 0;
-		rcu_read_lock();
-		tmp = rhashtable_lookup_fast(&gl_hash_table, &name, ht_parms);
-		if (tmp == NULL || !lockref_get_not_dead(&tmp->gl_lockref)) {
-			if (++tries < 100) {
-				rcu_read_unlock();
-				cond_resched();
-				goto again;
-			}
-			tmp = NULL;
-			ret = -ENOMEM;
-		}
-		rcu_read_unlock();
-	} else {
-		WARN_ON_ONCE(ret);
+	if (IS_ERR(tmp)) {
+		ret = PTR_ERR(tmp);
+		goto out_free;
+	}
+	if (lockref_get_not_dead(&tmp->gl_lockref)) {
+		*glp = tmp;
+		goto out_free;
 	}
+	rcu_read_unlock();
+	cond_resched();
+	goto again;
+
+out_free:
 	kfree(gl->gl_lksb.sb_lvbptr);
 	kmem_cache_free(cachep, gl);
 	atomic_dec(&sdp->sd_glock_disposal);
-	*glp = tmp;
 
+out:
+	rcu_read_unlock();
 	return ret;
 }
 
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Cluster-devel] [PATCH 0/2] GFS2 rhashtable cleanup
  2017-02-22 15:14 [Cluster-devel] [PATCH 0/2] GFS2 rhashtable cleanup Andreas Gruenbacher
  2017-02-22 15:14 ` [Cluster-devel] [PATCH 1/2] rhashtable: Add rhashtable_lookup_get_insert_fast Andreas Gruenbacher
  2017-02-22 15:14 ` [Cluster-devel] [PATCH 2/2] gfs2: Switch to rhashtable_lookup_get_insert_fast Andreas Gruenbacher
@ 2017-02-22 15:21 ` Steven Whitehouse
  2 siblings, 0 replies; 5+ messages in thread
From: Steven Whitehouse @ 2017-02-22 15:21 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Hi,

Ah, thats where the rhashtable bit has got to :-)

Looks good,

Steve.

On 22/02/17 15:14, Andreas Gruenbacher wrote:
> The first of these patches adds rhashtable_lookup_get_insert_fast, which is
> modeled after rhashtable_lookup_get_insert_key and returns existing objects in
> the hash table, other than rhashtable_lookup_insert_fast which returns -EEXIST.
>
> The second of these patch cleans up the GFS2 gfs2 rhashtable code by using
> rhashtable_lookup_get_insert_fast.
>
> Andreas Gruenbacher (2):
>    rhashtable: Add rhashtable_lookup_get_insert_fast
>    gfs2: Switch to rhashtable_lookup_get_insert_fast
>
>   fs/gfs2/glock.c            | 45 +++++++++++++++++++++------------------------
>   include/linux/rhashtable.h | 22 ++++++++++++++++++++++
>   2 files changed, 43 insertions(+), 24 deletions(-)
>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Cluster-devel] [PATCH 1/2] rhashtable: Add rhashtable_lookup_get_insert_fast
  2017-02-22 15:14 ` [Cluster-devel] [PATCH 1/2] rhashtable: Add rhashtable_lookup_get_insert_fast Andreas Gruenbacher
@ 2017-02-24 14:22   ` Herbert Xu
  0 siblings, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2017-02-24 14:22 UTC (permalink / raw)
  To: cluster-devel.redhat.com

On Wed, Feb 22, 2017 at 04:14:47PM +0100, Andreas Gruenbacher wrote:
> Add rhashtable_lookup_get_insert_fast for fixed keys, similar to
> rhashtable_lookup_get_insert_key for explicit keys.
> 
> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
> Cc: Pablo Neira Ayuso <pablo@netfilter.org>
> Cc: Herbert Xu <herbert@gondor.apana.org.au>
> Cc: Thomas Graf <tgraf@suug.ch>

Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-02-24 14:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-22 15:14 [Cluster-devel] [PATCH 0/2] GFS2 rhashtable cleanup Andreas Gruenbacher
2017-02-22 15:14 ` [Cluster-devel] [PATCH 1/2] rhashtable: Add rhashtable_lookup_get_insert_fast Andreas Gruenbacher
2017-02-24 14:22   ` Herbert Xu
2017-02-22 15:14 ` [Cluster-devel] [PATCH 2/2] gfs2: Switch to rhashtable_lookup_get_insert_fast Andreas Gruenbacher
2017-02-22 15:21 ` [Cluster-devel] [PATCH 0/2] GFS2 rhashtable cleanup Steven Whitehouse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).