All of lore.kernel.org
 help / color / mirror / Atom feed
From: Damien Le Moal <damien.lemoal@wdc.com>
To: fio@vger.kernel.org, Jens Axboe <axboe@kernel.dk>
Cc: Bart Van Assche <bvanassche@acm.org>
Subject: [PATCH 09/11] libaio: relax cdmprio_percentage constraints
Date: Tue,  6 Jul 2021 09:17:41 +0900	[thread overview]
Message-ID: <20210706001743.10818-10-damien.lemoal@wdc.com> (raw)
In-Reply-To: <20210706001743.10818-1-damien.lemoal@wdc.com>

When an AIO is issued without a priority set, Linux kernel will execute
it using the issuing context IO priority set with ioprio_set(). In fio,
a job IO priority is controlled with the prioclass and prio options and
these options cannot be used together with the cmdprio_percentage
option.

Allow a user to have AIO priorities to default to the job defined IO
priority by removing the mutual exclusion between the options
cmdprio_percentage and prioclass/prio.

With the introduction of the aioprioclass option, an AIO priority may be
lower than the job default priority, resulting in reversed clat
statistics showed for high and low priority IOs when fio completes.
Solve this by setting an io_u IO_U_F_PRIORITY flag depending on a
comparison between the aio priority and job default IO priority. The job
default IO priority is added as the ioprio field in struct thread_data
for convenience, avoiding referencing the job options for every IO.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 backend.c        |  1 +
 engines/libaio.c | 28 ++++++++++++++++------------
 fio.h            |  5 +++++
 3 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/backend.c b/backend.c
index 6290e0d6..ff53e8b5 100644
--- a/backend.c
+++ b/backend.c
@@ -1760,6 +1760,7 @@ static void *thread_main(void *data)
 			td_verror(td, errno, "ioprio_set");
 			goto err;
 		}
+		td->ioprio = ioprio_value(o->ioprio_class, o->ioprio);
 	}
 
 	if (o->cgroup && cgroup_setup(td, cgroup_list, &cgroup_mnt))
diff --git a/engines/libaio.c b/engines/libaio.c
index e0f8a3d3..c0cbf97b 100644
--- a/engines/libaio.c
+++ b/engines/libaio.c
@@ -282,13 +282,26 @@ static int fio_libaio_need_prio(struct libaio_options *o, struct io_u *io_u)
 static void fio_libaio_prio_prep(struct thread_data *td, struct io_u *io_u)
 {
 	struct libaio_options *o = td->eo;
-	enum fio_ddir ddir = io_u->ddir;
 	unsigned int p = fio_libaio_need_prio(o, io_u);
+	enum fio_ddir ddir = io_u->ddir;
+	unsigned int aioprio =
+		ioprio_value(o->aioprio_class[ddir], o->aioprio[ddir]);
 
 	if (p && rand_between(&td->prio_state, 0, 99) < p) {
-		io_u->iocb.aio_reqprio =
-			ioprio_value(o->aioprio_class[ddir], o->aioprio[ddir]);
+		io_u->iocb.aio_reqprio = aioprio;
 		io_u->iocb.u.c.flags |= IOCB_FLAG_IOPRIO;
+		if (!td->ioprio || aioprio < td->ioprio) {
+			/*
+			 * The AIO priortity is higher than the default context
+			 * priority.
+			 */
+			io_u->flags |= IO_U_F_PRIORITY;
+		}
+	} else if (td->ioprio && td->ioprio < aioprio) {
+		/*
+		 * The IO will be executed with the default context priority
+		 * and it is higher than the aio priority.
+		 */
 		io_u->flags |= IO_U_F_PRIORITY;
 	}
 }
@@ -605,15 +618,6 @@ static int fio_libaio_init(struct thread_data *td)
 		td_verror(td, EINVAL, "fio_libaio_init");
 		return 1;
 	}
-	if (p &&
-	    (fio_option_is_set(to, ioprio) ||
-	     fio_option_is_set(to, ioprio_class))) {
-		log_err("%s: cmdprio_percentage option and mutually exclusive "
-			"prio or prioclass option is set, exiting\n",
-			to->name);
-		td_verror(td, EINVAL, "fio_libaio_init");
-		return 1;
-	}
 
 	ld->use_aioprio = p || nr_aioprio_bssplits;
 
diff --git a/fio.h b/fio.h
index 83334652..fa7e42dd 100644
--- a/fio.h
+++ b/fio.h
@@ -274,6 +274,11 @@ struct thread_data {
 
 	int shm_id;
 
+	/*
+	 * Job default IO priority set with prioclass and prio options.
+	 */
+	unsigned int ioprio;
+
 	/*
 	 * IO engine hooks, contains everything needed to submit an io_u
 	 * to any of the available IO engines.
-- 
2.31.1



  parent reply	other threads:[~2021-07-06  0:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-06  0:17 [PATCH 00/11] Improve libaio IO priority support Damien Le Moal
2021-07-06  0:17 ` [PATCH 01/11] manpage: fix formatting Damien Le Moal
2021-07-06  0:17 ` [PATCH 02/11] manpage: fix definition of prio and prioclass options Damien Le Moal
2021-07-06  0:17 ` [PATCH 03/11] tools: fiograph: do not overwrite input script file Damien Le Moal
2021-07-06  0:17 ` [PATCH 04/11] os: introduce ioprio_value() helper Damien Le Moal
2021-07-06  0:17 ` [PATCH 05/11] options: make parsing functions available to ioengines Damien Le Moal
2021-07-06  0:17 ` [PATCH 06/11] libaio,io_uring: improve cmdprio_percentage option Damien Le Moal
2021-07-06  0:17 ` [PATCH 07/11] libaio: introduce aioprio and aioprioclass options Damien Le Moal
2021-07-06  0:17 ` [PATCH 08/11] libaio: introduce aioprio_bssplit Damien Le Moal
2021-07-06  0:17 ` Damien Le Moal [this message]
2021-07-06  0:17 ` [PATCH 10/11] fio: Introduce the log_prio option Damien Le Moal
2021-07-06  0:17 ` [PATCH 11/11] examples: add libaio priority use examples Damien Le Moal
2021-07-19  3:24 ` [PATCH 00/11] Improve libaio IO priority support Damien Le Moal
2021-07-19 14:20   ` Jens Axboe
2021-08-02  5:44     ` Damien Le Moal

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=20210706001743.10818-10-damien.lemoal@wdc.com \
    --to=damien.lemoal@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --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.