From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH v2 07/11] vinyl: zap vy_env::memory, read_threads, and write_threads Date: Fri, 28 Sep 2018 20:40:05 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: They are only used to set corresponding members of vy_quota, vy_run_env, and vy_scheduler when vy_env is created. No point in keeping them around all the time. --- src/box/vinyl.c | 20 +++++--------------- src/box/vy_run.c | 12 ++++++------ src/box/vy_run.h | 17 ++++++++++++----- test/unit/vy_point_lookup.c | 2 +- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/box/vinyl.c b/src/box/vinyl.c index 2ed14c94..25ba92fe 100644 --- a/src/box/vinyl.c +++ b/src/box/vinyl.c @@ -135,14 +135,8 @@ struct vy_env { int64_t join_lsn; /** Path to the data directory. */ char *path; - /** Max size of the memory level. */ - size_t memory; /** Max time a transaction may wait for memory. */ double timeout; - /** Max number of threads used for reading. */ - int read_threads; - /** Max number of threads used for writing. */ - int write_threads; /** Try to recover corrupted data if set. */ bool force_recovery; }; @@ -760,8 +754,7 @@ vinyl_index_open(struct index *index) rc = vy_lsm_create(lsm); if (rc == 0) { /* Make sure reader threads are up and running. */ - vy_run_env_enable_coio(&env->run_env, - env->read_threads); + vy_run_env_enable_coio(&env->run_env); } break; case VINYL_INITIAL_RECOVERY_REMOTE: @@ -2489,10 +2482,7 @@ vy_env_new(const char *path, size_t memory, } memset(e, 0, sizeof(*e)); e->status = VINYL_OFFLINE; - e->memory = memory; e->timeout = TIMEOUT_INFINITY; - e->read_threads = read_threads; - e->write_threads = write_threads; e->force_recovery = force_recovery; e->path = strdup(path); if (e->path == NULL) { @@ -2508,8 +2498,8 @@ vy_env_new(const char *path, size_t memory, if (e->squash_queue == NULL) goto error_squash_queue; - vy_mem_env_create(&e->mem_env, e->memory); - vy_scheduler_create(&e->scheduler, e->write_threads, + vy_mem_env_create(&e->mem_env, memory); + vy_scheduler_create(&e->scheduler, write_threads, vy_env_dump_complete_cb, &e->run_env, &e->xm->read_views); @@ -2526,7 +2516,7 @@ vy_env_new(const char *path, size_t memory, mempool_create(&e->iterator_pool, slab_cache, sizeof(struct vinyl_iterator)); vy_cache_env_create(&e->cache_env, slab_cache); - vy_run_env_create(&e->run_env); + vy_run_env_create(&e->run_env, read_threads); vy_log_init(e->path); return e; @@ -2823,7 +2813,7 @@ vinyl_engine_end_recovery(struct engine *engine) * creation, see vinyl_index_open(). */ if (e->lsm_env.lsm_count > 0) - vy_run_env_enable_coio(&e->run_env, e->read_threads); + vy_run_env_enable_coio(&e->run_env); e->status = VINYL_ONLINE; return 0; diff --git a/src/box/vy_run.c b/src/box/vy_run.c index 7485d97a..bb5baf2c 100644 --- a/src/box/vy_run.c +++ b/src/box/vy_run.c @@ -123,12 +123,11 @@ vy_run_reader_f(va_list ap) /** Start run reader threads. */ static void -vy_run_env_start_readers(struct vy_run_env *env, int threads) +vy_run_env_start_readers(struct vy_run_env *env) { - assert(threads > 0); assert(env->reader_pool == NULL); + assert(env->reader_pool_size > 0); - env->reader_pool_size = threads; env->reader_pool = calloc(env->reader_pool_size, sizeof(*env->reader_pool)); if (env->reader_pool == NULL) @@ -166,9 +165,10 @@ vy_run_env_stop_readers(struct vy_run_env *env) * Initialize vinyl run environment */ void -vy_run_env_create(struct vy_run_env *env) +vy_run_env_create(struct vy_run_env *env, int read_threads) { memset(env, 0, sizeof(*env)); + env->reader_pool_size = read_threads; tt_pthread_key_create(&env->zdctx_key, vy_free_zdctx); mempool_create(&env->read_task_pool, cord_slab_cache(), sizeof(struct vy_page_read_task)); @@ -190,11 +190,11 @@ vy_run_env_destroy(struct vy_run_env *env) * Enable coio reads for a vinyl run environment. */ void -vy_run_env_enable_coio(struct vy_run_env *env, int threads) +vy_run_env_enable_coio(struct vy_run_env *env) { if (env->reader_pool != NULL) return; /* already enabled */ - vy_run_env_start_readers(env, threads); + vy_run_env_start_readers(env); } /** diff --git a/src/box/vy_run.h b/src/box/vy_run.h index d74f216c..4b919a8f 100644 --- a/src/box/vy_run.h +++ b/src/box/vy_run.h @@ -281,9 +281,13 @@ struct vy_page { /** * Initialize vinyl run environment + * + * @param read_threads - max number of background threads to + * use for disk reads; note background threads are not used + * until vy_run_env_enable_coio() is called. */ void -vy_run_env_create(struct vy_run_env *env); +vy_run_env_create(struct vy_run_env *env, int read_threads); /** * Destroy vinyl run environment @@ -294,14 +298,17 @@ vy_run_env_destroy(struct vy_run_env *env); /** * Enable coio reads for a vinyl run environment. * - * This function starts @threads reader threads and makes - * the run iterator hand disk reads over to them rather than - * read run files directly blocking the current fiber. + * This function starts background reader threads and makes + * the run iterator hand disk reads over to them rather + * than read run files directly blocking the current fiber. + * + * The number of background reader threads is configured when + * the environment is created, see vy_run_env_create(). * * Subsequent calls to this function will silently return. */ void -vy_run_env_enable_coio(struct vy_run_env *env, int threads); +vy_run_env_enable_coio(struct vy_run_env *env); /** * Return the size of a run bloom filter. diff --git a/test/unit/vy_point_lookup.c b/test/unit/vy_point_lookup.c index 86877d7d..dd33bbec 100644 --- a/test/unit/vy_point_lookup.c +++ b/test/unit/vy_point_lookup.c @@ -70,7 +70,7 @@ test_basic() is(rc, 0, "vy_lsm_env_create"); struct vy_run_env run_env; - vy_run_env_create(&run_env); + vy_run_env_create(&run_env, 0); struct vy_cache_env cache_env; vy_cache_env_create(&cache_env, slab_cache); -- 2.11.0