struct rcu_table t;
cds_lfht_hash_fct hash_fct;
cds_lfht_compare_fct compare_fct;
+ unsigned long min_alloc_order;
+ unsigned long min_alloc_size;
unsigned long hash_seed;
int flags;
/*
assert(size > 0);
index = hash & (size - 1);
+
+ if (index < ht->min_alloc_size) {
+ dbg_printf("lookup hash %lu index %lu order 0 aridx 0\n",
+ hash, index);
+ return &ht->t.tbl[0]->nodes[index];
+ }
/*
* equivalent to get_count_order_ulong(index + 1), but optimizes
* away the non-existing 0 special-case for
* get_count_order_ulong.
*/
order = fls_ulong(index);
-
dbg_printf("lookup hash %lu index %lu order %lu aridx %lu\n",
- hash, index, order, index & (!order ? 0 : ((1UL << (order - 1)) - 1)));
-
- return &ht->t.tbl[order]->nodes[index & (!order ? 0 : ((1UL << (order - 1)) - 1))];
+ hash, index, order, index & ((1UL << (order - 1)) - 1));
+ return &ht->t.tbl[order]->nodes[index & ((1UL << (order - 1)) - 1)];
}
/*
{
unsigned long j;
- assert(i > 0);
+ assert(i > ht->min_alloc_order);
ht->cds_lfht_rcu_read_lock();
for (j = start; j < start + len; j++) {
struct cds_lfht_node *new_node =
dbg_printf("init table: first_order %lu last_order %lu\n",
first_order, last_order);
- assert(first_order > 0);
+ assert(first_order > ht->min_alloc_order);
for (i = first_order; i <= last_order; i++) {
unsigned long len;
{
unsigned long j;
- assert(i > 0);
+ assert(i > ht->min_alloc_order);
ht->cds_lfht_rcu_read_lock();
for (j = start; j < start + len; j++) {
struct cds_lfht_node *fini_node =
dbg_printf("fini table: first_order %lu last_order %lu\n",
first_order, last_order);
- assert(first_order > 0);
+ assert(first_order > ht->min_alloc_order);
for (i = last_order; i >= first_order; i--) {
unsigned long len;
struct _cds_lfht_node *prev, *node;
unsigned long order, len, i, j;
- ht->t.tbl[0] = calloc(1, sizeof(struct _cds_lfht_node));
+ ht->t.tbl[0] = calloc(1, ht->min_alloc_size * sizeof(struct _cds_lfht_node));
assert(ht->t.tbl[0]);
dbg_printf("create dummy: order %lu index %lu hash %lu\n", 0, 0, 0);
for (order = 1; order < get_count_order_ulong(size) + 1; order++) {
len = 1UL << (order - 1);
- ht->t.tbl[order] = calloc(1, len * sizeof(struct _cds_lfht_node));
- assert(ht->t.tbl[order]);
+ if (order <= ht->min_alloc_order) {
+ ht->t.tbl[order] = (struct rcu_level *) (ht->t.tbl[0]->nodes + len);
+ } else {
+ ht->t.tbl[order] = calloc(1, len * sizeof(struct _cds_lfht_node));
+ assert(ht->t.tbl[order]);
+ }
i = 0;
prev = ht->t.tbl[i]->nodes;
cds_lfht_compare_fct compare_fct,
unsigned long hash_seed,
unsigned long init_size,
+ unsigned long min_alloc_size,
int flags,
void (*cds_lfht_call_rcu)(struct rcu_head *head,
void (*func)(struct rcu_head *head)),
struct cds_lfht *ht;
unsigned long order;
+ /* min_alloc_size must be power of two */
+ if (!min_alloc_size || (min_alloc_size & (min_alloc_size - 1)))
+ return NULL;
/* init_size must be power of two */
- if (init_size && (init_size & (init_size - 1)))
+ if (!init_size || (init_size & (init_size - 1)))
return NULL;
+ min_alloc_size = max(min_alloc_size, MIN_TABLE_SIZE);
+ init_size = max(init_size, min_alloc_size);
ht = calloc(1, sizeof(struct cds_lfht));
assert(ht);
ht->hash_fct = hash_fct;
/* this mutex should not nest in read-side C.S. */
pthread_mutex_init(&ht->resize_mutex, NULL);
ht->flags = flags;
- order = get_count_order_ulong(max(init_size, MIN_TABLE_SIZE));
+ order = get_count_order_ulong(init_size);
ht->t.resize_target = 1UL << order;
cds_lfht_create_dummy(ht, 1UL << order);
ht->t.size = 1UL << order;
+ ht->min_alloc_size = min_alloc_size;
+ ht->min_alloc_order = get_count_order_ulong(min_alloc_size);
return ht;
}
bit_reverse_ulong(ht->t.tbl[order]->nodes[i].reverse_hash));
assert(is_dummy(ht->t.tbl[order]->nodes[i].next));
}
- poison_free(ht->t.tbl[order]);
+
+ if (order == ht->min_alloc_order)
+ poison_free(ht->t.tbl[0]);
+ else if (order > ht->min_alloc_order)
+ poison_free(ht->t.tbl[order]);
+ /* Nothing to delete for order < ht->min_alloc_order */
}
return 0;
}
{
unsigned long old_order, new_order;
- new_size = max(new_size, MIN_TABLE_SIZE);
+ new_size = max(new_size, ht->min_alloc_size);
old_order = get_count_order_ulong(old_size);
new_order = get_count_order_ulong(new_size);
dbg_printf("resize from %lu (order %lu) to %lu (order %lu) buckets\n",
void resize_target_update_count(struct cds_lfht *ht,
unsigned long count)
{
- count = max(count, MIN_TABLE_SIZE);
+ count = max(count, ht->min_alloc_size);
uatomic_set(&ht->t.resize_target, count);
}