Re: [PATCH] netdevsim: fib: Make use of rhashtable_iter

From: Herbert Xu
Date: Wed Apr 26 2023 - 05:38:19 EST


Cai Huoqing <cai.huoqing@xxxxxxxxx> wrote:
> Iterating 'fib_rt_ht' by rhashtable_walk_next and rhashtable_iter directly
> instead of using list_for_each, because each entry of fib_rt_ht can be
> found by rhashtable API. And remove fib_rt_list.
>
> Signed-off-by: Cai Huoqing <cai.huoqing@xxxxxxxxx>
> ---
> drivers/net/netdevsim/fib.c | 37 ++++++++++++++++++-------------------
> 1 file changed, 18 insertions(+), 19 deletions(-)

What is the rationale for this patch? Are you trying to save
memory?

> @@ -1099,9 +1090,12 @@ static void nsim_fib_dump_inconsistent(struct notifier_block *nb)
> /* The notifier block is still not registered, so we do not need to
> * take any locks here.
> */
> - list_for_each_entry_safe(fib_rt, fib_rt_tmp, &data->fib_rt_list, list) {
> - rhashtable_remove_fast(&data->fib_rt_ht, &fib_rt->ht_node,
> + rhashtable_walk_enter(&data->fib_rt_ht, &hti);
> + rhashtable_walk_start(&hti);
> + while ((pos = rhashtable_walk_next(&hti))) {
> + rhashtable_remove_fast(&data->fib_rt_ht, hti.p,
> nsim_fib_rt_ht_params);
> + fib_rt = rhashtable_walk_peek(&hti);
> nsim_fib_rt_free(fib_rt, data);
> }

In general rhashtable walks are not stable. You may miss entries
or see entries twice. They should be avoided unless absolutely
necessary.

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