Skip to contentSkip to conversation

fio: work with cgroup2 as well

PATCH In review Josef Bacik 2 participants 4 messages Jun 29, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 fio: work with cgroup2 as well

The current code only works with cgroupv1, but as long as you don't want to set blkio.weight or anything we can use the 'cgroup=' setting with cgroupv2 easily with cgroupv1, we just need to write the thread pids to a different file for cgroup2.

---
 backend.c |  5 ++---
 cgroup.c  | 64 ++++++++++++++++++++++++++++++++++++++++++++-------------------
 cgroup.h  | 13 ++++++++++---
 3 files changed, 57 insertions(+), 25 deletions(-)
backend.c +2 -3
index c52eba58fa10..a7e91843a0be 100644
@@ -50,7 +50,7 @@
 
 static struct fio_sem *startup_sem;
 static struct flist_head *cgroup_list;
-static char *cgroup_mnt;
+static struct cgroup_mnt *cgroup_mnt;
 static int exit_value;
 static volatile int fio_abort;
 static unsigned int nr_process = 0;
@@ -1886,7 +1886,7 @@ err:
 	close_and_free_files(td);
 	cleanup_io_u(td);
 	close_ioengine(td);
-	cgroup_shutdown(td, &cgroup_mnt);
+	cgroup_shutdown(td, cgroup_mnt);
 	verify_free_state(td);
 
 	if (td->zone_state_index) {
@@ -2508,7 +2508,6 @@ int fio_backend(struct sk_out *sk_out)
 		cgroup_kill(cgroup_list);
 		sfree(cgroup_list);
 	}
-	sfree(cgroup_mnt);
 
 	fio_sem_remove(startup_sem);
 	stat_exit();
cgroup.c +45 -19

135 lines not on this page · raw message

cgroup.h +10 -3
index 0bbe25a2cb79..e5b6addcf190 100644
@@ -3,13 +3,20 @@
 
 #ifdef FIO_HAVE_CGROUPS
 
-int cgroup_setup(struct thread_data *, struct flist_head *, char **);
-void cgroup_shutdown(struct thread_data *, char **);
+struct cgroup_mnt {
+	char *path;
+	bool cgroup2;
+};
+
+int cgroup_setup(struct thread_data *, struct flist_head *, struct cgroup_mnt **);
+void cgroup_shutdown(struct thread_data *, struct cgroup_mnt *);
 
 void cgroup_kill(struct flist_head *list);
 
 #else
 
+struct cgroup_mnt;
+
 static inline int cgroup_setup(struct thread_data *td, struct flist_head *list,
 			       char **mnt)
 {
@@ -17,7 +24,7 @@ static inline int cgroup_setup(struct thread_data *td, struct flist_head *list,
 	return 1;
 }
 
-static inline void cgroup_shutdown(struct thread_data *td, char **mnt)
+static inline void cgroup_shutdown(struct thread_data *td, struct cgroup_mnt **mnt)
 {
 }
 
Signature · 1 line
2.14.3
#1 lore raw

PATCH 2/2 fio: add total_run_time to the thread json output

I discovered that the 'elapsed' value of each job is the overall time the whole fio run took, not the per-job elapsed time, despite it being in the per-job section of the json output. Rather than break everybody by fixing this, just add a 'total_run_time' value to the job section and include the time the thread ran in milliseconds. This is handy for jobs that want to compare runtime of two threads in different cgroups.

---
 stat.c | 1 +
 1 file changed, 1 insertion(+)
stat.c +1 -0
index d5240d96a25b..76553489d068 100644
@@ -1288,6 +1288,7 @@ static struct json_object *show_thread_status_json(struct thread_stat *ts,
 		usr_cpu = 0;
 		sys_cpu = 0;
 	}
+	json_object_add_value_int(root, "total_run_time", ts->total_run_time);
 	json_object_add_value_float(root, "usr_cpu", usr_cpu);
 	json_object_add_value_float(root, "sys_cpu", sys_cpu);
 	json_object_add_value_int(root, "ctx", ts->ctx);
Signature · 1 line
2.14.3
#2 lore raw

Re: [PATCH 2/2] fio: add total_run_time to the thread json output

Quoted 6 lines · Josef Bacik

I discovered that the 'elapsed' value of each job is the overall time the whole fio run took, not the per-job elapsed time, despite it being in the per-job section of the json output. Rather than break everybody by fixing this, just add a 'total_run_time' value to the job section and include the time the thread ran in milliseconds. This is handy for jobs that want to compare runtime of two threads in different cgroups.

How about 'job_runtime' instead, total_run_time sounds like higher scope than 'elapsed'.

Signature · 1 line
Jens Axboe
#3 lore raw
In reply to Josef Bacik
Quoted 4 lines · Josef Bacik

The current code only works with cgroupv1, but as long as you don't want to set blkio.weight or anything we can use the 'cgroup=' setting with cgroupv2 easily with cgroupv1, we just need to write the thread pids to a different file for cgroup2.

Thanks Josef - applied, but with the below fixup on top.

cgroup.h +2 -2
index e5b6addcf190..5afac7f7551f 100644
@@ -18,13 +18,13 @@ void cgroup_kill(struct flist_head *list);
 struct cgroup_mnt;
 
 static inline int cgroup_setup(struct thread_data *td, struct flist_head *list,
-			       char **mnt)
+			       struct cgroup_mount **mnt)
 {
 	td_verror(td, EINVAL, "cgroup_setup");
 	return 1;
 }
 
-static inline void cgroup_shutdown(struct thread_data *td, struct cgroup_mnt **mnt)
+static inline void cgroup_shutdown(struct thread_data *td, struct cgroup_mnt *mnt)
 {
 }
 
Signature · 1 line
Jens Axboe