[PATCH v3 2/4] cgroup: Allow to use weights with cgroup-v2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Andreas Herrmann <aherrmann@xxxxxxxx>
---
 cgroup.c | 38 ++++++++++++++++++++++++++++++++------
 1 file changed, 32 insertions(+), 6 deletions(-)

diff --git a/cgroup.c b/cgroup.c
index fc31d4cd..c6369f54 100644
--- a/cgroup.c
+++ b/cgroup.c
@@ -165,6 +165,26 @@ static int write_int_to_file(struct thread_data *td, const char *path,
 
 }
 
+static int write_str_to_file(struct thread_data *td, const char *path,
+			     const char *filename, const char *str,
+			     const char *onerr)
+{
+	char tmp[256];
+	FILE *f;
+
+	sprintf(tmp, "%s/%s", path, filename);
+	f = fopen(tmp, "w");
+	if (!f) {
+		td_verror(td, errno, onerr);
+		return 1;
+	}
+
+	fprintf(f, "%s", str);
+	fclose(f);
+	return 0;
+
+}
+
 static int cgroup_write_pid(struct thread_data *td, char *path, bool cgroup2)
 {
 	unsigned int val = td->pid;
@@ -213,13 +233,19 @@ int cgroup_setup(struct thread_data *td, struct flist_head *clist, struct cgroup
 
 	if (td->o.cgroup_weight) {
 		if ((*mnt)->cgroup2) {
-			log_err("fio: cgroup weit doesn't work with cgroup2\n");
-			goto err;
+			if (write_str_to_file(td, (*mnt)->path, "cgroup.subtree_control",
+						"+io", "cgroup open cgroup.subtree_control"))
+				goto err;
+			if (write_int_to_file(td, root, "io.weight",
+						td->o.cgroup_weight,
+						"cgroup open io.weight"))
+				goto err;
+		} else {
+			if (write_int_to_file(td, root, "blkio.weight",
+						td->o.cgroup_weight,
+						"cgroup open blkio.weight"))
+				goto err;
 		}
-		if (write_int_to_file(td, root, "blkio.weight",
-					td->o.cgroup_weight,
-					"cgroup open weight"))
-			goto err;
 	}
 
 	if (!cgroup_write_pid(td, root, (*mnt)->cgroup2)) {
-- 
2.28.0





[Index of Archives]     [Linux Kernel]     [Linux SCSI]     [Linux IDE]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux