Reduce thread stack size
authorbart Van Assche <bart.vanassche@gmail.com>
Sun, 1 Aug 2010 19:31:26 +0000 (21:31 +0200)
committerJens Axboe <jaxboe@fusionio.com>
Sun, 1 Aug 2010 19:31:26 +0000 (21:31 +0200)
This patch reduces the stack size required by fio threads and hence allows
to run fio with 200 or more threads on systems with a moderate amount of
virtual memory.

Signed-off-by: Bart Van Assche <bart.vanassche@gmail.com>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
fio.c
verify.c

diff --git a/fio.c b/fio.c
index 896f79774980758df43755d023cdcac5106fd128..6ab0f4ada7229205d6a1774b0f56ff7cfb3fce1f 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -1380,9 +1380,13 @@ static void *gtod_thread_main(void *data)
 
 static int fio_start_gtod_thread(void)
 {
 
 static int fio_start_gtod_thread(void)
 {
+       pthread_attr_t attr;
        int ret;
 
        int ret;
 
-       ret = pthread_create(&gtod_thread, NULL, gtod_thread_main, NULL);
+       pthread_attr_init(&attr);
+       pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
+       ret = pthread_create(&gtod_thread, &attr, gtod_thread_main, NULL);
+       pthread_attr_destroy(&attr);
        if (ret) {
                log_err("Can't create gtod thread: %s\n", strerror(ret));
                return 1;
        if (ret) {
                log_err("Can't create gtod thread: %s\n", strerror(ret));
                return 1;
index 42ea462f0cf656d18a47e404e8d13a13a8dbd0ab..7957bd4110d88bea8aecc242c6460f739871ef99 100644 (file)
--- a/verify.c
+++ b/verify.c
@@ -886,12 +886,16 @@ done:
 int verify_async_init(struct thread_data *td)
 {
        int i, ret;
 int verify_async_init(struct thread_data *td)
 {
        int i, ret;
+       pthread_attr_t attr;
+
+       pthread_attr_init(&attr);
+       pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
 
        td->verify_thread_exit = 0;
 
        td->verify_threads = malloc(sizeof(pthread_t) * td->o.verify_async);
        for (i = 0; i < td->o.verify_async; i++) {
 
        td->verify_thread_exit = 0;
 
        td->verify_threads = malloc(sizeof(pthread_t) * td->o.verify_async);
        for (i = 0; i < td->o.verify_async; i++) {
-               ret = pthread_create(&td->verify_threads[i], NULL,
+               ret = pthread_create(&td->verify_threads[i], &attr,
                                        verify_async_thread, td);
                if (ret) {
                        log_err("fio: async verify creation failed: %s\n",
                                        verify_async_thread, td);
                if (ret) {
                        log_err("fio: async verify creation failed: %s\n",
@@ -907,6 +911,8 @@ int verify_async_init(struct thread_data *td)
                td->nr_verify_threads++;
        }
 
                td->nr_verify_threads++;
        }
 
+       pthread_attr_destroy(&attr);
+
        if (i != td->o.verify_async) {
                log_err("fio: only %d verify threads started, exiting\n", i);
                td->verify_thread_exit = 1;
        if (i != td->o.verify_async) {
                log_err("fio: only %d verify threads started, exiting\n", i);
                td->verify_thread_exit = 1;