Re: rhashtable: how to use insecure_elasticity of rhashtable_params

2016-11-08 Thread Xin Long
On Mon, Nov 7, 2016 at 3:55 PM, Herbert Xu  wrote:
> On Sun, Nov 06, 2016 at 09:15:07PM +0800, Xin Long wrote:
>> Now when I don't set  insecure_elasticity, ht->elasticity would be
>> set 16, it would be checked in  the loop of __rhashtable_insert_fast
>> and rhashtable_lookup_one.
>
> This is now obsolete.  Please use the new rhlist interface.
>
just checked, It's a very new interface.
will try it, thanks.

> Thanks,
> --
> Email: Herbert Xu 
> Home Page: http://gondor.apana.org.au/~herbert/
> PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


Re: rhashtable: how to use insecure_elasticity of rhashtable_params

2016-11-07 Thread Herbert Xu
On Sun, Nov 06, 2016 at 09:15:07PM +0800, Xin Long wrote:
> Now when I don't set  insecure_elasticity, ht->elasticity would be
> set 16, it would be checked in  the loop of __rhashtable_insert_fast
> and rhashtable_lookup_one.

This is now obsolete.  Please use the new rhlist interface.

Thanks,
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


rhashtable: how to use insecure_elasticity of rhashtable_params

2016-11-06 Thread Xin Long
Now when I don't set  insecure_elasticity, ht->elasticity would be
set 16, it would be checked in  the loop of __rhashtable_insert_fast
and rhashtable_lookup_one.

But if I set  insecure_elasticity = true,  ht->elasticity wouldn't be
set (and the default is 0). when it is checked in that loop. they
also return EAGAIN, as:

if (elasticity <= 0)
return ERR_PTR(-EAGAIN);

it seems insecure_elasticity=true doesn't really work well.

* @insecure_elasticity: Set to true to disable chain length checks

shouldn't it be something like this ? or did I miss something ?

-
diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index 5c132d3..9743ab7 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -702,7 +702,8 @@ static inline void *__rhashtable_insert_fast(
struct rhlist_head *plist;
struct rhlist_head *list;

-   elasticity--;
+   if (ht->elasticity)
+   elasticity--;
if (!key ||
(params.obj_cmpfn ?
 params.obj_cmpfn(, rht_obj(ht, head)) :
@@ -726,7 +727,7 @@ static inline void *__rhashtable_insert_fast(
goto good;
}

-   if (elasticity <= 0)
+   if (ht->elasticity && elasticity <= 0)
goto slow_path;

data = ERR_PTR(-E2BIG);
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 32d0ad0..e3d615a 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -444,7 +444,8 @@ static void *rhashtable_lookup_one(struct rhashtable *ht,
struct rhlist_head *list;
struct rhlist_head *plist;

-   elasticity--;
+   if (ht->elasticity)
+   elasticity--;
if (!key ||
(ht->p.obj_cmpfn ?
 ht->p.obj_cmpfn(, rht_obj(ht, head)) :
@@ -465,7 +466,7 @@ static void *rhashtable_lookup_one(struct rhashtable *ht,
return NULL;
}

-   if (elasticity <= 0)
+   if (ht->elasticity && elasticity <= 0)
return ERR_PTR(-EAGAIN);

return ERR_PTR(-ENOENT);