[PATCH] fio: scale max_jobs if the shm segment gets too large
authorJens Axboe <axboe@suse.de>
Mon, 24 Oct 2005 08:07:45 +0000 (10:07 +0200)
committerJens Axboe <axboe@suse.de>
Mon, 24 Oct 2005 08:07:45 +0000 (10:07 +0200)
fio.c

diff --git a/fio.c b/fio.c
index b90036f796b698afb0a12dbed0d785663d4d3b3d..da3cd28650d69fade149daaa3bb4ebbb3d8b0719 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -101,6 +101,8 @@ static int rate_quit = 1;
 static int thread_number;
 static char *ini_file;
 
+static int max_jobs = MAX_JOBS;
+
 static int shm_id;
 
 enum {
@@ -814,7 +816,7 @@ static struct thread_data *get_new_job(int global)
 
        if (global)
                return &def_thread;
-       if (thread_number >= MAX_JOBS)
+       if (thread_number >= max_jobs)
                return NULL;
 
        td = &threads[thread_number++];
@@ -1369,26 +1371,48 @@ static void run_threads(char *argv[])
        }
 }
 
-int main(int argc, char *argv[])
+int setup_thread_area(void)
 {
-       static unsigned long max_run[2], min_run[2], total_blocks[2];
-       static unsigned long max_bw[2], min_bw[2], maxl[2], minl[2];
-       static unsigned long read_mb, write_mb, read_agg, write_agg;
-       int i;
+       /*
+        * 1024 is too much on some machines, scale max_jobs if
+        * we get a failure that looks like too large a shm segment
+        */
+       do {
+               int s = max_jobs * sizeof(struct thread_data);
 
-       shm_id = shmget(0, MAX_JOBS * sizeof(struct thread_data), IPC_CREAT | 0600);
-       if (shm_id == -1) {
-               perror("shmget");
+               shm_id = shmget(0, s, IPC_CREAT | 0600);
+               if (shm_id != -1)
+                       break;
+               if (errno != EINVAL) {
+                       perror("shmget");
+                       break;
+               }
+
+               max_jobs >>= 1;
+       } while (1);
+
+       if (shm_id == -1)
                return 1;
-       }
 
        threads = shmat(shm_id, NULL, 0);
-       if (threads == (void *) -1 ) {
+       if (threads == (void *) -1) {
                perror("shmat");
                return 1;
        }
 
        atexit(free_shm);
+       return 0;
+}
+
+int main(int argc, char *argv[])
+{
+       static unsigned long max_run[2], min_run[2], total_blocks[2];
+       static unsigned long max_bw[2], min_bw[2], maxl[2], minl[2];
+       static unsigned long read_mb, write_mb, read_agg, write_agg;
+       int i;
+
+       if (setup_thread_area())
+               return 1;
 
        if (sched_getaffinity(getpid(), sizeof(cpu_set_t), &def_thread.cpumask) == -1) {
                perror("sched_getaffinity");