All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Herrmann <aherrmann@suse.com>
To: Jens Axboe <axboe@fb.com>
Cc: fio@vger.kernel.org
Subject: [PATCH 2/3] cgroup: Fix handling when cgroup blkio and cgroup-v2 are mounted
Date: Thu, 27 Aug 2020 14:12:15 +0200	[thread overview]
Message-ID: <20200827121215.GE6041@suselix> (raw)
In-Reply-To: <20200827120722.GC6041@suselix>

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 9ee1b8c8..43513733 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



  parent reply	other threads:[~2020-08-27 12:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-27 12:07 [PATCH 0/3] cgroup: Misc fixes Andreas Herrmann
2020-08-27 12:08 ` [PATCH 1/3] cgroup: Fix typo Andreas Herrmann
2020-08-27 12:12 ` Andreas Herrmann [this message]
2020-08-27 12:15 ` [PATCH 3/3] cgroup: Try to use blkio.bfq.weight if blkio.weight is not available Andreas Herrmann
2020-08-28 17:29   ` Sitsofe Wheeler
2020-08-31  5:54     ` Andreas Herrmann
2020-08-31  7:33 ` [PATCH 0/3] cgroup: Misc fixes Andreas Herrmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200827121215.GE6041@suselix \
    --to=aherrmann@suse.com \
    --cc=axboe@fb.com \
    --cc=fio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.