From: Mathieu Desnoyers Date: Wed, 21 Sep 2011 14:21:21 +0000 (-0400) Subject: rculfhash: handle small and negative table size approximation X-Git-Tag: v0.7.0~43^2~131 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=e3ecefd6319001d15f8abc05f28fce0feb5c82bb;p=userspace-rcu.git rculfhash: handle small and negative table size approximation Signed-off-by: Mathieu Desnoyers --- diff --git a/rculfhash.c b/rculfhash.c index 7e959fb..9a95be2 100644 --- a/rculfhash.c +++ b/rculfhash.c @@ -556,7 +556,7 @@ void ht_count_add(struct cds_lfht *ht, unsigned long size) return; percpu_count = uatomic_add_return(&ht->percpu_count[cpu].add, 1); if (unlikely(!(percpu_count & ((1UL << COUNT_COMMIT_ORDER) - 1)))) { - unsigned long count; + long count; dbg_printf("add percpu %lu\n", percpu_count); count = uatomic_add_return(&ht->count, @@ -565,7 +565,13 @@ void ht_count_add(struct cds_lfht *ht, unsigned long size) if (!(count & (count - 1))) { if ((count >> CHAIN_LEN_RESIZE_THRESHOLD) < size) return; - dbg_printf("add set global %lu\n", count); + dbg_printf("add set global %ld\n", count); + /* + * Don't resize table if the number of nodes is below a + * certain threshold. + */ + if (count < (1UL << COUNT_COMMIT_ORDER)) + return; cds_lfht_resize_lazy_count(ht, size, count >> (CHAIN_LEN_TARGET - 1)); } @@ -585,7 +591,7 @@ void ht_count_del(struct cds_lfht *ht, unsigned long size) return; percpu_count = uatomic_add_return(&ht->percpu_count[cpu].del, 1); if (unlikely(!(percpu_count & ((1UL << COUNT_COMMIT_ORDER) - 1)))) { - unsigned long count; + long count; dbg_printf("del percpu %lu\n", percpu_count); count = uatomic_add_return(&ht->count, @@ -594,7 +600,13 @@ void ht_count_del(struct cds_lfht *ht, unsigned long size) if (!(count & (count - 1))) { if ((count >> CHAIN_LEN_RESIZE_THRESHOLD) >= size) return; - dbg_printf("del set global %lu\n", count); + dbg_printf("del set global %ld\n", count); + /* + * Don't resize table if the number of nodes is below a + * certain threshold. + */ + if (count < (1UL << COUNT_COMMIT_ORDER)) + return; cds_lfht_resize_lazy_count(ht, size, count >> (CHAIN_LEN_TARGET - 1)); }