summaryrefslogtreecommitdiffstats
path: root/test/unit/rtree.c
diff options
context:
space:
mode:
authorJason Evans <je@fb.com>2014-01-03 01:36:38 (GMT)
committerJason Evans <je@fb.com>2014-01-03 01:36:38 (GMT)
commitb954bc5d3a65966df0ce7801cd6102542b5e894b (patch)
treeac7b4d7ca10898f6113414ab0e2ef162915d4aa9 /test/unit/rtree.c
parentb980cc774a9ccb208a82f4e9ccdcc695d06a960a (diff)
downloadjemalloc-b954bc5d3a65966df0ce7801cd6102542b5e894b.zip
jemalloc-b954bc5d3a65966df0ce7801cd6102542b5e894b.tar.gz
jemalloc-b954bc5d3a65966df0ce7801cd6102542b5e894b.tar.bz2
Convert rtree from (void *) to (uint8_t) storage.
Reduce rtree memory usage by storing booleans (1 byte each) rather than pointers. The rtree code is only used to record whether jemalloc manages a chunk of memory, so there's no need to store pointers in the rtree. Increase rtree node size to 64 KiB in order to reduce tree depth from 13 to 3 on 64-bit systems. The conversion to more compact leaf nodes was enough by itself to make the rtree depth 1 on 32-bit systems; due to the fact that root nodes are smaller than the specified node size if possible, the node size change has no impact on 32-bit systems (assuming default chunk size).
Diffstat (limited to 'test/unit/rtree.c')
-rw-r--r--test/unit/rtree.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/test/unit/rtree.c b/test/unit/rtree.c
index c12a744..5e7a411 100644
--- a/test/unit/rtree.c
+++ b/test/unit/rtree.c
@@ -6,7 +6,7 @@ TEST_BEGIN(test_rtree_get_empty)
for (i = 1; i <= (sizeof(uintptr_t) << 3); i++) {
rtree_t *rtree = rtree_new(i, imalloc, idalloc);
- assert_ptr_null(rtree_get(rtree, 0),
+ assert_u_eq(rtree_get(rtree, 0), 0,
"rtree_get() should return NULL for empty tree");
rtree_delete(rtree);
}
@@ -20,12 +20,12 @@ TEST_BEGIN(test_rtree_extrema)
for (i = 1; i <= (sizeof(uintptr_t) << 3); i++) {
rtree_t *rtree = rtree_new(i, imalloc, idalloc);
- rtree_set(rtree, 0, (void *)1);
- assert_ptr_eq(rtree_get(rtree, 0), (void *)1,
+ rtree_set(rtree, 0, 1);
+ assert_u_eq(rtree_get(rtree, 0), 1,
"rtree_get() should return previously set value");
- rtree_set(rtree, ~((uintptr_t)0), (void *)1);
- assert_ptr_eq(rtree_get(rtree, ~((uintptr_t)0)), (void *)1,
+ rtree_set(rtree, ~((uintptr_t)0), 1);
+ assert_u_eq(rtree_get(rtree, ~((uintptr_t)0)), 1,
"rtree_get() should return previously set value");
rtree_delete(rtree);
@@ -43,21 +43,19 @@ TEST_BEGIN(test_rtree_bits)
rtree_t *rtree = rtree_new(i, imalloc, idalloc);
for (j = 0; j < sizeof(keys)/sizeof(uintptr_t); j++) {
- rtree_set(rtree, keys[j], (void *)1);
+ rtree_set(rtree, keys[j], 1);
for (k = 0; k < sizeof(keys)/sizeof(uintptr_t); k++) {
- assert_ptr_eq(rtree_get(rtree, keys[k]),
- (void *)1,
+ assert_u_eq(rtree_get(rtree, keys[k]), 1,
"rtree_get() should return previously set "
"value and ignore insignificant key bits; "
"i=%u, j=%u, k=%u, set key=%#x, "
"get key=%#x", i, j, k, keys[j], keys[k]);
}
- assert_ptr_eq(rtree_get(rtree,
- (((uintptr_t)1) << (sizeof(uintptr_t)*8-i))),
- (void *)0,
+ assert_u_eq(rtree_get(rtree,
+ (((uintptr_t)1) << (sizeof(uintptr_t)*8-i))), 0,
"Only leftmost rtree leaf should be set; "
"i=%u, j=%u", i, j);
- rtree_set(rtree, keys[j], (void *)0);
+ rtree_set(rtree, keys[j], 0);
}
rtree_delete(rtree);
@@ -80,22 +78,22 @@ TEST_BEGIN(test_rtree_random)
for (j = 0; j < NSET; j++) {
keys[j] = (uintptr_t)gen_rand64(sfmt);
- rtree_set(rtree, keys[j], (void *)1);
- assert_ptr_eq(rtree_get(rtree, keys[j]), (void *)1,
+ rtree_set(rtree, keys[j], 1);
+ assert_u_eq(rtree_get(rtree, keys[j]), 1,
"rtree_get() should return previously set value");
}
for (j = 0; j < NSET; j++) {
- assert_ptr_eq(rtree_get(rtree, keys[j]), (void *)1,
+ assert_u_eq(rtree_get(rtree, keys[j]), 1,
"rtree_get() should return previously set value");
}
for (j = 0; j < NSET; j++) {
- rtree_set(rtree, keys[j], (void *)0);
- assert_ptr_eq(rtree_get(rtree, keys[j]), (void *)0,
+ rtree_set(rtree, keys[j], 0);
+ assert_u_eq(rtree_get(rtree, keys[j]), 0,
"rtree_get() should return previously set value");
}
for (j = 0; j < NSET; j++) {
- assert_ptr_eq(rtree_get(rtree, keys[j]), (void *)0,
+ assert_u_eq(rtree_get(rtree, keys[j]), 0,
"rtree_get() should return previously set value");
}