Skip to contentSkip to conversation

block: Fix IO priority mess

PATCH Superseded Jan Kara 3 participants 22 messages Jun 21, 2022 – Jun 23, 2022

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Jan Kara

author
#0 lore raw

v4 cover block: Fix IO priority mess

Hello,

This is the fourth revision of my patches fixing IO priority handling in the block layer.

Changes since v3:
* Added Reviewed-by tags from Damien
* Fixed build failure without CONFIG_BLOCK
* Separated refactoring of get_current_ioprio() into a separate patch

Changes since v2:
* added some comments to better explain things
* changed handling of ioprio_get(2)
* a few small tweaks based on Damien's feedback

Original cover letter:
Recently, I've been looking into 10% regression reported by our performance measurement infrastructure in reaim benchmark that was bisected down to 5a9d041ba2f6 ("block: move io_context creation into where it's needed"). This didn't really make much sense and it took me a while to understand this but the culprit is actually in even older commit e70344c05995 ("block: fix default IO priority handling") and 5a9d041ba2f6 just made the breakage visible. Essentially the problem was that after these commits some IO was queued with IO priority class IOPRIO_CLASS_BE while other IO was queued with IOPRIO_CLASS_NONE and as a result they could not be merged together resulting in performance regression. I think what commit e70344c05995 ("block: fix default IO priority handling") did is actually broken not only because of this performance regression but because of other reasons as well (see changelog of patch 3/8 for details). Besides this problem, there are multiple other inconsistencies in the IO priority handling throughout the block stack we have identified when discussing this with Damien Le Moal. So this patch set aims at fixing all these various issues.

Note that there are a few choices I've made I'm not 100% sold on. In particular the conversion of blk-ioprio from rqos is somewhat disputable since it now incurs a cost similar to blk-throttle in the bio submission fast path (need to load bio->bi_blkg->pd[ioprio_policy.plid]). If people think the removed boilerplate code is not worth the cost, I can certainly go via the "additional rqos hook" path.

Honza
Previous versions:

author
#1 lore raw

PATCH v4 1/9 block: fix default IO priority handling again

Commit e70344c05995 ("block: fix default IO priority handling") introduced an inconsistency in get_current_ioprio() that tasks without IO context return IOPRIO_DEFAULT priority while tasks with freshly allocated IO context will return 0 (IOPRIO_CLASS_NONE/0) IO priority. Tasks without IO context used to be rare before 5a9d041ba2f6 ("block:
move io_context creation into where it's needed") but after this commit they became common because now only BFQ IO scheduler setups task's IO context. Similar inconsistency is there for get_task_ioprio() so this inconsistency is now exposed to userspace and userspace will see different IO priority for tasks operating on devices with BFQ compared to devices without BFQ. Furthemore the changes done by commit e70344c05995 change the behavior when no IO priority is set for BFQ IO scheduler which is also documented in ioprio_set(2) manpage:

"If no I/O scheduler has been set for a thread, then by default the I/O priority will follow the CPU nice value (setpriority(2)). In Linux kernels before version 2.6.24, once an I/O priority had been set using ioprio_set(), there was no way to reset the I/O scheduling behavior to the default. Since Linux 2.6.24, specifying ioprio as 0 can be used to reset to the default I/O scheduling behavior."

So make sure we default to IOPRIO_CLASS_NONE as used to be the case before commit e70344c05995. Also cleanup alloc_io_context() to explicitely set this IO priority for the allocated IO context to avoid future surprises. Note that we tweak ioprio_best() to maintain ioprio_get(2) behavior and make this commit easily backportable.

Fixes e70344c05995 ("block: fix default IO priority handling")
---
 block/blk-ioc.c        | 2 ++
 block/ioprio.c         | 4 ++--
 include/linux/ioprio.h | 2 +-
 3 files changed, 5 insertions(+), 3 deletions(-)
block/blk-ioc.c +2 -0
index df9cfe4ca532..63fc02042408 100644
@@ -247,6 +247,8 @@ static struct io_context *alloc_io_context(gfp_t gfp_flags, int node)
 	INIT_HLIST_HEAD(&ioc->icq_list);
 	INIT_WORK(&ioc->release_work, ioc_release_fn);
 #endif
+	ioc->ioprio = IOPRIO_DEFAULT;
+
 	return ioc;
 }
 
block/ioprio.c +2 -2
index 2fe068fcaad5..2a34cbca18ae 100644
@@ -157,9 +157,9 @@ static int get_task_ioprio(struct task_struct *p)
 int ioprio_best(unsigned short aprio, unsigned short bprio)
 {
 	if (!ioprio_valid(aprio))
-		aprio = IOPRIO_DEFAULT;
+		aprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM);
 	if (!ioprio_valid(bprio))
-		bprio = IOPRIO_DEFAULT;
+		bprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM);
 
 	return min(aprio, bprio);
 }
include/linux/ioprio.h +1 -1
index 3f53bc27a19b..3d088a88f832 100644
@@ -11,7 +11,7 @@
 /*
  * Default IO priority.
  */
-#define IOPRIO_DEFAULT	IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM)
+#define IOPRIO_DEFAULT	IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0)
 
 /*
  * Check that a priority value has a valid class.
Signature · 1 line
2.35.3
author
#2 lore raw

PATCH v4 2/9 block: Return effective IO priority from get_current_ioprio()

In reply to Jan Kara

get_current_ioprio() is used to initialize IO priority of various requests. As such it should be returning the effective IO priority of the task (i.e., reflecting the fact that unset IO priority should get set based on task's CPU priority) so that the conversion is concentrated in one place.

---
 include/linux/ioprio.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
include/linux/ioprio.h +9 -2
index 3d088a88f832..61ed6bb4998e 100644
@@ -53,10 +53,17 @@ static inline int task_nice_ioclass(struct task_struct *task)
 static inline int get_current_ioprio(void)
 {
 	struct io_context *ioc = current->io_context;
+	int prio;
 
 	if (ioc)
-		return ioc->ioprio;
-	return IOPRIO_DEFAULT;
+		prio = ioc->ioprio;
+	else
+		prio = IOPRIO_DEFAULT;
+
+	if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE)
+		prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(current),
+					 task_nice_ioprio(current));
+	return prio;
 }
 
 /*
Signature · 1 line
2.35.3
author
#3 lore raw

PATCH v4 3/9 block: Generalize get_current_ioprio() for any task

In reply to Jan Kara

get_current_ioprio() operates only on current task. We will need the same functionality for other tasks as well. Generalize get_current_ioprio() for that and also move the bulk out of the header file because it is large enough.

---
 block/ioprio.c         | 26 ++++++++++++++++++++++++++
 include/linux/ioprio.h | 26 ++++++++++----------------
 2 files changed, 36 insertions(+), 16 deletions(-)
block/ioprio.c +26 -0
index 2a34cbca18ae..c4e3476155a1 100644
@@ -138,6 +138,32 @@ SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio)
 	return ret;
 }
 
+/*
+ * If the task has set an I/O priority, use that. Otherwise, return
+ * the default I/O priority.
+ *
+ * Expected to be called for current task or with task_lock() held to keep
+ * io_context stable.
+ */
+int __get_task_ioprio(struct task_struct *p)
+{
+	struct io_context *ioc = p->io_context;
+	int prio;
+
+	if (p != current)
+		lockdep_assert_held(&p->alloc_lock);
+	if (ioc)
+		prio = ioc->ioprio;
+	else
+		prio = IOPRIO_DEFAULT;
+
+	if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE)
+		prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(p),
+					 task_nice_ioprio(p));
+	return prio;
+}
+EXPORT_SYMBOL_GPL(__get_task_ioprio);
+
 static int get_task_ioprio(struct task_struct *p)
 {
 	int ret;
include/linux/ioprio.h +10 -16
index 61ed6bb4998e..788a8ff57068 100644
@@ -46,24 +46,18 @@ static inline int task_nice_ioclass(struct task_struct *task)
 		return IOPRIO_CLASS_BE;
 }
 
-/*
- * If the calling process has set an I/O priority, use that. Otherwise, return
- * the default I/O priority.
- */
-static inline int get_current_ioprio(void)
+#ifdef CONFIG_BLOCK
+int __get_task_ioprio(struct task_struct *p);
+#else
+static inline int __get_task_ioprio(int ioprio)
 {
-	struct io_context *ioc = current->io_context;
-	int prio;
-
-	if (ioc)
-		prio = ioc->ioprio;
-	else
-		prio = IOPRIO_DEFAULT;
+	return IOPRIO_DEFAULT;
+}
+#endif /* CONFIG_BLOCK */
 
-	if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE)
-		prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(current),
-					 task_nice_ioprio(current));
-	return prio;
+static inline int get_current_ioprio(void)
+{
+	return __get_task_ioprio(current);
 }
 
 /*
Signature · 1 line
2.35.3
author
#4 lore raw

Re: [PATCH 3/9] block: Generalize get_current_ioprio() for any task

Quoted 6 lines · Jan Kara

get_current_ioprio() operates only on current task. We will need the same functionality for other tasks as well. Generalize get_current_ioprio() for that and also move the bulk out of the header file because it is large enough.

Bah, I've messed up the prototype of the stub function for !CONFIG_BLOCK. One more fixup will be needed here but let me wait if people have more comments...

Honza

Quoted 84 lines
---
 block/ioprio.c         | 26 ++++++++++++++++++++++++++
 include/linux/ioprio.h | 26 ++++++++++----------------
 2 files changed, 36 insertions(+), 16 deletions(-)
block/ioprio.c +26 -0
index 2a34cbca18ae..c4e3476155a1 100644
@@ -138,6 +138,32 @@ SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio)
 	return ret;
 }
 
+/*
+ * If the task has set an I/O priority, use that. Otherwise, return
+ * the default I/O priority.
+ *
+ * Expected to be called for current task or with task_lock() held to keep
+ * io_context stable.
+ */
+int __get_task_ioprio(struct task_struct *p)
+{
+	struct io_context *ioc = p->io_context;
+	int prio;
+
+	if (p != current)
+		lockdep_assert_held(&p->alloc_lock);
+	if (ioc)
+		prio = ioc->ioprio;
+	else
+		prio = IOPRIO_DEFAULT;
+
+	if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE)
+		prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(p),
+					 task_nice_ioprio(p));
+	return prio;
+}
+EXPORT_SYMBOL_GPL(__get_task_ioprio);
+
 static int get_task_ioprio(struct task_struct *p)
 {
 	int ret;
include/linux/ioprio.h +10 -16
index 61ed6bb4998e..788a8ff57068 100644
@@ -46,24 +46,18 @@ static inline int task_nice_ioclass(struct task_struct *task)
 		return IOPRIO_CLASS_BE;
 }
 
-/*
- * If the calling process has set an I/O priority, use that. Otherwise, return
- * the default I/O priority.
- */
-static inline int get_current_ioprio(void)
+#ifdef CONFIG_BLOCK
+int __get_task_ioprio(struct task_struct *p);
+#else
+static inline int __get_task_ioprio(int ioprio)
 {
-	struct io_context *ioc = current->io_context;
-	int prio;
-
-	if (ioc)
-		prio = ioc->ioprio;
-	else
-		prio = IOPRIO_DEFAULT;
+	return IOPRIO_DEFAULT;
+}
+#endif /* CONFIG_BLOCK */
 
-	if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE)
-		prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(current),
-					 task_nice_ioprio(current));
-	return prio;
+static inline int get_current_ioprio(void)
+{
+	return __get_task_ioprio(current);
 }
 
 /*
Signature · 1 line
2.35.3
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#5 lore raw

Re: [PATCH 3/9] block: Generalize get_current_ioprio() for any task

Quoted 11 lines · Jan Kara
Quoted 6 lines · Jan Kara

get_current_ioprio() operates only on current task. We will need the same functionality for other tasks as well. Generalize get_current_ioprio() for that and also move the bulk out of the header file because it is large enough.

Bah, I've messed up the prototype of the stub function for !CONFIG_BLOCK. One more fixup will be needed here but let me wait if people have more comments...

Oops. Missed it :)

Quoted 87 lines

Honza

Quoted 84 lines
---
 block/ioprio.c         | 26 ++++++++++++++++++++++++++
 include/linux/ioprio.h | 26 ++++++++++----------------
 2 files changed, 36 insertions(+), 16 deletions(-)
block/ioprio.c +26 -0
index 2a34cbca18ae..c4e3476155a1 100644
@@ -138,6 +138,32 @@ SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio)
 	return ret;
 }
 
+/*
+ * If the task has set an I/O priority, use that. Otherwise, return
+ * the default I/O priority.
+ *
+ * Expected to be called for current task or with task_lock() held to keep
+ * io_context stable.
+ */
+int __get_task_ioprio(struct task_struct *p)
+{
+	struct io_context *ioc = p->io_context;
+	int prio;
+
+	if (p != current)
+		lockdep_assert_held(&p->alloc_lock);
+	if (ioc)
+		prio = ioc->ioprio;
+	else
+		prio = IOPRIO_DEFAULT;
+
+	if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE)
+		prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(p),
+					 task_nice_ioprio(p));
+	return prio;
+}
+EXPORT_SYMBOL_GPL(__get_task_ioprio);
+
 static int get_task_ioprio(struct task_struct *p)
 {
 	int ret;
include/linux/ioprio.h +10 -16
index 61ed6bb4998e..788a8ff57068 100644
@@ -46,24 +46,18 @@ static inline int task_nice_ioclass(struct task_struct *task)
 		return IOPRIO_CLASS_BE;
 }
 
-/*
- * If the calling process has set an I/O priority, use that. Otherwise, return
- * the default I/O priority.
- */
-static inline int get_current_ioprio(void)
+#ifdef CONFIG_BLOCK
+int __get_task_ioprio(struct task_struct *p);
+#else
+static inline int __get_task_ioprio(int ioprio)
 {
-	struct io_context *ioc = current->io_context;
-	int prio;
-
-	if (ioc)
-		prio = ioc->ioprio;
-	else
-		prio = IOPRIO_DEFAULT;
+	return IOPRIO_DEFAULT;
+}
+#endif /* CONFIG_BLOCK */
 
-	if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE)
-		prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(current),
-					 task_nice_ioprio(current));
-	return prio;
+static inline int get_current_ioprio(void)
+{
+	return __get_task_ioprio(current);
 }
 
 /*
Signature · 1 line
2.35.3
Signature · 2 lines
Damien Le Moal
Western Digital Research
Reviewed-by on v4 3/9
#6 lore raw

Re: [PATCH 3/9] block: Generalize get_current_ioprio() for any task

In reply to Jan Kara
Quoted 6 lines · Jan Kara

get_current_ioprio() operates only on current task. We will need the same functionality for other tasks as well. Generalize get_current_ioprio() for that and also move the bulk out of the header file because it is large enough.

Looks OK to me.

Quoted 81 lines
---
 block/ioprio.c         | 26 ++++++++++++++++++++++++++
 include/linux/ioprio.h | 26 ++++++++++----------------
 2 files changed, 36 insertions(+), 16 deletions(-)
block/ioprio.c +26 -0
index 2a34cbca18ae..c4e3476155a1 100644
@@ -138,6 +138,32 @@ SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio)
 	return ret;
 }
 
+/*
+ * If the task has set an I/O priority, use that. Otherwise, return
+ * the default I/O priority.
+ *
+ * Expected to be called for current task or with task_lock() held to keep
+ * io_context stable.
+ */
+int __get_task_ioprio(struct task_struct *p)
+{
+	struct io_context *ioc = p->io_context;
+	int prio;
+
+	if (p != current)
+		lockdep_assert_held(&p->alloc_lock);
+	if (ioc)
+		prio = ioc->ioprio;
+	else
+		prio = IOPRIO_DEFAULT;
+
+	if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE)
+		prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(p),
+					 task_nice_ioprio(p));
+	return prio;
+}
+EXPORT_SYMBOL_GPL(__get_task_ioprio);
+
 static int get_task_ioprio(struct task_struct *p)
 {
 	int ret;
include/linux/ioprio.h +10 -16
index 61ed6bb4998e..788a8ff57068 100644
@@ -46,24 +46,18 @@ static inline int task_nice_ioclass(struct task_struct *task)
 		return IOPRIO_CLASS_BE;
 }
 
-/*
- * If the calling process has set an I/O priority, use that. Otherwise, return
- * the default I/O priority.
- */
-static inline int get_current_ioprio(void)
+#ifdef CONFIG_BLOCK
+int __get_task_ioprio(struct task_struct *p);
+#else
+static inline int __get_task_ioprio(int ioprio)
 {
-	struct io_context *ioc = current->io_context;
-	int prio;
-
-	if (ioc)
-		prio = ioc->ioprio;
-	else
-		prio = IOPRIO_DEFAULT;
+	return IOPRIO_DEFAULT;
+}
+#endif /* CONFIG_BLOCK */
 
-	if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE)
-		prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(current),
-					 task_nice_ioprio(current));
-	return prio;
+static inline int get_current_ioprio(void)
+{
+	return __get_task_ioprio(current);
 }
 
 /*
Signature · 2 lines
Damien Le Moal
Western Digital Research
#7 lore raw

Re: [PATCH 3/9] block: Generalize get_current_ioprio() for any task

In reply to Jan Kara
I love your patch! Perhaps something to improve:

Hi Jan,

I love your patch! Perhaps something to improve:

[auto build test WARNING on axboe-block/for-next]
[also build test WARNING on linus/master v5.19-rc3 next-20220621] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Jan-Kara/block-Fix-IO-priority-mess/20220621-183235
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
config: hexagon-randconfig-r016-20220622 (https://download.01.org/0day-ci/archive/20220622/[email protected]/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project af6d2a0b6825e71965f3e2701a63c239fa0ad70f)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/8421c851d4fe5f4b9d9d6870ada8ccd0b48a4012
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jan-Kara/block-Fix-IO-priority-mess/20220621-183235 git checkout 8421c851d4fe5f4b9d9d6870ada8ccd0b48a4012
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon prepare

If you fix the issue, kindly add following tag where applicable

All warnings (new ones prefixed by >>):

In file included from arch/hexagon/kernel/asm-offsets.c:12:
In file included from include/linux/compat.h:17:
In file included from include/linux/fs.h:38:

>> include/linux/ioprio.h:60:27: warning: incompatible pointer to integer conversion passing 'struct task_struct *' to parameter of type 'int' [-Wint-conversion]
           return __get_task_ioprio(current);
                                    ^~~~~~~
   include/asm-generic/current.h:8:17: note: expanded from macro 'current'
   #define current get_current()
                   ^~~~~~~~~~~~~
   include/asm-generic/current.h:7:23: note: expanded from macro 'get_current'
   #define get_current() (current_thread_info()->task)
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/ioprio.h:52:41: note: passing argument to parameter 'ioprio' here
   static inline int __get_task_ioprio(int ioprio)
                                           ^

1 warning generated.
--
In file included from drivers/iio/proximity/isl29501.c:13:
In file included from include/linux/i2c.h:19:
In file included from include/linux/regulator/consumer.h:35:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:17:
In file included from include/linux/fs.h:38:

>> include/linux/ioprio.h:60:27: warning: incompatible pointer to integer conversion passing 'struct task_struct *' to parameter of type 'int' [-Wint-conversion]
           return __get_task_ioprio(current);
                                    ^~~~~~~
   include/asm-generic/current.h:8:17: note: expanded from macro 'current'
   #define current get_current()
                   ^~~~~~~~~~~~~
   include/asm-generic/current.h:7:23: note: expanded from macro 'get_current'
   #define get_current() (current_thread_info()->task)
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/ioprio.h:52:41: note: passing argument to parameter 'ioprio' here
   static inline int __get_task_ioprio(int ioprio)
                                           ^
   drivers/iio/proximity/isl29501.c:1000:34: warning: unused variable 'isl29501_i2c_matches' [-Wunused-const-variable]
   static const struct of_device_id isl29501_i2c_matches[] = {
                                    ^

2 warnings generated.
--
In file included from drivers/iio/proximity/sx9500.c:13:
In file included from include/linux/i2c.h:19:
In file included from include/linux/regulator/consumer.h:35:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:17:
In file included from include/linux/fs.h:38:

>> include/linux/ioprio.h:60:27: warning: incompatible pointer to integer conversion passing 'struct task_struct *' to parameter of type 'int' [-Wint-conversion]
           return __get_task_ioprio(current);
                                    ^~~~~~~
   include/asm-generic/current.h:8:17: note: expanded from macro 'current'
   #define current get_current()
                   ^~~~~~~~~~~~~
   include/asm-generic/current.h:7:23: note: expanded from macro 'get_current'
   #define get_current() (current_thread_info()->task)
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/ioprio.h:52:41: note: passing argument to parameter 'ioprio' here
   static inline int __get_task_ioprio(int ioprio)
                                           ^
   drivers/iio/proximity/sx9500.c:1035:36: warning: unused variable 'sx9500_acpi_match' [-Wunused-const-variable]
   static const struct acpi_device_id sx9500_acpi_match[] = {
                                      ^

2 warnings generated.
--
In file included from arch/hexagon/kernel/asm-offsets.c:12:
In file included from include/linux/compat.h:17:
In file included from include/linux/fs.h:38:

>> include/linux/ioprio.h:60:27: warning: incompatible pointer to integer conversion passing 'struct task_struct *' to parameter of type 'int' [-Wint-conversion]
           return __get_task_ioprio(current);
                                    ^~~~~~~
   include/asm-generic/current.h:8:17: note: expanded from macro 'current'
   #define current get_current()
                   ^~~~~~~~~~~~~
   include/asm-generic/current.h:7:23: note: expanded from macro 'get_current'
   #define get_current() (current_thread_info()->task)
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/ioprio.h:52:41: note: passing argument to parameter 'ioprio' here
   static inline int __get_task_ioprio(int ioprio)
                                           ^
   1 warning generated.
   <stdin>:1517:2: warning: syscall clone3 not implemented [-W#warnings]
   #warning syscall clone3 not implemented
    ^

1 warning generated.

vim +60 include/linux/ioprio.h

    57	
    58	static inline int get_current_ioprio(void)
    59	{
  > 60		return __get_task_ioprio(current);
    61	}
    62	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp
#8 lore raw

Re: [PATCH 3/9] block: Generalize get_current_ioprio() for any task

In reply to Jan Kara
I love your patch! Perhaps something to improve:

Hi Jan,

I love your patch! Perhaps something to improve:

[auto build test WARNING on axboe-block/for-next]
[also build test WARNING on linus/master v5.19-rc3 next-20220621] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Jan-Kara/block-Fix-IO-priority-mess/20220621-183235
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
config: riscv-nommu_k210_defconfig (https://download.01.org/0day-ci/archive/20220622/[email protected]/config)
compiler: riscv64-linux-gcc (GCC) 11.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/8421c851d4fe5f4b9d9d6870ada8ccd0b48a4012
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jan-Kara/block-Fix-IO-priority-mess/20220621-183235 git checkout 8421c851d4fe5f4b9d9d6870ada8ccd0b48a4012
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=riscv prepare

If you fix the issue, kindly add following tag where applicable

All warnings (new ones prefixed by >>):

In file included from include/linux/thread_info.h:23,
from include/asm-generic/preempt.h:5, from ./arch/riscv/include/generated/asm/preempt.h:1, from include/linux/preempt.h:78,
from include/linux/spinlock.h:55,
from include/linux/mmzone.h:8,
from include/linux/gfp.h:6,
from include/linux/mm.h:7,
from arch/riscv/kernel/asm-offsets.c:10:
include/linux/ioprio.h: In function 'get_current_ioprio':

>> arch/riscv/include/asm/current.h:34:17: warning: passing argument 1 of '__get_task_ioprio' makes integer from pointer without a cast [-Wint-conversion]
      34 | #define current get_current()
         |                 ^~~~~~~~~~~~~
         |                 |
         |                 struct task_struct *
   include/linux/ioprio.h:60:34: note: in expansion of macro 'current'
      60 |         return __get_task_ioprio(current);
         |                                  ^~~~~~~
   In file included from include/linux/fs.h:38,
                    from include/linux/huge_mm.h:8,
                    from include/linux/mm.h:700,
                    from arch/riscv/kernel/asm-offsets.c:10:

include/linux/ioprio.h:52:41: note: expected 'int' but argument is of type 'struct task_struct *'
52 | static inline int __get_task_ioprio(int ioprio)
| ~~~~^~~~~~
--
In file included from include/linux/thread_info.h:23,

                    from include/asm-generic/preempt.h:5,
                    from ./arch/riscv/include/generated/asm/preempt.h:1,
                    from include/linux/preempt.h:78,
                    from include/linux/smp.h:110,
                    from arch/riscv/include/asm/mmiowb.h:12,
                    from arch/riscv/include/asm/mmio.h:15,
                    from arch/riscv/include/asm/clint.h:10,
                    from arch/riscv/include/asm/timex.h:15,
                    from include/linux/timex.h:67,
                    from include/linux/time32.h:13,
                    from include/linux/time.h:60,
                    from include/linux/stat.h:19,
                    from include/linux/module.h:13,
                    from drivers/clk/clkdev.c:9:
   include/linux/ioprio.h: In function 'get_current_ioprio':
>> arch/riscv/include/asm/current.h:34:17: warning: passing argument 1 of '__get_task_ioprio' makes integer from pointer without a cast [-Wint-conversion]
      34 | #define current get_current()
         |                 ^~~~~~~~~~~~~
         |                 |
         |                 struct task_struct *
   include/linux/ioprio.h:60:34: note: in expansion of macro 'current'
      60 |         return __get_task_ioprio(current);
         |                                  ^~~~~~~
   In file included from include/linux/fs.h:38,
                    from include/linux/compat.h:17,
                    from arch/riscv/include/asm/elf.h:12,
                    from include/linux/elf.h:6,
                    from include/linux/module.h:19,
                    from drivers/clk/clkdev.c:9:
   include/linux/ioprio.h:52:41: note: expected 'int' but argument is of type 'struct task_struct *'
      52 | static inline int __get_task_ioprio(int ioprio)
         |                                     ~~~~^~~~~~
   drivers/clk/clkdev.c: In function 'vclkdev_alloc':
   drivers/clk/clkdev.c:173:17: warning: function 'vclkdev_alloc' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format]
     173 |                 vscnprintf(cla->dev_id, sizeof(cla->dev_id), dev_fmt, ap);
         |                 ^~~~~~~~~~

--
In file included from include/linux/thread_info.h:23,
from include/asm-generic/preempt.h:5, from ./arch/riscv/include/generated/asm/preempt.h:1, from include/linux/preempt.h:78,
from include/linux/spinlock.h:55,
from include/linux/mmzone.h:8,
from include/linux/gfp.h:6,
from include/linux/mm.h:7,
from arch/riscv/kernel/asm-offsets.c:10:
include/linux/ioprio.h: In function 'get_current_ioprio':

>> arch/riscv/include/asm/current.h:34:17: warning: passing argument 1 of '__get_task_ioprio' makes integer from pointer without a cast [-Wint-conversion]
      34 | #define current get_current()
         |                 ^~~~~~~~~~~~~
         |                 |
         |                 struct task_struct *
   include/linux/ioprio.h:60:34: note: in expansion of macro 'current'
      60 |         return __get_task_ioprio(current);
         |                                  ^~~~~~~
   In file included from include/linux/fs.h:38,
                    from include/linux/huge_mm.h:8,
                    from include/linux/mm.h:700,
                    from arch/riscv/kernel/asm-offsets.c:10:

include/linux/ioprio.h:52:41: note: expected 'int' but argument is of type 'struct task_struct *'
52 | static inline int __get_task_ioprio(int ioprio)
| ~~~~^~~~~~

vim +/__get_task_ioprio +34 arch/riscv/include/asm/current.h

7db91e57a0acde Palmer Dabbelt 2017-07-10 33
7db91e57a0acde Palmer Dabbelt 2017-07-10 @34 #define current get_current() 7db91e57a0acde Palmer Dabbelt 2017-07-10 35

Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp
#9 lore raw

Re: [PATCH 3/9] block: Generalize get_current_ioprio() for any task

In reply to Jan Kara
I love your patch! Yet something to improve:

Hi Jan,

I love your patch! Yet something to improve:

[auto build test ERROR on axboe-block/for-next]
[also build test ERROR on linus/master v5.19-rc3 next-20220621] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Jan-Kara/block-Fix-IO-priority-mess/20220621-183235
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
config: s390-randconfig-r021-20220622 (https://download.01.org/0day-ci/archive/20220622/[email protected]/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project af6d2a0b6825e71965f3e2701a63c239fa0ad70f)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install s390 cross compiling tool for clang build
# apt-get install binutils-s390x-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/8421c851d4fe5f4b9d9d6870ada8ccd0b48a4012
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jan-Kara/block-Fix-IO-priority-mess/20220621-183235 git checkout 8421c851d4fe5f4b9d9d6870ada8ccd0b48a4012
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=s390 SHELL=/bin/bash lib/

If you fix the issue, kindly add following tag where applicable

All errors (new ones prefixed by >>):

In file included from lib/test_bitops.c:9:
In file included from include/linux/module.h:19:
In file included from include/linux/elf.h:6:
In file included from arch/s390/include/asm/elf.h:160:
In file included from include/linux/compat.h:17:
In file included from include/linux/fs.h:38:

>> include/linux/ioprio.h:60:27: error: incompatible pointer to integer conversion passing 'struct task_struct *' to parameter of type 'int' [-Werror,-Wint-conversion]
           return __get_task_ioprio(current);
                                    ^~~~~~~
   arch/s390/include/asm/current.h:17:17: note: expanded from macro 'current'
   #define current ((struct task_struct *const)S390_lowcore.current_task)
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/ioprio.h:52:41: note: passing argument to parameter 'ioprio' here
   static inline int __get_task_ioprio(int ioprio)
                                           ^

1 error generated.

vim +60 include/linux/ioprio.h

    57	
    58	static inline int get_current_ioprio(void)
    59	{
  > 60		return __get_task_ioprio(current);
    61	}
    62	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp
#10 lore raw

Re: [PATCH 3/9] block: Generalize get_current_ioprio() for any task

In reply to Jan Kara
I love your patch! Perhaps something to improve:

Hi Jan,

I love your patch! Perhaps something to improve:

[auto build test WARNING on axboe-block/for-next]
[also build test WARNING on linus/master v5.19-rc3 next-20220622] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Jan-Kara/block-Fix-IO-priority-mess/20220621-183235
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
config: x86_64-randconfig-s022 (https://download.01.org/0day-ci/archive/20220622/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-3) 11.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.4-31-g4880bd19-dirty
        # https://github.com/intel-lab-lkp/linux/commit/8421c851d4fe5f4b9d9d6870ada8ccd0b48a4012
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Jan-Kara/block-Fix-IO-priority-mess/20220621-183235
        git checkout 8421c851d4fe5f4b9d9d6870ada8ccd0b48a4012
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable

sparse warnings: (new ones prefixed by >>)
fs/read_write.c: note: in included file (through include/linux/fs.h, include/linux/fsnotify_backend.h, include/linux/fsnotify.h):
include/linux/ioprio.h:60:34: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected int ioprio @@ got struct task_struct * @@
include/linux/ioprio.h:60:34: sparse: expected int ioprio
include/linux/ioprio.h:60:34: sparse: got struct task_struct *
fs/read_write.c: note: in included file (through include/linux/thread_info.h, arch/x86/include/asm/preempt.h, include/linux/preempt.h, ...):

>> arch/x86/include/asm/current.h:15:16: sparse: sparse: non size-preserving pointer to integer cast
   fs/read_write.c: note: in included file (through include/linux/fs.h, include/linux/fsnotify_backend.h, include/linux/fsnotify.h):
   include/linux/ioprio.h:60:34: sparse: sparse: incorrect type in argument 1 (different base types) @@     expected int ioprio @@     got struct task_struct * @@
   include/linux/ioprio.h:60:34: sparse:     expected int ioprio
   include/linux/ioprio.h:60:34: sparse:     got struct task_struct *
   fs/read_write.c: note: in included file (through include/linux/thread_info.h, arch/x86/include/asm/preempt.h, include/linux/preempt.h, ...):
>> arch/x86/include/asm/current.h:15:16: sparse: sparse: non size-preserving pointer to integer cast
   fs/read_write.c: note: in included file (through include/linux/fs.h, include/linux/fsnotify_backend.h, include/linux/fsnotify.h):
   include/linux/ioprio.h:60:34: sparse: sparse: incorrect type in argument 1 (different base types) @@     expected int ioprio @@     got struct task_struct * @@
   include/linux/ioprio.h:60:34: sparse:     expected int ioprio
   include/linux/ioprio.h:60:34: sparse:     got struct task_struct *
   fs/read_write.c: note: in included file (through include/linux/thread_info.h, arch/x86/include/asm/preempt.h, include/linux/preempt.h, ...):
>> arch/x86/include/asm/current.h:15:16: sparse: sparse: non size-preserving pointer to integer cast
   fs/read_write.c: note: in included file (through include/linux/fs.h, include/linux/fsnotify_backend.h, include/linux/fsnotify.h):
   include/linux/ioprio.h:60:34: sparse: sparse: incorrect type in argument 1 (different base types) @@     expected int ioprio @@     got struct task_struct * @@
   include/linux/ioprio.h:60:34: sparse:     expected int ioprio
   include/linux/ioprio.h:60:34: sparse:     got struct task_struct *
   fs/read_write.c: note: in included file (through include/linux/thread_info.h, arch/x86/include/asm/preempt.h, include/linux/preempt.h, ...):
>> arch/x86/include/asm/current.h:15:16: sparse: sparse: non size-preserving pointer to integer cast
   fs/read_write.c: note: in included file (through include/linux/fs.h, include/linux/fsnotify_backend.h, include/linux/fsnotify.h):
   include/linux/ioprio.h:60:34: sparse: sparse: incorrect type in argument 1 (different base types) @@     expected int ioprio @@     got struct task_struct * @@
   include/linux/ioprio.h:60:34: sparse:     expected int ioprio
   include/linux/ioprio.h:60:34: sparse:     got struct task_struct *
   fs/read_write.c: note: in included file (through include/linux/thread_info.h, arch/x86/include/asm/preempt.h, include/linux/preempt.h, ...):
>> arch/x86/include/asm/current.h:15:16: sparse: sparse: non size-preserving pointer to integer cast

--
fs/seq_file.c:938:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
fs/seq_file.c:938:9: sparse: struct list_head [noderef] __rcu *
fs/seq_file.c:938:9: sparse: struct list_head *
fs/seq_file.c:938:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
fs/seq_file.c:938:9: sparse: struct list_head [noderef] __rcu *
fs/seq_file.c:938:9: sparse: struct list_head *
fs/seq_file.c:960:12: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct list_head *lh @@ got struct list_head [noderef] __rcu * @@
fs/seq_file.c:960:12: sparse: expected struct list_head *lh
fs/seq_file.c:960:12: sparse: got struct list_head [noderef] __rcu *
fs/seq_file.c:1087:24: sparse: sparse: incompatible types in comparison expression (different address spaces):
fs/seq_file.c:1087:24: sparse: struct hlist_node [noderef] __rcu *
fs/seq_file.c:1087:24: sparse: struct hlist_node *
fs/seq_file.c:1089:24: sparse: sparse: incompatible types in comparison expression (different address spaces):
fs/seq_file.c:1089:24: sparse: struct hlist_node [noderef] __rcu *
fs/seq_file.c:1089:24: sparse: struct hlist_node *
fs/seq_file.c: note: in included file (through include/linux/fs.h):
include/linux/ioprio.h:60:34: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected int ioprio @@ got struct task_struct * @@
include/linux/ioprio.h:60:34: sparse: expected int ioprio
include/linux/ioprio.h:60:34: sparse: got struct task_struct *
fs/seq_file.c: note: in included file (through include/linux/thread_info.h, arch/x86/include/asm/preempt.h, include/linux/preempt.h, ...):

>> arch/x86/include/asm/current.h:15:16: sparse: sparse: non size-preserving pointer to integer cast

--
fs/splice.c: note: in included file (through include/linux/fs.h, include/linux/highmem.h, include/linux/bvec.h):
include/linux/ioprio.h:60:34: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected int ioprio @@ got struct task_struct * @@
include/linux/ioprio.h:60:34: sparse: expected int ioprio
include/linux/ioprio.h:60:34: sparse: got struct task_struct *
fs/splice.c: note: in included file (through include/linux/thread_info.h, arch/x86/include/asm/preempt.h, include/linux/preempt.h, ...):

>> arch/x86/include/asm/current.h:15:16: sparse: sparse: non size-preserving pointer to integer cast

vim +15 arch/x86/include/asm/current.h

f0766440dda7ace include/asm-x86/current.h      Christoph Lameter 2008-05-09  12  
f0766440dda7ace include/asm-x86/current.h      Christoph Lameter 2008-05-09  13  static __always_inline struct task_struct *get_current(void)
f0766440dda7ace include/asm-x86/current.h      Christoph Lameter 2008-05-09  14  {
c6ae41e7d469f00 arch/x86/include/asm/current.h Alex Shi          2012-05-11 @15  	return this_cpu_read_stable(current_task);
f0766440dda7ace include/asm-x86/current.h      Christoph Lameter 2008-05-09  16  }
f0766440dda7ace include/asm-x86/current.h      Christoph Lameter 2008-05-09  17  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp
author
#11 lore raw

PATCH v4 4/9 block: Make ioprio_best() static

In reply to Jan Kara

Nobody outside of block/ioprio.c uses it.

---
 block/ioprio.c         | 2 +-
 include/linux/ioprio.h | 5 -----
 2 files changed, 1 insertion(+), 6 deletions(-)
block/ioprio.c +1 -1
index c4e3476155a1..8c46f672a0ba 100644
@@ -180,7 +180,7 @@ static int get_task_ioprio(struct task_struct *p)
 	return ret;
 }
 
-int ioprio_best(unsigned short aprio, unsigned short bprio)
+static int ioprio_best(unsigned short aprio, unsigned short bprio)
 {
 	if (!ioprio_valid(aprio))
 		aprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM);
include/linux/ioprio.h +0 -5
index 788a8ff57068..3ba5804e5770 100644
@@ -60,11 +60,6 @@ static inline int get_current_ioprio(void)
 	return __get_task_ioprio(current);
 }
 
-/*
- * For inheritance, return the highest of the two given priorities
- */
-extern int ioprio_best(unsigned short aprio, unsigned short bprio);
-
 extern int set_task_ioprio(struct task_struct *task, int ioprio);
 
 #ifdef CONFIG_BLOCK
Signature · 1 line
2.35.3
author
#12 lore raw

PATCH v4 5/9 block: Fix handling of tasks without ioprio in ioprio_get(2)

In reply to Jan Kara

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.

---
 block/ioprio.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)
block/ioprio.c +23 -7
index 8c46f672a0ba..32a456b45804 100644
@@ -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)
Signature · 1 line
2.35.3
Reviewed-by on v4 5/9
#13 lore raw

Re: [PATCH 5/9] block: Fix handling of tasks without ioprio in ioprio_get(2)

Quoted 6 lines · Jan Kara

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).

Quoted 6 lines

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.

Looks OK to me.

Quoted 62 lines
---
 block/ioprio.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)
block/ioprio.c +23 -7
index 8c46f672a0ba..32a456b45804 100644
@@ -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)
Signature · 2 lines
Damien Le Moal
Western Digital Research
author
#14 lore raw

PATCH v4 6/9 blk-ioprio: Remove unneeded field

In reply to Jan Kara

blkcg->ioprio_set field is not really useful except for avoiding possibly more expensive checks inside blkcg_ioprio_track(). The check for blkcg->prio_policy being equal to POLICY_NO_CHANGE does the same service so just remove the ioprio_set field and replace the check.

---
 block/blk-ioprio.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
block/blk-ioprio.c +3 -6
index 79e797f5d194..3f605583598b 100644
@@ -62,7 +62,6 @@ struct ioprio_blkg {
 struct ioprio_blkcg {
 	struct blkcg_policy_data cpd;
 	enum prio_policy	 prio_policy;
-	bool			 prio_set;
 };
 
 static inline struct ioprio_blkg *pd_to_ioprio(struct blkg_policy_data *pd)
@@ -113,7 +112,6 @@ static ssize_t ioprio_set_prio_policy(struct kernfs_open_file *of, char *buf,
 	if (ret < 0)
 		return ret;
 	blkcg->prio_policy = ret;
-	blkcg->prio_set = true;
 	return nbytes;
 }
 
@@ -193,16 +191,15 @@ static void blkcg_ioprio_track(struct rq_qos *rqos, struct request *rq,
 	struct ioprio_blkcg *blkcg = ioprio_blkcg_from_bio(bio);
 	u16 prio;
 
-	if (!blkcg->prio_set)
+	if (blkcg->prio_policy == POLICY_NO_CHANGE)
 		return;
 
 	/*
 	 * Except for IOPRIO_CLASS_NONE, higher I/O priority numbers
 	 * correspond to a lower priority. Hence, the max_t() below selects
 	 * the lower priority of bi_ioprio and the cgroup I/O priority class.
-	 * If the cgroup policy has been set to POLICY_NO_CHANGE == 0, the
-	 * bio I/O priority is not modified. If the bio I/O priority equals
-	 * IOPRIO_CLASS_NONE, the cgroup I/O priority is assigned to the bio.
+	 * If the bio I/O priority equals IOPRIO_CLASS_NONE, the cgroup I/O
+	 * priority is assigned to the bio.
 	 */
 	prio = max_t(u16, bio->bi_ioprio,
 			IOPRIO_PRIO_VALUE(blkcg->prio_policy, 0));
Signature · 1 line
2.35.3
author
#15 lore raw

PATCH v4 7/9 blk-ioprio: Convert from rqos policy to direct call

In reply to Jan Kara

Convert blk-ioprio handling from a rqos policy to a direct call from blk_mq_submit_bio(). Firstly, blk-ioprio is not much of a rqos policy anyway, it just needs a hook in bio submission path to set the bio's IO priority. Secondly, the rqos .track hook gets actually called too late for blk-ioprio purposes and introducing a special rqos hook just for blk-ioprio looks even weirder.

---
 block/blk-cgroup.c |  1 +
 block/blk-ioprio.c | 50 +++++-----------------------------------------
 block/blk-ioprio.h |  9 +++++++++
 block/blk-mq.c     |  8 ++++++++
 4 files changed, 23 insertions(+), 45 deletions(-)
block/blk-cgroup.c +1 -0
index 764e740b0c0f..6906981563f8 100644
@@ -1299,6 +1299,7 @@ int blkcg_init_queue(struct request_queue *q)
 	ret = blk_iolatency_init(q);
 	if (ret) {
 		blk_throtl_exit(q);
+		blk_ioprio_exit(q);
 		goto err_destroy_all;
 	}
 
block/blk-ioprio.c +5 -45

71 lines not on this page · raw message

block/blk-ioprio.h +9 -0
index a7785c2f1aea..5a1eb550e178 100644
@@ -6,14 +6,23 @@
 #include <linux/kconfig.h>
 
 struct request_queue;
+struct bio;
 
 #ifdef CONFIG_BLK_CGROUP_IOPRIO
 int blk_ioprio_init(struct request_queue *q);
+void blk_ioprio_exit(struct request_queue *q);
+void blkcg_set_ioprio(struct bio *bio);
 #else
 static inline int blk_ioprio_init(struct request_queue *q)
 {
 	return 0;
 }
+static inline void blk_ioprio_exit(struct request_queue *q)
+{
+}
+static inline void blkcg_set_ioprio(struct bio *bio)
+{
+}
 #endif
 
 #endif /* _BLK_IOPRIO_H_ */
block/blk-mq.c +8 -0
index e9bf950983c7..67a7bfa58b7c 100644
@@ -42,6 +42,7 @@
 #include "blk-stat.h"
 #include "blk-mq-sched.h"
 #include "blk-rq-qos.h"
+#include "blk-ioprio.h"
 
 static DEFINE_PER_CPU(struct llist_head, blk_cpu_done);
 
@@ -2790,6 +2791,11 @@ static inline struct request *blk_mq_get_cached_request(struct request_queue *q,
 	return rq;
 }
 
+static void bio_set_ioprio(struct bio *bio)
+{
+	blkcg_set_ioprio(bio);
+}
+
 /**
  * blk_mq_submit_bio - Create and send a request to block device.
  * @bio: Bio pointer.
@@ -2830,6 +2836,8 @@ void blk_mq_submit_bio(struct bio *bio)
 
 	trace_block_getrq(bio);
 
+	bio_set_ioprio(bio);
+
 	rq_qos_track(q, rq, bio);
 
 	blk_mq_bio_to_request(rq, bio, nr_segs);
Signature · 1 line
2.35.3
author
#16 lore raw

PATCH v4 8/9 block: Initialize bio priority earlier

In reply to Jan Kara

Bio's IO priority needs to be initialized before we try to merge the bio with other bios. Otherwise we could merge bios which would otherwise receive different IO priorities leading to possible QoS issues.

---
 block/blk-mq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/blk-mq.c +2 -2
index 67a7bfa58b7c..e17d822e6051 100644
@@ -2825,6 +2825,8 @@ void blk_mq_submit_bio(struct bio *bio)
 	if (!bio_integrity_prep(bio))
 		return;
 
+	bio_set_ioprio(bio);
+
 	rq = blk_mq_get_cached_request(q, plug, &bio, nr_segs);
 	if (!rq) {
 		if (!bio)
@@ -2836,8 +2838,6 @@ void blk_mq_submit_bio(struct bio *bio)
 
 	trace_block_getrq(bio);
 
-	bio_set_ioprio(bio);
-
 	rq_qos_track(q, rq, bio);
 
 	blk_mq_bio_to_request(rq, bio, nr_segs);
Signature · 1 line
2.35.3
author
#17 lore raw

PATCH v4 9/9 block: Always initialize bio IO priority on submit

In reply to Jan Kara

Currently, IO priority set in task's IO context is not reflected in the bio->bi_ioprio for most IO (only io_uring and direct IO set it). This results in odd results where process is submitting some bios with one priority and other bios with a different (unset) priority and due to differing priorities bios cannot be merged. Make sure bio->bi_ioprio is always set on bio submission.

---
 block/blk-mq.c | 3 +++
 1 file changed, 3 insertions(+)
block/blk-mq.c +3 -0
index e17d822e6051..7548f8aebea8 100644
@@ -2793,6 +2793,9 @@ static inline struct request *blk_mq_get_cached_request(struct request_queue *q,
 
 static void bio_set_ioprio(struct bio *bio)
 {
+	/* Nobody set ioprio so far? Initialize it based on task's nice value */
+	if (IOPRIO_PRIO_CLASS(bio->bi_ioprio) == IOPRIO_CLASS_NONE)
+		bio->bi_ioprio = get_current_ioprio();
 	blkcg_set_ioprio(bio);
 }
 
Signature · 1 line
2.35.3
#18 lore raw
In reply to Jan Kara
Quoted 4 lines · Jan Kara

Hello,

This is the fourth revision of my patches fixing IO priority handling in the block layer.

Thanks for this. I reviewed and this all looks good to me. Nevertheless, I will give this a spin tomorrow (with ATA drives that have NCQ priority).

Quoted 41 lines

Changes since v3:
* Added Reviewed-by tags from Damien
* Fixed build failure without CONFIG_BLOCK
* Separated refactoring of get_current_ioprio() into a separate patch

Changes since v2:
* added some comments to better explain things
* changed handling of ioprio_get(2)
* a few small tweaks based on Damien's feedback

Original cover letter:
Recently, I've been looking into 10% regression reported by our performance measurement infrastructure in reaim benchmark that was bisected down to 5a9d041ba2f6 ("block: move io_context creation into where it's needed"). This didn't really make much sense and it took me a while to understand this but the culprit is actually in even older commit e70344c05995 ("block: fix default IO priority handling") and 5a9d041ba2f6 just made the breakage visible. Essentially the problem was that after these commits some IO was queued with IO priority class IOPRIO_CLASS_BE while other IO was queued with IOPRIO_CLASS_NONE and as a result they could not be merged together resulting in performance regression. I think what commit e70344c05995 ("block: fix default IO priority handling") did is actually broken not only because of this performance regression but because of other reasons as well (see changelog of patch 3/8 for details). Besides this problem, there are multiple other inconsistencies in the IO priority handling throughout the block stack we have identified when discussing this with Damien Le Moal. So this patch set aims at fixing all these various issues.

Note that there are a few choices I've made I'm not 100% sold on. In particular the conversion of blk-ioprio from rqos is somewhat disputable since it now incurs a cost similar to blk-throttle in the bio submission fast path (need to load bio->bi_blkg->pd[ioprio_policy.plid]). If people think the removed boilerplate code is not worth the cost, I can certainly go via the "additional rqos hook" path.

Honza
Previous versions:

Signature · 2 lines
Damien Le Moal
Western Digital Research
author
#19 lore raw
Quoted 9 lines · Damien Le Moal
Quoted 4 lines · Jan Kara

Hello,

This is the fourth revision of my patches fixing IO priority handling in the block layer.

Thanks for this. I reviewed and this all looks good to me. Nevertheless, I will give this a spin tomorrow (with ATA drives that have NCQ priority).

Great, thanks for the review and the testing! I will wait for the results and then post the final version of the patchset.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
Tested-by on the v4 series
#20 lore raw
In reply to Jan Kara
Quoted 4 lines · Jan Kara

Hello,

This is the fourth revision of my patches fixing IO priority handling in the block layer.

Hey,

I ran some tests with RT IO class on an ATA HDD with NCQ priority. Results look good:

randread: (groupid=0, jobs=1): err= 0: pid=1862: Thu Jun 23 09:22:42 2022
read: IOPS=152, BW=19.1MiB/s (20.0MB/s)(11.1GiB/592929msec)

    slat (usec): min=37, max=3280, avg=174.96, stdev=120.90
    clat (msec): min=7, max=918, avg=156.95, stdev=149.43
     lat (msec): min=7, max=918, avg=157.13, stdev=149.43
    clat prio 0/0 (msec): min=7, max=918, avg=171.68, stdev=150.48
    clat prio 1/0 (msec): min=8, max=166, avg=24.64, stdev= 5.93
    clat percentiles (msec):
     |  1.00th=[   15],  5.00th=[   20], 10.00th=[   23], 20.00th=[   32],
     | 30.00th=[   51], 40.00th=[   77], 50.00th=[  108], 60.00th=[  146],
     | 70.00th=[  194], 80.00th=[  262], 90.00th=[  372], 95.00th=[  477],
     | 99.00th=[  659], 99.50th=[  701], 99.90th=[  793], 99.95th=[  818],
     | 99.99th=[  885]
    clat prio 0/0 (89.99% of IOs) percentiles (msec):
     |  1.00th=[   15],  5.00th=[   21], 10.00th=[   27], 20.00th=[   46],
     | 30.00th=[   68], 40.00th=[   94], 50.00th=[  126], 60.00th=[  163],
     | 70.00th=[  213], 80.00th=[  279], 90.00th=[  388], 95.00th=[  489],
     | 99.00th=[  659], 99.50th=[  709], 99.90th=[  793], 99.95th=[  827],
     | 99.99th=[  885]
    clat prio 1/0 (10.01% of IOs) percentiles (msec):
     |  1.00th=[   14],  5.00th=[   17], 10.00th=[   18], 20.00th=[   20],
     | 30.00th=[   22], 40.00th=[   23], 50.00th=[   25], 60.00th=[   26],
     | 70.00th=[   28], 80.00th=[   30], 90.00th=[   33], 95.00th=[   35],
     | 99.00th=[   40], 99.50th=[   42], 99.90th=[   47], 99.95th=[   50],
     | 99.99th=[  167]

Clearly significantly lower tail latencies for the 10% of IOs with class RT (1/0), as expected. This is with "none" scheduler at QD=24 (128K random read).

Feel free to add:

Quoted 41 lines

Changes since v3:
* Added Reviewed-by tags from Damien
* Fixed build failure without CONFIG_BLOCK
* Separated refactoring of get_current_ioprio() into a separate patch

Changes since v2:
* added some comments to better explain things
* changed handling of ioprio_get(2)
* a few small tweaks based on Damien's feedback

Original cover letter:
Recently, I've been looking into 10% regression reported by our performance measurement infrastructure in reaim benchmark that was bisected down to 5a9d041ba2f6 ("block: move io_context creation into where it's needed"). This didn't really make much sense and it took me a while to understand this but the culprit is actually in even older commit e70344c05995 ("block: fix default IO priority handling") and 5a9d041ba2f6 just made the breakage visible. Essentially the problem was that after these commits some IO was queued with IO priority class IOPRIO_CLASS_BE while other IO was queued with IOPRIO_CLASS_NONE and as a result they could not be merged together resulting in performance regression. I think what commit e70344c05995 ("block: fix default IO priority handling") did is actually broken not only because of this performance regression but because of other reasons as well (see changelog of patch 3/8 for details). Besides this problem, there are multiple other inconsistencies in the IO priority handling throughout the block stack we have identified when discussing this with Damien Le Moal. So this patch set aims at fixing all these various issues.

Note that there are a few choices I've made I'm not 100% sold on. In particular the conversion of blk-ioprio from rqos is somewhat disputable since it now incurs a cost similar to blk-throttle in the bio submission fast path (need to load bio->bi_blkg->pd[ioprio_policy.plid]). If people think the removed boilerplate code is not worth the cost, I can certainly go via the "additional rqos hook" path.

Honza
Previous versions:

Signature · 2 lines
Damien Le Moal
Western Digital Research
author
#21 lore raw
Quoted 37 lines · Damien Le Moal
Quoted 4 lines · Jan Kara

Hello,

This is the fourth revision of my patches fixing IO priority handling in the block layer.

Hey,

I ran some tests with RT IO class on an ATA HDD with NCQ priority. Results look good:

randread: (groupid=0, jobs=1): err= 0: pid=1862: Thu Jun 23 09:22:42 2022
read: IOPS=152, BW=19.1MiB/s (20.0MB/s)(11.1GiB/592929msec)

    slat (usec): min=37, max=3280, avg=174.96, stdev=120.90
    clat (msec): min=7, max=918, avg=156.95, stdev=149.43
     lat (msec): min=7, max=918, avg=157.13, stdev=149.43
    clat prio 0/0 (msec): min=7, max=918, avg=171.68, stdev=150.48
    clat prio 1/0 (msec): min=8, max=166, avg=24.64, stdev= 5.93
    clat percentiles (msec):
     |  1.00th=[   15],  5.00th=[   20], 10.00th=[   23], 20.00th=[   32],
     | 30.00th=[   51], 40.00th=[   77], 50.00th=[  108], 60.00th=[  146],
     | 70.00th=[  194], 80.00th=[  262], 90.00th=[  372], 95.00th=[  477],
     | 99.00th=[  659], 99.50th=[  701], 99.90th=[  793], 99.95th=[  818],
     | 99.99th=[  885]
    clat prio 0/0 (89.99% of IOs) percentiles (msec):
     |  1.00th=[   15],  5.00th=[   21], 10.00th=[   27], 20.00th=[   46],
     | 30.00th=[   68], 40.00th=[   94], 50.00th=[  126], 60.00th=[  163],
     | 70.00th=[  213], 80.00th=[  279], 90.00th=[  388], 95.00th=[  489],
     | 99.00th=[  659], 99.50th=[  709], 99.90th=[  793], 99.95th=[  827],
     | 99.99th=[  885]
    clat prio 1/0 (10.01% of IOs) percentiles (msec):
     |  1.00th=[   14],  5.00th=[   17], 10.00th=[   18], 20.00th=[   20],
     | 30.00th=[   22], 40.00th=[   23], 50.00th=[   25], 60.00th=[   26],
     | 70.00th=[   28], 80.00th=[   30], 90.00th=[   33], 95.00th=[   35],
     | 99.00th=[   40], 99.50th=[   42], 99.90th=[   47], 99.95th=[   50],
     | 99.99th=[  167]
Quoted 3 lines

Clearly significantly lower tail latencies for the 10% of IOs with class RT (1/0), as expected. This is with "none" scheduler at QD=24 (128K random read).

Nice! :)

Quoted 3 lines

Feel free to add:

Thanks for testing! I'll post the final patch version shortly.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR