projects
/
urcu.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
rculfhash: set next to NULL when node is NULL
[urcu.git]
/
rculfhash.c
diff --git
a/rculfhash.c
b/rculfhash.c
index 1487980c832c115154937cda4b185024636f9e44..8ed9c10b2386c710c2791ed8db3565d4ea13bce5 100644
(file)
--- a/
rculfhash.c
+++ b/
rculfhash.c
@@
-246,7
+246,7
@@
struct cds_lfht {
void (*cds_lfht_rcu_register_thread)(void);
void (*cds_lfht_rcu_unregister_thread)(void);
pthread_attr_t *resize_attr; /* Resize threads attributes */
void (*cds_lfht_rcu_register_thread)(void);
void (*cds_lfht_rcu_unregister_thread)(void);
pthread_attr_t *resize_attr; /* Resize threads attributes */
-
unsigned long count;
/* global approximate item count */
+
long count;
/* global approximate item count */
struct ht_items_count *percpu_count; /* per-cpu item count */
};
struct ht_items_count *percpu_count; /* per-cpu item count */
};
@@
-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)))) {
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,
dbg_printf("add percpu %lu\n", percpu_count);
count = uatomic_add_return(&ht->count,
@@
-565,7
+565,7
@@
void ht_count_add(struct cds_lfht *ht, unsigned long size)
if (!(count & (count - 1))) {
if ((count >> CHAIN_LEN_RESIZE_THRESHOLD) < size)
return;
if (!(count & (count - 1))) {
if ((count >> CHAIN_LEN_RESIZE_THRESHOLD) < size)
return;
- dbg_printf("add set global %l
u
\n", count);
+ dbg_printf("add set global %l
d
\n", count);
cds_lfht_resize_lazy_count(ht, size,
count >> (CHAIN_LEN_TARGET - 1));
}
cds_lfht_resize_lazy_count(ht, size,
count >> (CHAIN_LEN_TARGET - 1));
}
@@
-583,9
+583,9
@@
void ht_count_del(struct cds_lfht *ht, unsigned long size)
cpu = ht_get_cpu();
if (unlikely(cpu < 0))
return;
cpu = ht_get_cpu();
if (unlikely(cpu < 0))
return;
- percpu_count = uatomic_add_return(&ht->percpu_count[cpu].del,
-
1);
+ percpu_count = uatomic_add_return(&ht->percpu_count[cpu].del, 1);
if (unlikely(!(percpu_count & ((1UL << COUNT_COMMIT_ORDER) - 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,
dbg_printf("del percpu %lu\n", percpu_count);
count = uatomic_add_return(&ht->count,
@@
-594,7
+594,13
@@
void ht_count_del(struct cds_lfht *ht, unsigned long size)
if (!(count & (count - 1))) {
if ((count >> CHAIN_LEN_RESIZE_THRESHOLD) >= size)
return;
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 shrink table if the number of nodes is below a
+ * certain threshold.
+ */
+ if (count < (1UL << COUNT_COMMIT_ORDER) * (nr_cpus_mask + 1))
+ return;
cds_lfht_resize_lazy_count(ht, size,
count >> (CHAIN_LEN_TARGET - 1));
}
cds_lfht_resize_lazy_count(ht, size,
count >> (CHAIN_LEN_TARGET - 1));
}
@@
-1274,11
+1280,11
@@
void cds_lfht_lookup(struct cds_lfht *ht, void *key, size_t key_len,
node = clear_flag(node);
for (;;) {
if (unlikely(is_end(node))) {
node = clear_flag(node);
for (;;) {
if (unlikely(is_end(node))) {
- node = NULL;
+ node =
next =
NULL;
break;
}
if (unlikely(node->p.reverse_hash > reverse_hash)) {
break;
}
if (unlikely(node->p.reverse_hash > reverse_hash)) {
- node = NULL;
+ node =
next =
NULL;
break;
}
next = rcu_dereference(node->p.next);
break;
}
next = rcu_dereference(node->p.next);
@@
-1310,11
+1316,11
@@
void cds_lfht_next(struct cds_lfht *ht, struct cds_lfht_iter *iter)
for (;;) {
if (unlikely(is_end(node))) {
for (;;) {
if (unlikely(is_end(node))) {
- node = NULL;
+ node =
next =
NULL;
break;
}
if (unlikely(node->p.reverse_hash > reverse_hash)) {
break;
}
if (unlikely(node->p.reverse_hash > reverse_hash)) {
- node = NULL;
+ node =
next =
NULL;
break;
}
next = rcu_dereference(node->p.next);
break;
}
next = rcu_dereference(node->p.next);
@@
-1446,13
+1452,25
@@
int cds_lfht_destroy(struct cds_lfht *ht, pthread_attr_t **attr)
}
void cds_lfht_count_nodes(struct cds_lfht *ht,
}
void cds_lfht_count_nodes(struct cds_lfht *ht,
+ long *approx_before,
unsigned long *count,
unsigned long *count,
- unsigned long *removed)
+ unsigned long *removed,
+ long *approx_after)
{
struct cds_lfht_node *node, *next;
struct _cds_lfht_node *lookup;
unsigned long nr_dummy = 0;
{
struct cds_lfht_node *node, *next;
struct _cds_lfht_node *lookup;
unsigned long nr_dummy = 0;
+ *approx_before = 0;
+ if (nr_cpus_mask >= 0) {
+ int i;
+
+ for (i = 0; i < nr_cpus_mask + 1; i++) {
+ *approx_before += uatomic_read(&ht->percpu_count[i].add);
+ *approx_before -= uatomic_read(&ht->percpu_count[i].del);
+ }
+ }
+
*count = 0;
*removed = 0;
*count = 0;
*removed = 0;
@@
-1462,8
+1480,10
@@
void cds_lfht_count_nodes(struct cds_lfht *ht,
do {
next = rcu_dereference(node->p.next);
if (is_removed(next)) {
do {
next = rcu_dereference(node->p.next);
if (is_removed(next)) {
- assert(!is_dummy(next));
- (*removed)++;
+ if (!is_dummy(next))
+ (*removed)++;
+ else
+ (nr_dummy)++;
} else if (!is_dummy(next))
(*count)++;
else
} else if (!is_dummy(next))
(*count)++;
else
@@
-1471,6
+1491,15
@@
void cds_lfht_count_nodes(struct cds_lfht *ht,
node = clear_flag(next);
} while (!is_end(node));
dbg_printf("number of dummy nodes: %lu\n", nr_dummy);
node = clear_flag(next);
} while (!is_end(node));
dbg_printf("number of dummy nodes: %lu\n", nr_dummy);
+ *approx_after = 0;
+ if (nr_cpus_mask >= 0) {
+ int i;
+
+ for (i = 0; i < nr_cpus_mask + 1; i++) {
+ *approx_after += uatomic_read(&ht->percpu_count[i].add);
+ *approx_after -= uatomic_read(&ht->percpu_count[i].del);
+ }
+ }
}
/* called with resize mutex held */
}
/* called with resize mutex held */
This page took
0.025835 seconds
and
4
git commands to generate.