# Re: \[PATCH 1/3\] rhashtable: use cmpxchg() in nested\_table\_alloc()

- From: Herbert Xu \<herbert@gondor.apana.org.au\>
- Date: 2019-03-15 05:10:51 
- List: netdev
- Page: https://ratatoskr.run/netdev/2019/03/5539473
- Thread: https://ratatoskr.run/netdev/2019/03/5538648/t.md

```text
Hi Neil:

On Thu, Mar 14, 2019 at 04:05:28PM +1100, NeilBrown wrote:
> nested_table_alloc() relies on the fact that there is
> at most one spinlock allocated for every slot in the top
> level nested table, so it is not possible for two threads
> to try to allocate the same table at the same time.
> 
> This assumption is a little fragile (it is not explicit) and is
> unnecessary.  We can instead protect against
> a race using cmpxchg() - if it the cmp fails, free the table
> that was just allocated.
> 
> Signed-off-by: NeilBrown <redacted>
> ---
>  lib/rhashtable.c |    8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)

You probably explained it to me before but it's been long enough
that I no longer remember why we need this change.  So please
explain in the commit log why this change is needed.  Because
on the face of it you are adding locking/sychronisation and not
taking it away.

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