From e1977a4e75637109889b581201e44e24506398c8 Mon Sep 17 00:00:00 2001 From: Shehjar Tikoo Date: Fri, 10 Apr 2009 04:21:53 -0700 Subject: io-threads: Use non-default thread stack size The default stack size on Linux is around 8 MiB for each thread. This is clearly too high for our purpose. This commit reduces the stack size down to 1 MiB. Signed-off-by: Anand V. Avati --- xlators/performance/io-threads/src/io-threads.c | 22 +++++++++++++++++++++- xlators/performance/io-threads/src/io-threads.h | 6 ++++++ 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'xlators') diff --git a/xlators/performance/io-threads/src/io-threads.c b/xlators/performance/io-threads/src/io-threads.c index b8cb633cdeb..66aec51a37e 100644 --- a/xlators/performance/io-threads/src/io-threads.c +++ b/xlators/performance/io-threads/src/io-threads.c @@ -1759,7 +1759,8 @@ void iot_startup_worker (iot_worker_t *worker, iot_worker_fn workerfunc) { worker->state = IOT_STATE_ACTIVE; - pthread_create (&worker->thread, NULL, workerfunc, worker); + pthread_create (&worker->thread, &worker->conf->w_attr, workerfunc, + worker); } @@ -1776,6 +1777,24 @@ iot_startup_workers (iot_worker_t **workers, int start_idx, int count, } +static void +set_stack_size (iot_conf_t *conf) +{ + int err = 0; + size_t stacksize = IOT_THREAD_STACK_SIZE; + + pthread_attr_init (&conf->w_attr); + err = pthread_attr_setstacksize (&conf->w_attr, stacksize); + if (err == EINVAL) { + gf_log (conf->this->name, GF_LOG_WARNING, + "Using default thread stack size"); + stacksize = 0; + } + + pthread_attr_setstacksize (&conf->w_attr, stacksize); + +} + static void workers_init (iot_conf_t *conf) { @@ -1787,6 +1806,7 @@ workers_init (iot_conf_t *conf) conf->oworkers = allocate_worker_array (conf->max_o_threads); allocate_workers (conf, conf->oworkers, 0, conf->max_o_threads); + set_stack_size (conf); iot_startup_workers (conf->oworkers, 0, conf->min_o_threads, iot_worker_ordered); iot_startup_workers (conf->uworkers, 0, conf->min_u_threads, diff --git a/xlators/performance/io-threads/src/io-threads.h b/xlators/performance/io-threads/src/io-threads.h index 3bc37a67d43..3fff676f6cf 100644 --- a/xlators/performance/io-threads/src/io-threads.h +++ b/xlators/performance/io-threads/src/io-threads.h @@ -65,6 +65,8 @@ struct iot_request { #define iot_ordered_scaling_on(conf) ((conf)->o_scaling == IOT_SCALING_ON) #define iot_unordered_scaling_on(conf) ((conf)->u_scaling == IOT_SCALING_ON) +#define IOT_THREAD_STACK_SIZE ((size_t)(1024*1024)) + struct iot_worker { struct list_head rqlist; /* List of requests assigned to me. */ struct iot_conf *conf; @@ -131,6 +133,10 @@ struct iot_conf { and never lets any thread exit. */ + pthread_attr_t w_attr; /* Used to reduce the stack size of the + pthread worker down from the default of + 8MiB. + */ }; typedef struct iot_conf iot_conf_t; -- cgit