From: Jens Axboe Date: Fri, 4 Dec 2009 18:54:18 +0000 (+0100) Subject: Move cgroup list to proper shared storage X-Git-Tag: fio-1.36-rc1~2 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=dae5341c3059273242598de2bc27cc9f18c627c1;ds=sidebyside Move cgroup list to proper shared storage Otherwise we have per-job lists, and that doesn't help very much with cleaning up. Signed-off-by: Jens Axboe --- diff --git a/cgroup.c b/cgroup.c index 417c50be..6810ede2 100644 --- 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); diff --git a/cgroup.h b/cgroup.h index 1c67ba80..b246ef86 100644 --- 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 a18ca1b6..bcc130bb 100644 --- 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);