Re: [PATCH] rhashtable: add likely() to __rht_ptr()

From: Menglong Dong

Date: Tue Sep 23 2025 - 05:30:25 EST


On Tue, Sep 23, 2025 at 2:36 PM Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx> wrote:
>
> Menglong Dong <menglong8.dong@xxxxxxxxx> wrote:
> > In the fast path, the value of "p" in __rht_ptr() should be valid.
> > Therefore, wrap it with a "likely". The performance increasing is tiny,
> > but it's still worth to do it.
> >
> > Signed-off-by: Menglong Dong <dongml2@xxxxxxxxxxxxxxx>
> > ---
> > include/linux/rhashtable.h | 5 +++--
> > 1 file changed, 3 insertions(+), 2 deletions(-)
>
> It's not obvious that rht_ptr would be non-NULL. It depends on the
> work load. For example, if you're doing a lookup where most keys
> are non-existent then it would most likely be NULL.

Yeah, I see. In my case, the usage of the rhashtable will be:
add -> lookup, and rht_ptr is alway non-NULL. You are right,
it can be NULL in other situations, and it's not a good idea to
use likely() here ;)

Thanks!
Menglong Dong

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