From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 1/8] memtx: init index extent allocator in engine constructor Date: Tue, 22 May 2018 14:46:09 +0300 Message-Id: <740aef7d85f42c48c9d07b704d04ad8f8b7320a9.1526987033.git.vdavydov.dev@gmail.com> In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: Postponing it until a memtx index is created for the first time saves us no memory or cpu, it only makes the code more difficult to follow. --- src/box/memtx_bitset.c | 2 -- src/box/memtx_engine.c | 34 +++++++--------------------------- src/box/memtx_engine.h | 9 --------- src/box/memtx_hash.c | 2 -- src/box/memtx_rtree.c | 2 -- src/box/memtx_tree.c | 2 -- 6 files changed, 7 insertions(+), 44 deletions(-) diff --git a/src/box/memtx_bitset.c b/src/box/memtx_bitset.c index 7d8ee11a..93b4a00a 100644 --- a/src/box/memtx_bitset.c +++ b/src/box/memtx_bitset.c @@ -490,8 +490,6 @@ memtx_bitset_index_new(struct memtx_engine *memtx, struct index_def *def) assert(def->iid > 0); assert(!def->opts.is_unique); - memtx_index_arena_init(); - if (!mempool_is_initialized(&memtx->bitset_iterator_pool)) { mempool_create(&memtx->bitset_iterator_pool, cord_slab_cache(), sizeof(struct bitset_index_iterator)); diff --git a/src/box/memtx_engine.c b/src/box/memtx_engine.c index ee3afaec..fd93491e 100644 --- a/src/box/memtx_engine.c +++ b/src/box/memtx_engine.c @@ -55,7 +55,6 @@ * box.slab.info(), @sa lua/slab.cc */ extern struct quota memtx_quota; -static bool memtx_index_arena_initialized = false; struct slab_arena memtx_arena; /* used by memtx_tuple.cc */ static struct slab_cache memtx_index_slab_cache; struct mempool memtx_index_extent_pool; @@ -971,6 +970,13 @@ memtx_engine_new(const char *snap_dirname, bool force_recovery, if (memtx->gc_fiber == NULL) goto fail; + /* Initialize index extent allocator. */ + slab_cache_create(&memtx_index_slab_cache, &memtx_arena); + mempool_create(&memtx_index_extent_pool, &memtx_index_slab_cache, + MEMTX_EXTENT_SIZE); + memtx_index_num_reserved_extents = 0; + memtx_index_reserved_extents = NULL; + memtx->state = MEMTX_INITIALIZED; memtx->force_recovery = force_recovery; @@ -1007,32 +1013,6 @@ memtx_engine_set_max_tuple_size(struct memtx_engine *memtx, size_t max_size) } /** - * Initialize arena for indexes. - * The arena is used for memtx_index_extent_alloc - * and memtx_index_extent_free. - * Can be called several times, only first call do the work. - */ -void -memtx_index_arena_init(void) -{ - if (memtx_index_arena_initialized) { - /* already done.. */ - return; - } - /* Creating slab cache */ - slab_cache_create(&memtx_index_slab_cache, &memtx_arena); - /* Creating mempool */ - mempool_create(&memtx_index_extent_pool, - &memtx_index_slab_cache, - MEMTX_EXTENT_SIZE); - /* Empty reserved list */ - memtx_index_num_reserved_extents = 0; - memtx_index_reserved_extents = 0; - /* Done */ - memtx_index_arena_initialized = true; -} - -/** * Allocate a block of size MEMTX_EXTENT_SIZE for memtx index */ void * diff --git a/src/box/memtx_engine.h b/src/box/memtx_engine.h index 2ce597b4..72f40528 100644 --- a/src/box/memtx_engine.h +++ b/src/box/memtx_engine.h @@ -154,15 +154,6 @@ enum { }; /** - * Initialize arena for indexes. - * The arena is used for memtx_index_extent_alloc - * and memtx_index_extent_free. - * Can be called several times, only first call do the work. - */ -void -memtx_index_arena_init(void); - -/** * Allocate a block of size MEMTX_EXTENT_SIZE for memtx index */ void * diff --git a/src/box/memtx_hash.c b/src/box/memtx_hash.c index 20d6ac5d..08ba84ad 100644 --- a/src/box/memtx_hash.c +++ b/src/box/memtx_hash.c @@ -461,8 +461,6 @@ static const struct index_vtab memtx_hash_index_vtab = { struct memtx_hash_index * memtx_hash_index_new(struct memtx_engine *memtx, struct index_def *def) { - memtx_index_arena_init(); - if (!mempool_is_initialized(&memtx->hash_iterator_pool)) { mempool_create(&memtx->hash_iterator_pool, cord_slab_cache(), sizeof(struct hash_iterator)); diff --git a/src/box/memtx_rtree.c b/src/box/memtx_rtree.c index 6afd5521..baeffa26 100644 --- a/src/box/memtx_rtree.c +++ b/src/box/memtx_rtree.c @@ -350,8 +350,6 @@ memtx_rtree_index_new(struct memtx_engine *memtx, struct index_def *def) enum rtree_distance_type distance_type = (enum rtree_distance_type)def->opts.distance; - memtx_index_arena_init(); - if (!mempool_is_initialized(&memtx->rtree_iterator_pool)) { mempool_create(&memtx->rtree_iterator_pool, cord_slab_cache(), sizeof(struct index_rtree_iterator)); diff --git a/src/box/memtx_tree.c b/src/box/memtx_tree.c index 6b76e538..0911af52 100644 --- a/src/box/memtx_tree.c +++ b/src/box/memtx_tree.c @@ -669,8 +669,6 @@ static const struct index_vtab memtx_tree_index_vtab = { struct memtx_tree_index * memtx_tree_index_new(struct memtx_engine *memtx, struct index_def *def) { - memtx_index_arena_init(); - if (!mempool_is_initialized(&memtx->tree_iterator_pool)) { mempool_create(&memtx->tree_iterator_pool, cord_slab_cache(), sizeof(struct tree_iterator)); -- 2.11.0