diff options
author | Dave Watson <davejwatson@fb.com> | 2016-10-31 23:23:33 (GMT) |
---|---|---|
committer | Jason Evans <jasone@canonware.com> | 2016-11-03 03:30:53 (GMT) |
commit | 25f7bbcf28f5c83b11149989b3552d87c1f3c5e9 (patch) | |
tree | aa27872a941e3e5d47a6da51d59da53fe018afe5 /include/jemalloc/internal/rtree.h | |
parent | 712fde79fda767ce1eec7cf1c967feeae90b0c21 (diff) | |
download | jemalloc-25f7bbcf28f5c83b11149989b3552d87c1f3c5e9.zip jemalloc-25f7bbcf28f5c83b11149989b3552d87c1f3c5e9.tar.gz jemalloc-25f7bbcf28f5c83b11149989b3552d87c1f3c5e9.tar.bz2 |
Fix long spinning in rtree_node_init
rtree_node_init spinlocks the node, allocates, and then sets the node.
This is under heavy contention at the top of the tree if many threads
start to allocate at the same time.
Instead, take a per-rtree sleeping mutex to reduce spinning. Tested
both pthreads and osx OSSpinLock, and both reduce spinning adequately
Previous benchmark time:
./ttest1 500 100
~15s
New benchmark time:
./ttest1 500 100
.57s
Diffstat (limited to 'include/jemalloc/internal/rtree.h')
-rw-r--r-- | include/jemalloc/internal/rtree.h | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/include/jemalloc/internal/rtree.h b/include/jemalloc/internal/rtree.h index fc88dfe..9c6cc22 100644 --- a/include/jemalloc/internal/rtree.h +++ b/include/jemalloc/internal/rtree.h @@ -23,9 +23,6 @@ typedef struct rtree_s rtree_t; #define RTREE_HEIGHT_MAX \ ((1U << (LG_SIZEOF_PTR+3)) / RTREE_BITS_PER_LEVEL) -/* Used for two-stage lock-free node initialization. */ -#define RTREE_NODE_INITIALIZING ((rtree_elm_t *)0x1) - #define RTREE_CTX_INITIALIZER { \ false, \ 0, \ @@ -139,6 +136,7 @@ struct rtree_s { */ unsigned start_level[RTREE_HEIGHT_MAX + 1]; rtree_level_t levels[RTREE_HEIGHT_MAX]; + malloc_mutex_t init_lock; }; #endif /* JEMALLOC_H_STRUCTS */ @@ -251,7 +249,7 @@ JEMALLOC_ALWAYS_INLINE bool rtree_node_valid(rtree_elm_t *node) { - return ((uintptr_t)node > (uintptr_t)RTREE_NODE_INITIALIZING); + return ((uintptr_t)node != (uintptr_t)0); } JEMALLOC_ALWAYS_INLINE rtree_elm_t * |