All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Jens Axboe <axboe@kernel.dk>
Cc: <linux-block@vger.kernel.org>,
	Damien Le Moal <damien.lemoal@opensource.wdc.com>,
	Bart Van Assche <bvanassche@acm.org>,
	Niklas Cassel <Niklas.Cassel@wdc.com>, Jan Kara <jack@suse.cz>
Subject: [PATCH 5/9] block: Fix handling of tasks without ioprio in ioprio_get(2)
Date: Thu, 23 Jun 2022 09:48:30 +0200	[thread overview]
Message-ID: <20220623074840.5960-5-jack@suse.cz> (raw)
In-Reply-To: <20220623074450.30550-1-jack@suse.cz>

ioprio_get(2) can be asked to return the best IO priority from several
tasks (IOPRIO_WHO_PGRP, IOPRIO_WHO_USER). Currently the call treats
tasks without set IO priority as having priority
IOPRIO_CLASS_BE/IOPRIO_BE_NORM however this does not really reflect the
IO priority the task will get (which depends on task's nice value).

Fix the code to use the real IO priority task's IO will use. We have to
modify code for ioprio_get(IOPRIO_WHO_PROCESS) to keep returning
IOPRIO_CLASS_NONE priority for tasks without set IO priority as a
special case to maintain userspace visible API.

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Tested-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 block/ioprio.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/block/ioprio.c b/block/ioprio.c
index 8c46f672a0ba..32a456b45804 100644
--- a/block/ioprio.c
+++ b/block/ioprio.c
@@ -171,10 +171,31 @@ static int get_task_ioprio(struct task_struct *p)
 	ret = security_task_getioprio(p);
 	if (ret)
 		goto out;
-	ret = IOPRIO_DEFAULT;
+	task_lock(p);
+	ret = __get_task_ioprio(p);
+	task_unlock(p);
+out:
+	return ret;
+}
+
+/*
+ * Return raw IO priority value as set by userspace. We use this for
+ * ioprio_get(pid, IOPRIO_WHO_PROCESS) so that we keep historical behavior and
+ * also so that userspace can distinguish unset IO priority (which just gets
+ * overriden based on task's nice value) from IO priority set to some value.
+ */
+static int get_task_raw_ioprio(struct task_struct *p)
+{
+	int ret;
+
+	ret = security_task_getioprio(p);
+	if (ret)
+		goto out;
 	task_lock(p);
 	if (p->io_context)
 		ret = p->io_context->ioprio;
+	else
+		ret = IOPRIO_DEFAULT;
 	task_unlock(p);
 out:
 	return ret;
@@ -182,11 +203,6 @@ static int get_task_ioprio(struct task_struct *p)
 
 static int ioprio_best(unsigned short aprio, unsigned short bprio)
 {
-	if (!ioprio_valid(aprio))
-		aprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM);
-	if (!ioprio_valid(bprio))
-		bprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM);
-
 	return min(aprio, bprio);
 }
 
@@ -207,7 +223,7 @@ SYSCALL_DEFINE2(ioprio_get, int, which, int, who)
 			else
 				p = find_task_by_vpid(who);
 			if (p)
-				ret = get_task_ioprio(p);
+				ret = get_task_raw_ioprio(p);
 			break;
 		case IOPRIO_WHO_PGRP:
 			if (!who)
-- 
2.35.3


  parent reply	other threads:[~2022-06-23  7:48 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-23  7:48 [PATCH 0/9 v5] block: Fix IO priority mess Jan Kara
2022-06-23  7:48 ` [PATCH 1/9] block: fix default IO priority handling again Jan Kara
2022-06-23 13:57   ` Christoph Hellwig
2022-06-23 14:23   ` Jens Axboe
2022-06-23  7:48 ` [PATCH 2/9] block: Return effective IO priority from get_current_ioprio() Jan Kara
2022-06-23 13:57   ` Christoph Hellwig
2022-06-23  7:48 ` [PATCH 3/9] block: Generalize get_current_ioprio() for any task Jan Kara
2022-06-23 13:59   ` Christoph Hellwig
2022-06-23  7:48 ` [PATCH 4/9] block: Make ioprio_best() static Jan Kara
2022-06-23 13:58   ` Christoph Hellwig
2022-06-23  7:48 ` Jan Kara [this message]
2022-06-23  7:48 ` [PATCH 6/9] blk-ioprio: Remove unneeded field Jan Kara
2022-06-23 14:00   ` Christoph Hellwig
2022-06-23  7:48 ` [PATCH 7/9] blk-ioprio: Convert from rqos policy to direct call Jan Kara
2022-06-23 14:01   ` Christoph Hellwig
2022-06-23  7:48 ` [PATCH 8/9] block: Initialize bio priority earlier Jan Kara
2022-06-23 14:01   ` Christoph Hellwig
2022-06-23  7:48 ` [PATCH 9/9] block: Always initialize bio IO priority on submit Jan Kara
2022-06-23 14:01   ` Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2022-06-21 10:24 [PATCH 0/9 v4] block: Fix IO priority mess Jan Kara
2022-06-21 10:24 ` [PATCH 5/9] block: Fix handling of tasks without ioprio in ioprio_get(2) Jan Kara
2022-06-21 13:02   ` 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=20220623074840.5960-5-jack@suse.cz \
    --to=jack@suse.cz \
    --cc=Niklas.Cassel@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=damien.lemoal@opensource.wdc.com \
    --cc=linux-block@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.