cds_lfht_new() clarification - init vs min
Ondřej Surý
ondrej at sury.org
Wed Jul 9 14:57:31 EDT 2025
Hi,
as the answer to this might be useful to more people, I am asking here:
The cds_lfht_new documentation specifies 3 sizes.
* cds_lfht_new - allocate a hash table.
* @init_size: number of buckets to allocate initially. Must be power of two.
* @min_nr_alloc_buckets: the minimum number of allocated buckets.
* (must be power of two)
* @max_nr_buckets: the maximum number of hash table buckets allowed.
* (must be power of two, 0 is accepted, means
* "infinite")
The max number of buckets is obvious, but the interaction between init
and min is confusing.
If I am reading the code right, then init_size < min_nr_alloc_buckets have no
effect, the buckets table will be at least 1 << min_nr_alloc_buckets.
But what happens if init_size > min_nr_alloc_buckets? It feels like it will work
as expected if you pre-populate the table, but if you use it "normally", e.g. there
could be single add / del, the table will shrink immediately.
Do I understand the code correctly?
Ondrej
--
Ondřej Surý (He/Him)
ondrej at sury.org
More information about the lttng-dev
mailing list