rculfhash: default mm type
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 4 Dec 2011 15:40:01 +0000 (10:40 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 4 Dec 2011 15:40:01 +0000 (10:40 -0500)
In the original patch from Lai Jiangshan <laijs@cn.fujitsu.com>:

When I test backend with the following commands.
(my box is x86_64 with 4 cores/logic cpus)
**(test with Load factor = 100% only)**

./tests/test_urcu_hash 4 0 10 -B mmap -h $((1<<19)) -p $((1<<19))
./tests/test_urcu_hash 4 0 10 -B mmap -h $((1<<18)) -p $((1<<18))
./tests/test_urcu_hash 4 0 10 -B mmap -h $((1<<17)) -p $((1<<17))
./tests/test_urcu_hash 4 0 10 -B mmap -h $((1<<16)) -p $((1<<16))
                    4readers/no writer

It shows that mmap backend is about 6% better over order backend.
(It also shows that chunk backend is (worse than)/(the same as) order
backend for small/large min_nr_alloc_buckets. (use -m when test)).

Note:
"6%" and the google-perftools told us the bucket_at() is not the
critical bottleneck.

new strategy:
* infinite buckets size                  --> order mm
* otherwise if 64bits,
   with number of buckets <= (1 << 32)   --> mmap mm
* otherwise                              --> order mm

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
rculfhash.c
urcu/rculfhash.h

index 6c648f17da8a939d22894067eb1cc8c24620a8e0..5ef2c781e3f6330ca631910df85f0a8ef92de954 100644 (file)
@@ -1271,6 +1271,36 @@ struct cds_lfht *_cds_lfht_new(unsigned long init_size,
        if (!init_size || (init_size & (init_size - 1)))
                return NULL;
 
+       /*
+        * Memory management plugin default.
+        */
+       if (!mm) {
+               if (!max_nr_buckets) {
+                       /*
+                        * If the maximum number of buckets is not
+                        * specified, we cannot use the mmap allocator,
+                        * so fallback on order allocator.
+                        */
+                       mm = &cds_lfht_mm_order;
+               } else if (CAA_BITS_PER_LONG > 32
+                               && max_nr_buckets <= (1ULL << 32)) {
+                       /*
+                        * For 64-bit architectures, with max number of
+                        * buckets small enough not to use the entire
+                        * 64-bit memory mapping space (and allowing a
+                        * fair number of hash table instances), use the
+                        * mmap allocator, which is faster than the
+                        * order allocator.
+                        */
+                       mm = &cds_lfht_mm_mmap;
+               } else {
+                       /*
+                        * The fallback is to use the order allocator.
+                        */
+                       mm = &cds_lfht_mm_order;
+               }
+       }
+
        /* max_nr_buckets == 0 for order based mm means infinite */
        if (mm == &cds_lfht_mm_order && !max_nr_buckets)
                max_nr_buckets = 1UL << (MAX_TABLE_ORDER - 1);
index 6ed7c8c75b1db697d78fe4c5c8efaef5601176ae..de315265d38efd597e26a0c4d3938474196005df 100644 (file)
@@ -154,7 +154,7 @@ struct cds_lfht *cds_lfht_new(unsigned long init_size,
                        pthread_attr_t *attr)
 {
        return _cds_lfht_new(init_size, min_nr_alloc_buckets, max_nr_buckets,
-                       flags, &cds_lfht_mm_order, &rcu_flavor, attr);
+                       flags, NULL, &rcu_flavor, attr);
 }
 
 /*
This page took 0.026631 seconds and 4 git commands to generate.