mbox series

[RFC,net-next,0/4] rhashtable: length helper for rhashtable and rhltable

Message ID 20230609151332.263152-1-pctammela@mojatatu.com (mailing list archive)
Headers show
Series rhashtable: length helper for rhashtable and rhltable | expand

Message

Pedro Tammela June 9, 2023, 3:13 p.m. UTC
Whenever someone wants to retrieve the total number of elements in a
rhashtable/rhltable it needs to open code the access to 'nelems'.
Therefore provide a helper for such operation and convert two accesses as
an example.

Pedro Tammela (4):
  rhashtable: add length helper for rhashtable and rhltable
  rhashtable: use new length helpers
  net/ipv4: use rhashtable length helper
  net/ipv6: use rhashtable length helper

 include/linux/rhashtable.h | 16 ++++++++++++++++
 lib/rhashtable.c           |  2 +-
 lib/test_rhashtable.c      |  4 ++--
 net/ipv4/proc.c            |  3 ++-
 net/ipv6/proc.c            |  3 ++-
 5 files changed, 23 insertions(+), 5 deletions(-)

Comments

Jakub Kicinski June 9, 2023, 5:36 p.m. UTC | #1
On Fri,  9 Jun 2023 12:13:28 -0300 Pedro Tammela wrote:
> Whenever someone wants to retrieve the total number of elements in a
> rhashtable/rhltable it needs to open code the access to 'nelems'.
> Therefore provide a helper for such operation and convert two accesses as
> an example.

IMHO read of nelems is much more readable than len(). I mean the name
of the helper is not great. IDK what length of a hashtable is. Feels
like a Python-ism.
Pedro Tammela June 9, 2023, 6:13 p.m. UTC | #2
On 09/06/2023 14:36, Jakub Kicinski wrote:
> On Fri,  9 Jun 2023 12:13:28 -0300 Pedro Tammela wrote:
>> Whenever someone wants to retrieve the total number of elements in a
>> rhashtable/rhltable it needs to open code the access to 'nelems'.
>> Therefore provide a helper for such operation and convert two accesses as
>> an example.
> 
> IMHO read of nelems is much more readable than len().

For the case of rhltable it requires:
	atomic_read(rhltable->rt.nelems);

Which feels like it defeats the purpose of the dedicated rhltable type 
in the first place.
But I must admit that there are no use cases in-tree AFAIK.

Another point is that having this sort of helper also conveys that it's 
OK for a consumer to query this value at any time.

> I mean the name of the helper is not great. > IDK what length of a hashtable is. Feels like a Python-ism.

Well 'length' has been the term used in a few languages (Python, Rust, 
Go, etc...) so it felt the most fitting. If you have any suggestions in 
mind, do tell; Some that crossed my mind were:
- count
- size
- elems
- num
Jakub Kicinski June 9, 2023, 6:21 p.m. UTC | #3
On Fri, 9 Jun 2023 15:13:40 -0300 Pedro Tammela wrote:
> > I mean the name of the helper is not great. > IDK what length of a hashtable is. Feels like a Python-ism.  
> 
> Well 'length' has been the term used in a few languages (Python, Rust, 
> Go, etc...) so it felt the most fitting. If you have any suggestions in 
> mind, do tell; Some that crossed my mind were:
> - count
> - size
> - elems
> - num

count and elems sound best to me