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>
Wed, 28 Mar 2012 18:50:15 +0000 (20:50 +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>
backend.c
fio.h
init.c
memory.c
options.c
thread_options.h

index 4c784e866a9cbbd91810660b11c3da82a38bda63..ad9231330547dc39278dd40d1ed94c37d0e2455e 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -1029,6 +1029,9 @@ static void *thread_main(void *data)
                goto err;
        }
 
+       if (fio_pin_memory(td))
+               goto err;
+
        /*
         * May alter parameters that init_io_u() will use, so we need to
         * do this first.
@@ -1144,6 +1147,8 @@ static void *thread_main(void *data)
        td->ts.io_bytes[0] = td->io_bytes[0];
        td->ts.io_bytes[1] = td->io_bytes[1];
 
+       fio_unpin_memory(td);
+
        fio_mutex_down(writeout_mutex);
        if (td->bw_log) {
                if (td->o.bw_log_file) {
@@ -1354,9 +1359,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;
 
@@ -1579,7 +1581,6 @@ static void run_threads(void)
        }
 
        update_io_ticks();
-       fio_unpin_memory();
 }
 
 static void *disk_thread_main(void *data)
diff --git a/fio.h b/fio.h
index 0aa24a5a7db3626aad690ea48785e26841cfc81b..e37e5ae1e8e38e55f7508afe8ca115a49ac6a15e 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -275,6 +275,8 @@ struct thread_data {
         */
        struct prof_io_ops prof_io_ops;
        void *prof_data;
+
+       void *pinned_mem;
 };
 
 /*
@@ -313,7 +315,6 @@ extern int shm_id;
 extern int groupid;
 extern int terse_output;
 extern int temp_stall_ts;
-extern unsigned long long mlock_size;
 extern unsigned long page_mask, page_size;
 extern int read_only;
 extern int eta_print;
@@ -440,8 +441,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 *);
 extern void free_threads_shm(void);
diff --git a/init.c b/init.c
index cf105a358824f0a7c0061108583ea48b5ae23b00..aa76733d9043d6038ee05c7ef81729503ee58096 100644 (file)
--- a/init.c
+++ b/init.c
@@ -40,7 +40,6 @@ struct thread_data *threads = NULL;
 int exitall_on_terminate = 0;
 int terse_output = 0;
 int eta_print;
-unsigned long long mlock_size = 0;
 FILE *f_out = NULL;
 FILE *f_err = NULL;
 char **job_sections = NULL;
index 0135abb1b0eb42d574eed3fe646a69908de12983..f97749bc72c657f7b0d9f3739853dd7039797280 100644 (file)
--- a/memory.c
+++ b/memory.c
 
 #include "fio.h"
 
-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;
        }
 
index 937a76e17cea9a518985a0d9973f1f6cdc062cf3..5b668e5d1226a57878b0cfdad739be57738e6553 100644 (file)
--- a/options.c
+++ b/options.c
@@ -251,12 +251,6 @@ static int fio_clock_source_cb(void *data, const char *str)
        return 0;
 }
 
-static int str_lockmem_cb(void fio_unused *data, unsigned long long *val)
-{
-       mlock_size = *val;
-       return 0;
-}
-
 static int str_rwmix_read_cb(void *data, unsigned long long *val)
 {
        struct thread_data *td = data;
@@ -2124,7 +2118,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
                .name   = "lockmem",
                .lname  = "Lock memory",
                .type   = FIO_OPT_STR_VAL,
-               .cb     = str_lockmem_cb,
+               .off1   = td_var_offset(lockmem),
                .help   = "Lock down this amount of memory",
                .def    = "0",
                .interval = 1024 * 1024,
index e9c67ee96d012e3bcd591c1f68dab25e98beddea..5eb4a20cad361ee8772f1a09a7ae940204b14162 100644 (file)
@@ -126,6 +126,7 @@ struct thread_options {
        unsigned long long zone_range;
        unsigned long long zone_size;
        unsigned long long zone_skip;
+       unsigned long long lockmem;
        enum fio_memtype mem_type;
        unsigned int mem_align;