GFS2 rhashtable cleanup
Subsystems (2)
Andreas Gruenbacher
maintainercover GFS2 rhashtable cleanup
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(-)
Signature · 1 line
2.7.4
Andreas Gruenbacher
maintainerPATCH 1/2 rhashtable: Add rhashtable_lookup_get_insert_fast
Add rhashtable_lookup_get_insert_fast for fixed keys, similar to rhashtable_lookup_get_insert_key for explicit keys.
--- include/linux/rhashtable.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
include/linux/rhashtable.h +22 -0
@@ -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
Signature · 1 line
2.7.4
Herbert Xu
maintainerPATCH 1/2 rhashtable: Add rhashtable_lookup_get_insert_fast
Quoted 7 lines · Andreas Gruenbacher
Add
rhashtable_lookup_get_insert_fastfor fixed keys, similar torhashtable_lookup_get_insert_keyfor explicit keys.Signed-off-by Andreas Gruenbacher <[email protected]>Cc Pablo Neira Ayuso <[email protected]>Cc Herbert Xu <[email protected]>Cc Thomas Graf <[email protected]>
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Andreas Gruenbacher
maintainerPATCH 2/2 gfs2: Switch to rhashtable_lookup_get_insert_fast
In reply to Andreas GruenbacherSwitch from rhashtable_lookup_insert_fast + rhashtable_lookup_fast to rhashtable_lookup_get_insert_fast, which is cleaner and avoids an extra rhashtable lookup.
--- fs/gfs2/glock.c | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-)
fs/gfs2/glock.c +21 -24
@@ -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; }
Signature · 1 line
2.7.4
cover GFS2 rhashtable cleanup
In reply to Andreas GruenbacherHi,
Ah, thats where the rhashtable bit has got to :-)
Looks good,
Steve.
Quoted 15 lines · Andreas Gruenbacher
The first of these patches adds
rhashtable_lookup_get_insert_fast, which is modeled afterrhashtable_lookup_get_insert_keyand returns existing objects in the hash table, other thanrhashtable_lookup_insert_fastwhich 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: Addrhashtable_lookup_get_insert_fast
gfs2: Switch torhashtable_lookup_get_insert_fastfs/gfs2/glock.c | 45 +++++++++++++++++++++------------------------ include/linux/rhashtable.h | 22 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 24 deletions(-)