Move cgroup list to proper shared storage
authorJens Axboe <jens.axboe@oracle.com>
Fri, 4 Dec 2009 18:54:18 +0000 (19:54 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Fri, 4 Dec 2009 18:54:18 +0000 (19:54 +0100)
Otherwise we have per-job lists, and that doesn't help very much
with cleaning up.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
cgroup.c
cgroup.h
fio.c

index 417c50be1088cc77bf531febfb29bbe1eeb8ddb2..6810ede2060bff74869404ebd265498aeac0f4fe 100644 (file)
--- a/cgroup.c
+++ b/cgroup.c
@@ -8,7 +8,6 @@
 #include "cgroup.h"
 #include "smalloc.h"
 
-static struct flist_head *cgroup_list;
 static struct fio_mutex *lock;
 
 struct cgroup_member {
@@ -16,7 +15,7 @@ struct cgroup_member {
        char *root;
 };
 
-static void add_cgroup(const char *name)
+static void add_cgroup(const char *name, struct flist_head *clist)
 {
        struct cgroup_member *cm;
 
@@ -25,26 +24,18 @@ static void add_cgroup(const char *name)
        cm->root = smalloc_strdup(name);
 
        fio_mutex_down(lock);
-
-       if (!cgroup_list) {
-               cgroup_list = smalloc(sizeof(struct flist_head));
-               INIT_FLIST_HEAD(cgroup_list);
-       }
-
-       flist_add_tail(&cm->list, cgroup_list);
+       flist_add_tail(&cm->list, clist);
        fio_mutex_up(lock);
 }
 
-void cgroup_kill(void)
+void cgroup_kill(struct flist_head *clist)
 {
        struct flist_head *n, *tmp;
        struct cgroup_member *cm;
 
        fio_mutex_down(lock);
-       if (!cgroup_list)
-               goto out;
 
-       flist_for_each_safe(n, tmp, cgroup_list) {
+       flist_for_each_safe(n, tmp, clist) {
                cm = flist_entry(n, struct cgroup_member, list);
                rmdir(cm->root);
                flist_del(&cm->list);
@@ -52,9 +43,6 @@ void cgroup_kill(void)
                sfree(cm);
        }
 
-       sfree(cgroup_list);
-       cgroup_list = NULL;
-out:
        fio_mutex_up(lock);
 }
 
@@ -97,7 +85,6 @@ static int cgroup_write_pid(struct thread_data *td, const char *root)
        fprintf(f, "%d", td->pid);
        fclose(f);
        return 0;
-
 }
 
 /*
@@ -122,7 +109,7 @@ static int cgroup_del_pid(struct thread_data *td)
        return cgroup_write_pid(td, td->o.cgroup_root);
 }
 
-int cgroup_setup(struct thread_data *td)
+int cgroup_setup(struct thread_data *td, struct flist_head *clist)
 {
        char *root, tmp[256];
        FILE *f;
@@ -145,7 +132,7 @@ int cgroup_setup(struct thread_data *td)
                        goto err;
                }
        } else
-               add_cgroup(root);
+               add_cgroup(root, clist);
 
        if (td->o.cgroup_weight) {
                sprintf(tmp, "%s/blkio.weight", root);
@@ -180,7 +167,6 @@ void cgroup_shutdown(struct thread_data *td)
        cgroup_del_pid(td);
 }
 
-
 static void fio_init cgroup_init(void)
 {
        lock = fio_mutex_init(1);
index 1c67ba80ab36ee1e67f9b454e3d9ed8d62875e53..b246ef8607d044f3f15e3a51ac9f8be7b6eefde3 100644 (file)
--- a/cgroup.h
+++ b/cgroup.h
@@ -3,14 +3,14 @@
 
 #ifdef FIO_HAVE_CGROUPS
 
-int cgroup_setup(struct thread_data *td);
+int cgroup_setup(struct thread_data *td, struct flist_head *list);
 void cgroup_shutdown(struct thread_data *td);
 
-void cgroup_kill(void);
+void cgroup_kill(struct flist_head *list);
 
 #else
 
-static inline int cgroup_setup(struct thread_data *td)
+static inline int cgroup_setup(struct thread_data *td, struct flist_head *list);
 {
        td_verror(td, EINVAL, "cgroup_setup");
        return 1;
@@ -20,7 +20,7 @@ static inline void cgroup_shutdown(struct thread_data *td)
 {
 }
 
-void cgroup_kill(void)
+void cgroup_kill(struct flist_head *list);
 {
 }
 
diff --git a/fio.c b/fio.c
index a18ca1b63f185fdca01d2ae677cd669fdefb4e58..bcc130bbde49297c2576b0081de0767289515931 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -61,6 +61,7 @@ static volatile int fio_abort;
 static int exit_value;
 static struct itimerval itimer;
 static pthread_t gtod_thread;
+static struct flist_head *cgroup_list;
 
 struct io_log *agg_io_log[2];
 
@@ -1076,7 +1077,7 @@ static void *thread_main(void *data)
                }
        }
 
-       if (td->o.cgroup_weight && cgroup_setup(td))
+       if (td->o.cgroup_weight && cgroup_setup(td, cgroup_list))
                goto err;
 
        if (nice(td->o.nice) == -1) {
@@ -1657,6 +1658,9 @@ int main(int argc, char *argv[])
 
        status_timer_arm();
 
+       cgroup_list = smalloc(sizeof(*cgroup_list));
+       INIT_FLIST_HEAD(cgroup_list);
+
        run_threads();
 
        if (!fio_abort) {
@@ -1668,7 +1672,8 @@ int main(int argc, char *argv[])
                }
        }
 
-       cgroup_kill();
+       cgroup_kill(cgroup_list);
+       sfree(cgroup_list);
 
        fio_mutex_remove(startup_mutex);
        fio_mutex_remove(writeout_mutex);