Add support for blkio cgroups on Linux
[fio.git] / fio.c
diff --git a/fio.c b/fio.c
index debcac5eea9edeb55eea6ff0488e7389f8a5de14..4bbab5af9a12e9c0d00fa559bdddb94107b42f77 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -39,6 +39,7 @@
 #include "smalloc.h"
 #include "verify.h"
 #include "diskutil.h"
+#include "cgroup.h"
 
 unsigned long page_mask;
 unsigned long page_size;
@@ -536,7 +537,8 @@ sync_done:
                 */
                full = queue_full(td) || ret == FIO_Q_BUSY;
                if (full || !td->o.iodepth_batch_complete) {
-                       min_events = td->o.iodepth_batch_complete;
+                       min_events = min(td->o.iodepth_batch_complete,
+                                        td->cur_depth);
                        if (full && !min_events)
                                min_events = 1;
 
@@ -688,7 +690,8 @@ sync_done:
                 */
                full = queue_full(td) || ret == FIO_Q_BUSY;
                if (full || !td->o.iodepth_batch_complete) {
-                       min_evts = td->o.iodepth_batch_complete;
+                       min_evts = min(td->o.iodepth_batch_complete,
+                                       td->cur_depth);
                        if (full && !min_evts)
                                min_evts = 1;
 
@@ -1073,6 +1076,9 @@ static void *thread_main(void *data)
                }
        }
 
+       if (td->o.cgroup_weight && cgroup_setup(td))
+               goto err;
+
        if (nice(td->o.nice) == -1) {
                td_verror(td, errno, "nice");
                goto err;
@@ -1202,6 +1208,7 @@ err:
        close_and_free_files(td);
        close_ioengine(td);
        cleanup_io_u(td);
+       cgroup_shutdown(td);
 
        if (td->o.cpumask_set) {
                int ret = fio_cpuset_exit(&td->o.cpumask);