Make lockmem a per job option
authorJens Axboe <axboe@kernel.dk>
Wed, 28 Mar 2012 18:50:15 +0000 (20:50 +0200)
committerJens Axboe <axboe@kernel.dk>
Thu, 11 Apr 2013 06:51:42 +0000 (08:51 +0200)
We need to get rid of per job options that fiddle with global
state. It's confusing, and it breaks remote option handling.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Conflicts:
backend.c
fio.h
init.c
options.c

Signed-off-by: Jens Axboe <axboe@kernel.dk>
backend.c
fio.h
init.c
memory.c

index c397eb173d2f6ad19552ab683af6517b48567e4a..5fc0fc86f7ae7ab94abd7317cba44c194850c0d1 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -1205,6 +1205,9 @@ static void *thread_main(void *data)
        }
 #endif
 
+       if (fio_pin_memory(td))
+               goto err;
+
        /*
         * May alter parameters that init_io_u() will use, so we need to
         * do this first.
@@ -1330,6 +1333,8 @@ static void *thread_main(void *data)
        td->ts.io_bytes[DDIR_WRITE] = td->io_bytes[DDIR_WRITE];
        td->ts.io_bytes[DDIR_TRIM] = td->io_bytes[DDIR_TRIM];
 
+       fio_unpin_memory(td);
+
        fio_mutex_down(writeout_mutex);
        if (td->bw_log) {
                if (td->o.bw_log_file) {
@@ -1545,9 +1550,6 @@ static void run_threads(void)
        unsigned long spent;
        unsigned int i, todo, nr_running, m_rate, t_rate, nr_started;
 
-       if (fio_pin_memory())
-               return;
-
        if (fio_gtod_offload && fio_start_gtod_thread())
                return;
        
@@ -1780,7 +1782,6 @@ static void run_threads(void)
        fio_idle_prof_stop();
 
        update_io_ticks();
-       fio_unpin_memory();
 }
 
 void wait_for_disk_thread_exit(void)
diff --git a/fio.h b/fio.h
index e55413a95dcb8fccc92019fd8cfa245b84be1f0c..2c8d9040e732a351d78ea9cfbf586045561941a5 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -308,6 +308,8 @@ struct thread_data {
         */
        struct prof_io_ops prof_io_ops;
        void *prof_data;
+
+       void *pinned_mem;
 };
 
 /*
@@ -348,7 +350,6 @@ extern int shm_id;
 extern int groupid;
 extern int output_format;
 extern int temp_stall_ts;
-extern unsigned long long mlock_size;
 extern uintptr_t page_mask, page_size;
 extern int read_only;
 extern int eta_print;
@@ -481,8 +482,8 @@ extern void fio_terminate_threads(int);
 /*
  * Memory helpers
  */
-extern int __must_check fio_pin_memory(void);
-extern void fio_unpin_memory(void);
+extern int __must_check fio_pin_memory(struct thread_data *);
+extern void fio_unpin_memory(struct thread_data *);
 extern int __must_check allocate_io_mem(struct thread_data *);
 extern void free_io_mem(struct thread_data *);
 
diff --git a/init.c b/init.c
index 44c74e315a4b758ccdd7bb8055094014d395b12e..9e2d1131d276637983094c1cbdf5afbb9172225a 100644 (file)
--- a/init.c
+++ b/init.c
@@ -45,7 +45,6 @@ int exitall_on_terminate = 0;
 int output_format = FIO_OUTPUT_NORMAL;
 int eta_print = FIO_ETA_AUTO;
 int eta_new_line = 0;
-unsigned long long mlock_size = 0;
 FILE *f_out = NULL;
 FILE *f_err = NULL;
 char **job_sections = NULL;
index 443d71d4bbda3de4c2771c055c77abdd49442954..9e751bedcc70b2bb8b9e2bf9a74228a3478a9630 100644 (file)
--- a/memory.c
+++ b/memory.c
 #include <sys/shm.h>
 #endif
 
-static void *pinned_mem;
-
-void fio_unpin_memory(void)
+void fio_unpin_memory(struct thread_data *td)
 {
-       if (pinned_mem) {
-               dprint(FD_MEM, "unpinning %llu bytes\n", mlock_size);
-               if (munlock(pinned_mem, mlock_size) < 0)
+       if (td->pinned_mem) {
+               dprint(FD_MEM, "unpinning %llu bytes\n", td->o.lockmem);
+               if (munlock(td->pinned_mem, td->o.lockmem) < 0)
                        perror("munlock");
-               munmap(pinned_mem, mlock_size);
-               pinned_mem = NULL;
+               munmap(td->pinned_mem, td->o.lockmem);
+               td->pinned_mem = NULL;
        }
 }
 
-int fio_pin_memory(void)
+int fio_pin_memory(struct thread_data *td)
 {
        unsigned long long phys_mem;
 
-       if (!mlock_size)
+       if (!td->o.lockmem)
                return 0;
 
-       dprint(FD_MEM, "pinning %llu bytes\n", mlock_size);
+       dprint(FD_MEM, "pinning %llu bytes\n", td->o.lockmem);
 
        /*
         * Don't allow mlock of more than real_mem-128MB
         */
        phys_mem = os_phys_mem();
        if (phys_mem) {
-               if ((mlock_size + 128 * 1024 * 1024) > phys_mem) {
-                       mlock_size = phys_mem - 128 * 1024 * 1024;
+               if ((td->o.lockmem + 128 * 1024 * 1024) > phys_mem) {
+                       td->o.lockmem = phys_mem - 128 * 1024 * 1024;
                        log_info("fio: limiting mlocked memory to %lluMB\n",
-                                                       mlock_size >> 20);
+                                                       td->o.lockmem >> 20);
                }
        }
 
-       pinned_mem = mmap(NULL, mlock_size, PROT_READ | PROT_WRITE,
+       td->pinned_mem = mmap(NULL, td->o.lockmem, PROT_READ | PROT_WRITE,
                                MAP_PRIVATE | OS_MAP_ANON, -1, 0);
-       if (pinned_mem == MAP_FAILED) {
+       if (td->pinned_mem == MAP_FAILED) {
                perror("malloc locked mem");
-               pinned_mem = NULL;
+               td->pinned_mem = NULL;
                return 1;
        }
-       if (mlock(pinned_mem, mlock_size) < 0) {
+       if (mlock(td->pinned_mem, td->o.lockmem) < 0) {
                perror("mlock");
-               munmap(pinned_mem, mlock_size);
-               pinned_mem = NULL;
+               munmap(td->pinned_mem, td->o.lockmem);
+               td->pinned_mem = NULL;
                return 1;
        }