* [PATCH v2 0/4] cgroup: Support cgroup-v2 weight and BFQ weight
@ 2020-08-31 9:21 Andreas Herrmann
2020-08-31 9:21 ` [PATCH v2 1/4] cgroup: Fix handling when cgroup blkio and cgroup-v2 are mounted Andreas Herrmann
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Andreas Herrmann @ 2020-08-31 9:21 UTC (permalink / raw)
To: Jens Axboe; +Cc: fio, Andreas Herrmann
These are changes to support weight with cgroup-v2, and also BFQ's
weight attribute. In recent kernels with cgroup v1 only
blkio.bfq.weight is available to set weight.
Andreas Herrmann (4):
cgroup: Fix handling when cgroup blkio and cgroup-v2 are mounted
cgroup: Allow to use weights with cgroup-v2
thread_options: Introduce cgroup_use_bfq
cgroup: Support BFQ's weight attributes
HOWTO | 6 +++
cconv.c | 2 +
cgroup.c | 110 ++++++++++++++++++++++++++++++++++++-----------
fio.1 | 5 +++
options.c | 11 +++++
server.h | 2 +-
thread_options.h | 7 ++-
7 files changed, 116 insertions(+), 27 deletions(-)
--
2.28.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/4] cgroup: Fix handling when cgroup blkio and cgroup-v2 are mounted
2020-08-31 9:21 [PATCH v2 0/4] cgroup: Support cgroup-v2 weight and BFQ weight Andreas Herrmann
@ 2020-08-31 9:21 ` Andreas Herrmann
2020-08-31 9:21 ` [PATCH v2 2/4] cgroup: Allow to use weights with cgroup-v2 Andreas Herrmann
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Andreas Herrmann @ 2020-08-31 9:21 UTC (permalink / raw)
To: Jens Axboe; +Cc: fio, Andreas Herrmann
On systems that have a mixed setup of cgroup and cgroup-v2, blkio
controller might be active. I think in this case there is no point in
using cgroup-v2. One needs to boot with cgroup_no_v1=blkio to be able
to use cgroup-v2 IO controller.
Signed-off-by: Andreas Herrmann <aherrmann@suse.com>
---
cgroup.c | 58 ++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 40 insertions(+), 18 deletions(-)
diff --git a/cgroup.c b/cgroup.c
index 77e31a4d..fc31d4cd 100644
--- a/cgroup.c
+++ b/cgroup.c
@@ -20,11 +20,10 @@ struct cgroup_member {
static struct cgroup_mnt *find_cgroup_mnt(struct thread_data *td)
{
- struct cgroup_mnt *cgroup_mnt = NULL;
+ struct cgroup_mnt *cgroup_mnt, *cg1_mnt = NULL, *cg2_mnt = NULL;
struct mntent *mnt, dummy;
char buf[256] = {0};
FILE *f;
- bool cgroup2 = false;
f = setmntent("/proc/mounts", "r");
if (!f) {
@@ -34,27 +33,50 @@ static struct cgroup_mnt *find_cgroup_mnt(struct thread_data *td)
while ((mnt = getmntent_r(f, &dummy, buf, sizeof(buf))) != NULL) {
if (!strcmp(mnt->mnt_type, "cgroup") &&
- strstr(mnt->mnt_opts, "blkio"))
- break;
- if (!strcmp(mnt->mnt_type, "cgroup2")) {
- cgroup2 = true;
+ strstr(mnt->mnt_opts, "blkio")) {
+ cg1_mnt = smalloc(sizeof(*cg1_mnt));
+ if (cg1_mnt) {
+ cg1_mnt->path = smalloc_strdup(mnt->mnt_dir);
+ if (!cg1_mnt->path) {
+ sfree(cg1_mnt);
+ cg1_mnt = NULL;
+ log_err("fio: could not allocate memory\n");
+ }
+ }
+ /*
+ * blkio controller has precedence
+ */
break;
+ } if (!strcmp(mnt->mnt_type, "cgroup2")) {
+ if (cg2_mnt)
+ continue;
+ cg2_mnt = smalloc(sizeof(*cg2_mnt));
+ if (cg2_mnt) {
+ cg2_mnt->path = smalloc_strdup(mnt->mnt_dir);
+ if (!cg2_mnt->path) {
+ sfree(cg2_mnt);
+ cg2_mnt = NULL;
+ log_err("fio: could not allocate memory\n");
+ } else
+ cg2_mnt->cgroup2 = true;
+ }
+ /*
+ * Check all mount points, there can be a mix
+ * of cgroup-v1 and cgroup-v2
+ */
+ continue;
}
}
- if (mnt) {
- cgroup_mnt = smalloc(sizeof(*cgroup_mnt));
- if (cgroup_mnt) {
- cgroup_mnt->path = smalloc_strdup(mnt->mnt_dir);
- if (!cgroup_mnt->path) {
- sfree(cgroup_mnt);
- log_err("fio: could not allocate memory\n");
- } else {
- cgroup_mnt->cgroup2 = cgroup2;
- }
- }
+ cgroup_mnt = NULL;
+ if (cg1_mnt) {
+ cgroup_mnt = cg1_mnt;
+ if (cg2_mnt)
+ sfree(cg2_mnt);
+ } else if (cg2_mnt) {
+ cgroup_mnt = cg2_mnt;
} else {
- log_err("fio: cgroup blkio does not appear to be mounted\n");
+ log_err("fio: cgroup blkio or cgroup2 do not appear to be mounted\n");
}
endmntent(f);
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/4] cgroup: Allow to use weights with cgroup-v2
2020-08-31 9:21 [PATCH v2 0/4] cgroup: Support cgroup-v2 weight and BFQ weight Andreas Herrmann
2020-08-31 9:21 ` [PATCH v2 1/4] cgroup: Fix handling when cgroup blkio and cgroup-v2 are mounted Andreas Herrmann
@ 2020-08-31 9:21 ` Andreas Herrmann
2020-08-31 9:21 ` [PATCH v2 3/4] thread_options: Introduce cgroup_use_bfq Andreas Herrmann
2020-08-31 9:21 ` [PATCH v2 4/4] cgroup: Support BFQ's weight attributes Andreas Herrmann
3 siblings, 0 replies; 5+ messages in thread
From: Andreas Herrmann @ 2020-08-31 9:21 UTC (permalink / raw)
To: Jens Axboe; +Cc: fio, Andreas Herrmann
Signed-off-by: Andreas Herrmann <aherrmann@suse.com>
---
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/4] thread_options: Introduce cgroup_use_bfq
2020-08-31 9:21 [PATCH v2 0/4] cgroup: Support cgroup-v2 weight and BFQ weight Andreas Herrmann
2020-08-31 9:21 ` [PATCH v2 1/4] cgroup: Fix handling when cgroup blkio and cgroup-v2 are mounted Andreas Herrmann
2020-08-31 9:21 ` [PATCH v2 2/4] cgroup: Allow to use weights with cgroup-v2 Andreas Herrmann
@ 2020-08-31 9:21 ` Andreas Herrmann
2020-08-31 9:21 ` [PATCH v2 4/4] cgroup: Support BFQ's weight attributes Andreas Herrmann
3 siblings, 0 replies; 5+ messages in thread
From: Andreas Herrmann @ 2020-08-31 9:21 UTC (permalink / raw)
To: Jens Axboe; +Cc: fio, Andreas Herrmann
Signed-off-by: Andreas Herrmann <aherrmann@suse.com>
---
HOWTO | 6 ++++++
cconv.c | 2 ++
fio.1 | 5 +++++
options.c | 11 +++++++++++
server.h | 2 +-
thread_options.h | 7 +++++--
6 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/HOWTO b/HOWTO
index e0403b08..4a16534f 100644
--- a/HOWTO
+++ b/HOWTO
@@ -2846,6 +2846,12 @@ Threads, processes and job synchronization
job completion, set ``cgroup_nodelete=1``. This can be useful if one wants
to inspect various cgroup files after job completion. Default: false.
+.. option:: cgroup_use_bfq=bool
+
+ Normally fio will use generic sysfs attributes to set cgroup_weight.
+ To use attributes specific to BFQ IO scheduler set ``cgroup_use_bfq=1``.
+ Default: false.
+
.. option:: flow_id=int
The ID of the flow. If not specified, it defaults to being a global
diff --git a/cconv.c b/cconv.c
index 4b0c3490..3f99e8d7 100644
--- a/cconv.c
+++ b/cconv.c
@@ -278,6 +278,7 @@ void convert_thread_options_to_cpu(struct thread_options *o,
o->continue_on_error = le32_to_cpu(top->continue_on_error);
o->cgroup_weight = le32_to_cpu(top->cgroup_weight);
o->cgroup_nodelete = le32_to_cpu(top->cgroup_nodelete);
+ o->cgroup_use_bfq = le32_to_cpu(top->cgroup_use_bfq);
o->uid = le32_to_cpu(top->uid);
o->gid = le32_to_cpu(top->gid);
o->flow_id = __le32_to_cpu(top->flow_id);
@@ -478,6 +479,7 @@ void convert_thread_options_to_net(struct thread_options_pack *top,
top->continue_on_error = cpu_to_le32(o->continue_on_error);
top->cgroup_weight = cpu_to_le32(o->cgroup_weight);
top->cgroup_nodelete = cpu_to_le32(o->cgroup_nodelete);
+ top->cgroup_use_bfq = cpu_to_le32(o->cgroup_use_bfq);
top->uid = cpu_to_le32(o->uid);
top->gid = cpu_to_le32(o->gid);
top->flow_id = __cpu_to_le32(o->flow_id);
diff --git a/fio.1 b/fio.1
index 1c90e4a5..a0896235 100644
--- a/fio.1
+++ b/fio.1
@@ -2544,6 +2544,11 @@ completion. To override this behavior and to leave cgroups around after the
job completion, set `cgroup_nodelete=1'. This can be useful if one wants
to inspect various cgroup files after job completion. Default: false.
.TP
+.BI cgroup_use_bfq \fR=\fPbool
+Normally fio will use generic sysfs attributes to set cgroup_weight.
+To use attributes specific to BFQ IO scheduler set ``cgroup_use_bfq=1``.
+Default: false.
+.TP
.BI flow_id \fR=\fPint
The ID of the flow. If not specified, it defaults to being a global
flow. See \fBflow\fR.
diff --git a/options.c b/options.c
index 251ad2c1..c84e911a 100644
--- a/options.c
+++ b/options.c
@@ -4609,6 +4609,17 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
.category = FIO_OPT_C_GENERAL,
.group = FIO_OPT_G_CGROUP,
},
+ {
+ .name = "cgroup_use_bfq",
+ .lname = "Cgroup use-bfq",
+ .type = FIO_OPT_BOOL,
+ .off1 = offsetof(struct thread_options, cgroup_use_bfq),
+ .help = "Use cgroup sysfs attributes specific to BFQ",
+ .def = "0",
+ .parent = "cgroup",
+ .category = FIO_OPT_C_GENERAL,
+ .group = FIO_OPT_G_CGROUP,
+ },
{
.name = "uid",
.lname = "User ID",
diff --git a/server.h b/server.h
index efa70e7c..3cd60096 100644
--- a/server.h
+++ b/server.h
@@ -48,7 +48,7 @@ struct fio_net_cmd_reply {
};
enum {
- FIO_SERVER_VER = 84,
+ FIO_SERVER_VER = 85,
FIO_SERVER_MAX_FRAGMENT_PDU = 1024,
FIO_SERVER_MAX_CMD_MB = 2048,
diff --git a/thread_options.h b/thread_options.h
index 14f1cbe9..c48ac19e 100644
--- a/thread_options.h
+++ b/thread_options.h
@@ -302,11 +302,12 @@ struct thread_options {
char *profile;
/*
- * blkio cgroup support
+ * (blk)io cgroup support
*/
char *cgroup;
unsigned int cgroup_weight;
unsigned int cgroup_nodelete;
+ unsigned int cgroup_use_bfq;
unsigned int uid;
unsigned int gid;
@@ -593,11 +594,13 @@ struct thread_options_pack {
uint8_t profile[FIO_TOP_STR_MAX];
/*
- * blkio cgroup support
+ * (blk)io cgroup support
*/
uint8_t cgroup[FIO_TOP_STR_MAX];
uint32_t cgroup_weight;
uint32_t cgroup_nodelete;
+ uint32_t cgroup_use_bfq;
+ uint32_t pad3;
uint32_t uid;
uint32_t gid;
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 4/4] cgroup: Support BFQ's weight attributes
2020-08-31 9:21 [PATCH v2 0/4] cgroup: Support cgroup-v2 weight and BFQ weight Andreas Herrmann
` (2 preceding siblings ...)
2020-08-31 9:21 ` [PATCH v2 3/4] thread_options: Introduce cgroup_use_bfq Andreas Herrmann
@ 2020-08-31 9:21 ` Andreas Herrmann
3 siblings, 0 replies; 5+ messages in thread
From: Andreas Herrmann @ 2020-08-31 9:21 UTC (permalink / raw)
To: Jens Axboe; +Cc: fio, Andreas Herrmann
Signed-off-by: Andreas Herrmann <aherrmann@suse.com>
---
cgroup.c | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/cgroup.c b/cgroup.c
index c6369f54..903c569e 100644
--- a/cgroup.c
+++ b/cgroup.c
@@ -236,15 +236,29 @@ int cgroup_setup(struct thread_data *td, struct flist_head *clist, struct cgroup
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;
+ if (td->o.cgroup_use_bfq) {
+ if (write_int_to_file(td, root, "io.bfq.weight",
+ td->o.cgroup_weight,
+ "cgroup open io.bfq.weight"))
+ goto err;
+ } else {
+ 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 (td->o.cgroup_use_bfq) {
+ if (write_int_to_file(td, root, "blkio.bfq.weight",
+ td->o.cgroup_weight,
+ "cgroup open blkio.bfq.weight"))
+ goto err;
+ } else {
+ if (write_int_to_file(td, root, "blkio.weight",
+ td->o.cgroup_weight,
+ "cgroup open blkio.weight"))
+ goto err;
+ }
}
}
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-08-31 9:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-31 9:21 [PATCH v2 0/4] cgroup: Support cgroup-v2 weight and BFQ weight Andreas Herrmann
2020-08-31 9:21 ` [PATCH v2 1/4] cgroup: Fix handling when cgroup blkio and cgroup-v2 are mounted Andreas Herrmann
2020-08-31 9:21 ` [PATCH v2 2/4] cgroup: Allow to use weights with cgroup-v2 Andreas Herrmann
2020-08-31 9:21 ` [PATCH v2 3/4] thread_options: Introduce cgroup_use_bfq Andreas Herrmann
2020-08-31 9:21 ` [PATCH v2 4/4] cgroup: Support BFQ's weight attributes Andreas Herrmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).