[PATCH 06/11] vinyl: zap vy_env::memory, read_threads, and write_threads

Vladimir Davydov vdavydov.dev at gmail.com
Thu Sep 20 12:34:11 MSK 2018


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             | 22 ++++++----------------
 src/box/vy_run.c            | 12 ++++++------
 src/box/vy_run.h            | 17 ++++++++++++-----
 test/unit/vy_point_lookup.c |  2 +-
 4 files changed, 25 insertions(+), 28 deletions(-)

diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index 32143af0..4c1e860d 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -132,14 +132,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;
 };
@@ -759,8 +753,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:
@@ -2491,10 +2484,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) {
@@ -2510,8 +2500,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);
 
@@ -2520,14 +2510,14 @@ vy_env_new(const char *path, size_t memory,
 			      vy_squash_schedule, e) != 0)
 		goto error_lsm_env;
 
-	if (vy_quota_create(&e->quota, e->memory, vy_env_trigger_dump_cb) != 0)
+	if (vy_quota_create(&e->quota, memory, vy_env_trigger_dump_cb) != 0)
 		goto error_quota;
 
 	struct slab_cache *slab_cache = cord_slab_cache();
 	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;
 error_quota:
@@ -2819,7 +2809,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 f107e3a9..975b6349 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 5030886c..5d9865e4 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




More information about the Tarantool-patches mailing list