[ovs-dev] [PATCH v7 14/16] net, rds: use new hashtable implementation

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Mon Oct 29 13:25:52 UTC 2012


* Sasha Levin (levinsasha928 at gmail.com) wrote:
> Switch rds to use the new hashtable implementation. This reduces the amount of
> generic unrelated code in rds.
> 
> Signed-off-by: Sasha Levin <levinsasha928 at gmail.com>
> ---
>  net/rds/bind.c       |  28 +++++++++-----
>  net/rds/connection.c | 102 +++++++++++++++++++++++----------------------------
>  2 files changed, 63 insertions(+), 67 deletions(-)
> 
> diff --git a/net/rds/bind.c b/net/rds/bind.c
> index 637bde5..79d65ce 100644
> --- a/net/rds/bind.c
> +++ b/net/rds/bind.c
> @@ -36,16 +36,16 @@
>  #include <linux/if_arp.h>
>  #include <linux/jhash.h>
>  #include <linux/ratelimit.h>
> +#include <linux/hashtable.h>
>  #include "rds.h"
>  
> -#define BIND_HASH_SIZE 1024
> -static struct hlist_head bind_hash_table[BIND_HASH_SIZE];
> +#define BIND_HASH_BITS 10
> +static DEFINE_HASHTABLE(bind_hash_table, BIND_HASH_BITS);
>  static DEFINE_SPINLOCK(rds_bind_lock);
>  
> -static struct hlist_head *hash_to_bucket(__be32 addr, __be16 port)
> +static u32 rds_hash(__be32 addr, __be16 port)
>  {
> -	return bind_hash_table + (jhash_2words((u32)addr, (u32)port, 0) &
> -				  (BIND_HASH_SIZE - 1));
> +	return jhash_2words((u32)addr, (u32)port, 0);
>  }
>  
>  static struct rds_sock *rds_bind_lookup(__be32 addr, __be16 port,
> @@ -53,12 +53,12 @@ static struct rds_sock *rds_bind_lookup(__be32 addr, __be16 port,
>  {
>  	struct rds_sock *rs;
>  	struct hlist_node *node;
> -	struct hlist_head *head = hash_to_bucket(addr, port);
> +	u32 key = rds_hash(addr, port);
>  	u64 cmp;
>  	u64 needle = ((u64)be32_to_cpu(addr) << 32) | be16_to_cpu(port);
>  
>  	rcu_read_lock();
> -	hlist_for_each_entry_rcu(rs, node, head, rs_bound_node) {
> +	hash_for_each_possible_rcu(bind_hash_table, rs, node, rs_bound_node, key) {

here too, key will be hashed twice:

- once by jhash_2words,
- once by hash_32(),

is this intended ?

Thanks,

Mathieu

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com



More information about the dev mailing list