From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: kostja@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [PATCH 1/8] memtx: init index extent allocator in engine constructor
Date: Tue, 22 May 2018 14:46:09 +0300 [thread overview]
Message-ID: <740aef7d85f42c48c9d07b704d04ad8f8b7320a9.1526987033.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1526987033.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1526987033.git.vdavydov.dev@gmail.com>
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
next prev parent reply other threads:[~2018-05-22 11:46 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-22 11:46 [PATCH 0/8] Follow-up on async memtx index cleanup Vladimir Davydov
2018-05-22 11:46 ` Vladimir Davydov [this message]
2018-05-22 13:43 ` [PATCH 1/8] memtx: init index extent allocator in engine constructor Konstantin Osipov
2018-05-22 11:46 ` [PATCH 2/8] memtx: fold memtx_tuple.cc into memtx_engine.c Vladimir Davydov
2018-05-22 13:45 ` Konstantin Osipov
2018-05-22 11:46 ` [PATCH 3/8] memtx: pass engine to memory allocation functions Vladimir Davydov
2018-05-22 13:47 ` Konstantin Osipov
2018-05-22 14:39 ` Vladimir Davydov
2018-05-22 11:46 ` [PATCH 4/8] memtx: move all global variables to engine Vladimir Davydov
2018-05-22 13:48 ` Konstantin Osipov
2018-05-22 11:46 ` [PATCH 5/8] memtx: destroy slab arena on engine shutdown Vladimir Davydov
2018-05-22 13:50 ` Konstantin Osipov
2018-05-22 16:26 ` Vladimir Davydov
2018-05-22 11:46 ` [PATCH 6/8] memtx: embed light hash into memtx_hash_index Vladimir Davydov
2018-05-22 13:51 ` Konstantin Osipov
2018-05-22 11:46 ` [PATCH 7/8] memtx: rework background garbage collection procedure Vladimir Davydov
2018-05-22 13:56 ` Konstantin Osipov
2018-05-22 14:49 ` Vladimir Davydov
2018-05-22 16:42 ` Konstantin Osipov
2018-05-22 11:46 ` [PATCH 8/8] memtx: run garbage collection on demand Vladimir Davydov
2018-05-22 14:00 ` Konstantin Osipov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=740aef7d85f42c48c9d07b704d04ad8f8b7320a9.1526987033.git.vdavydov.dev@gmail.com \
--to=vdavydov.dev@gmail.com \
--cc=kostja@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [PATCH 1/8] memtx: init index extent allocator in engine constructor' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox