iolog: run compression work at slightly elevated nice level
authorJens Axboe <axboe@fb.com>
Wed, 9 Jul 2014 07:52:20 +0000 (09:52 +0200)
committerJens Axboe <axboe@fb.com>
Wed, 9 Jul 2014 07:52:20 +0000 (09:52 +0200)
Add support for work items to contain a priority, and use this
directly with nice. Run compression at nice 1, to make it slightly
less important than the actual IO jobs.

Signed-off-by: Jens Axboe <axboe@fb.com>
iolog.c
lib/tp.c
lib/tp.h

diff --git a/iolog.c b/iolog.c
index 3b39f4c6ba6e5f8c919bd7c00d06d3235cb3feb4..79c189b70af83e1e5d452ab08b1bff291222709a 100644 (file)
--- a/iolog.c
+++ b/iolog.c
@@ -1087,6 +1087,7 @@ int iolog_flush(struct io_log *log, int wait)
        } else
                data->work.wait = 0;
 
+       data->work.prio = 1;
        tp_queue_work(tdat, &data->work);
 
        if (wait) {
index 386e31afc3f0d664e5ae68dbddd7ac119064217e..7462f5bfa824cbfc7fff44a50fe76ee8fe0919a9 100644 (file)
--- a/lib/tp.c
+++ b/lib/tp.c
@@ -11,6 +11,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include <pthread.h>
+#include <string.h>
 
 #include "../smalloc.h"
 #include "../log.h"
@@ -21,9 +22,19 @@ static void tp_flush_work(struct flist_head *list)
        struct tp_work *work;
 
        while (!flist_empty(list)) {
+               int prio;
+
                work = flist_entry(list->next, struct tp_work, list);
                flist_del(&work->list);
+
+               prio = work->prio;
+               if (nice(prio) < 0)
+                       log_err("fio: nice %s\n", strerror(errno));
+
                work->fn(work);
+
+               if (nice(prio) < 0)
+                       log_err("fio: nice %s\n", strerror(errno));
        }
 }
 
index 5b07cc6cf1e86041403f8e28f81f6b3d566a4218..9147cc2c9dc7137bb03a48d1706693f4fddcb22d 100644 (file)
--- a/lib/tp.h
+++ b/lib/tp.h
@@ -10,6 +10,7 @@ struct tp_work {
        struct flist_head list;
        tp_work_fn *fn;
        int wait;
+       int prio;
        pthread_cond_t cv;
        pthread_mutex_t lock;
        volatile int done;