All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/6] IO priority fixes and improvements
@ 2021-08-11  3:36 ` Damien Le Moal
  0 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-11  3:36 UTC (permalink / raw)
  To: Jens Axboe, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

This series fixes problems with IO priority values handling and cleans
up several macro names and code for clarity.

Changes from v3:
* Split former patch 2 into patches 2, 3 and 4 to facilitate review and
  have more descriptive commit titles.
* In patch 5, keep IOPRIO_BE_NR as an alias for the new IOPRIO_NR_LEVELS
  macro. Change this patch title and commit message accordingly.
* In patch 6, define IOPRIO_BE_NORM as an alias of IOPRIO_NORM.

Changes from v2:
* Fixed typo in a comment in patch 3
* Added reviewed-by tags

Changes from v1:
* Added patch 4 to unify the default priority value used in various
  places.
* Fixed patch 2 as suggested by Bart: remove extra parenthesis and move
  ioprio_valid() from the uapi header to the kernel header.
* In patch 2, add priority value masking.

Damien Le Moal (6):
  block: bfq: fix bfq_set_next_ioprio_data()
  block: improve ioprio class description comment
  block: change ioprio_valid() to an inline function
  block: fix IOPRIO_PRIO_CLASS() and IOPRIO_PRIO_VALUE() macros
  block: Introduce IOPRIO_NR_LEVELS
  block: fix default IO priority handling

 block/bfq-iosched.c          | 10 +++++-----
 block/bfq-iosched.h          |  4 ++--
 block/bfq-wf2q.c             |  6 +++---
 block/ioprio.c               |  9 ++++-----
 drivers/nvme/host/lightnvm.c |  2 +-
 fs/f2fs/sysfs.c              |  2 +-
 include/linux/ioprio.h       | 17 ++++++++++++++++-
 include/uapi/linux/ioprio.h  | 34 ++++++++++++++++++++--------------
 8 files changed, 52 insertions(+), 32 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [f2fs-dev] [PATCH v4 0/6] IO priority fixes and improvements
@ 2021-08-11  3:36 ` Damien Le Moal
  0 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-11  3:36 UTC (permalink / raw)
  To: Jens Axboe, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

This series fixes problems with IO priority values handling and cleans
up several macro names and code for clarity.

Changes from v3:
* Split former patch 2 into patches 2, 3 and 4 to facilitate review and
  have more descriptive commit titles.
* In patch 5, keep IOPRIO_BE_NR as an alias for the new IOPRIO_NR_LEVELS
  macro. Change this patch title and commit message accordingly.
* In patch 6, define IOPRIO_BE_NORM as an alias of IOPRIO_NORM.

Changes from v2:
* Fixed typo in a comment in patch 3
* Added reviewed-by tags

Changes from v1:
* Added patch 4 to unify the default priority value used in various
  places.
* Fixed patch 2 as suggested by Bart: remove extra parenthesis and move
  ioprio_valid() from the uapi header to the kernel header.
* In patch 2, add priority value masking.

Damien Le Moal (6):
  block: bfq: fix bfq_set_next_ioprio_data()
  block: improve ioprio class description comment
  block: change ioprio_valid() to an inline function
  block: fix IOPRIO_PRIO_CLASS() and IOPRIO_PRIO_VALUE() macros
  block: Introduce IOPRIO_NR_LEVELS
  block: fix default IO priority handling

 block/bfq-iosched.c          | 10 +++++-----
 block/bfq-iosched.h          |  4 ++--
 block/bfq-wf2q.c             |  6 +++---
 block/ioprio.c               |  9 ++++-----
 drivers/nvme/host/lightnvm.c |  2 +-
 fs/f2fs/sysfs.c              |  2 +-
 include/linux/ioprio.h       | 17 ++++++++++++++++-
 include/uapi/linux/ioprio.h  | 34 ++++++++++++++++++++--------------
 8 files changed, 52 insertions(+), 32 deletions(-)

-- 
2.31.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH v4 1/6] block: bfq: fix bfq_set_next_ioprio_data()
  2021-08-11  3:36 ` [f2fs-dev] " Damien Le Moal
@ 2021-08-11  3:36   ` Damien Le Moal
  -1 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-11  3:36 UTC (permalink / raw)
  To: Jens Axboe, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

For a request that has a priority level equal to or larger than
IOPRIO_BE_NR, bfq_set_next_ioprio_data() prints a critical warning but
defaults to setting the request new_ioprio field to IOPRIO_BE_NR. This
is not consistent with the warning and the allowed values for priority
levels. Fix this by setting the request new_ioprio field to
IOPRIO_BE_NR - 1, the lowest priority level allowed.

Cc: <stable@vger.kernel.org>
Fixes: aee69d78dec0 ("block, bfq: introduce the BFQ-v0 I/O scheduler as an extra scheduler")
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
---
 block/bfq-iosched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index e4a61eda2d0f..e546a5f4bff9 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -5296,7 +5296,7 @@ bfq_set_next_ioprio_data(struct bfq_queue *bfqq, struct bfq_io_cq *bic)
 	if (bfqq->new_ioprio >= IOPRIO_BE_NR) {
 		pr_crit("bfq_set_next_ioprio_data: new_ioprio %d\n",
 			bfqq->new_ioprio);
-		bfqq->new_ioprio = IOPRIO_BE_NR;
+		bfqq->new_ioprio = IOPRIO_BE_NR - 1;
 	}
 
 	bfqq->entity.new_weight = bfq_ioprio_to_weight(bfqq->new_ioprio);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [f2fs-dev] [PATCH v4 1/6] block: bfq: fix bfq_set_next_ioprio_data()
@ 2021-08-11  3:36   ` Damien Le Moal
  0 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-11  3:36 UTC (permalink / raw)
  To: Jens Axboe, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

For a request that has a priority level equal to or larger than
IOPRIO_BE_NR, bfq_set_next_ioprio_data() prints a critical warning but
defaults to setting the request new_ioprio field to IOPRIO_BE_NR. This
is not consistent with the warning and the allowed values for priority
levels. Fix this by setting the request new_ioprio field to
IOPRIO_BE_NR - 1, the lowest priority level allowed.

Cc: <stable@vger.kernel.org>
Fixes: aee69d78dec0 ("block, bfq: introduce the BFQ-v0 I/O scheduler as an extra scheduler")
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
---
 block/bfq-iosched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index e4a61eda2d0f..e546a5f4bff9 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -5296,7 +5296,7 @@ bfq_set_next_ioprio_data(struct bfq_queue *bfqq, struct bfq_io_cq *bic)
 	if (bfqq->new_ioprio >= IOPRIO_BE_NR) {
 		pr_crit("bfq_set_next_ioprio_data: new_ioprio %d\n",
 			bfqq->new_ioprio);
-		bfqq->new_ioprio = IOPRIO_BE_NR;
+		bfqq->new_ioprio = IOPRIO_BE_NR - 1;
 	}
 
 	bfqq->entity.new_weight = bfq_ioprio_to_weight(bfqq->new_ioprio);
-- 
2.31.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 2/6] block: improve ioprio class description comment
  2021-08-11  3:36 ` [f2fs-dev] " Damien Le Moal
@ 2021-08-11  3:36   ` Damien Le Moal
  -1 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-11  3:36 UTC (permalink / raw)
  To: Jens Axboe, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

In include/usapi/linux/ioprio.h, change the ioprio class enum comment
to remove the outdated reference to CFQ and mention BFQ and mq-deadline
instead. Also document the high priority NCQ command use for RT class
IOs directed at ATA drives that support NCQ priority.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 include/uapi/linux/ioprio.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/uapi/linux/ioprio.h b/include/uapi/linux/ioprio.h
index 77b17e08b0da..6b735854aebd 100644
--- a/include/uapi/linux/ioprio.h
+++ b/include/uapi/linux/ioprio.h
@@ -13,10 +13,12 @@
 #define IOPRIO_PRIO_VALUE(class, data)	(((class) << IOPRIO_CLASS_SHIFT) | data)
 
 /*
- * These are the io priority groups as implemented by CFQ. RT is the realtime
- * class, it always gets premium service. BE is the best-effort scheduling
- * class, the default for any process. IDLE is the idle scheduling class, it
- * is only served when no one else is using the disk.
+ * These are the io priority groups as implemented by the BFQ and mq-deadline
+ * schedulers. RT is the realtime class, it always gets premium service. For
+ * ATA disks supporting NCQ IO priority, RT class IOs will be processed using
+ * high priority NCQ commands. BE is the best-effort scheduling class, the
+ * default for any process. IDLE is the idle scheduling class, it is only
+ * served when no one else is using the disk.
  */
 enum {
 	IOPRIO_CLASS_NONE,
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [f2fs-dev] [PATCH v4 2/6] block: improve ioprio class description comment
@ 2021-08-11  3:36   ` Damien Le Moal
  0 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-11  3:36 UTC (permalink / raw)
  To: Jens Axboe, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

In include/usapi/linux/ioprio.h, change the ioprio class enum comment
to remove the outdated reference to CFQ and mention BFQ and mq-deadline
instead. Also document the high priority NCQ command use for RT class
IOs directed at ATA drives that support NCQ priority.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 include/uapi/linux/ioprio.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/uapi/linux/ioprio.h b/include/uapi/linux/ioprio.h
index 77b17e08b0da..6b735854aebd 100644
--- a/include/uapi/linux/ioprio.h
+++ b/include/uapi/linux/ioprio.h
@@ -13,10 +13,12 @@
 #define IOPRIO_PRIO_VALUE(class, data)	(((class) << IOPRIO_CLASS_SHIFT) | data)
 
 /*
- * These are the io priority groups as implemented by CFQ. RT is the realtime
- * class, it always gets premium service. BE is the best-effort scheduling
- * class, the default for any process. IDLE is the idle scheduling class, it
- * is only served when no one else is using the disk.
+ * These are the io priority groups as implemented by the BFQ and mq-deadline
+ * schedulers. RT is the realtime class, it always gets premium service. For
+ * ATA disks supporting NCQ IO priority, RT class IOs will be processed using
+ * high priority NCQ commands. BE is the best-effort scheduling class, the
+ * default for any process. IDLE is the idle scheduling class, it is only
+ * served when no one else is using the disk.
  */
 enum {
 	IOPRIO_CLASS_NONE,
-- 
2.31.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 3/6] block: change ioprio_valid() to an inline function
  2021-08-11  3:36 ` [f2fs-dev] " Damien Le Moal
@ 2021-08-11  3:36   ` Damien Le Moal
  -1 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-11  3:36 UTC (permalink / raw)
  To: Jens Axboe, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

Change the ioprio_valid() macro in include/usapi/linux/ioprio.h to an
inline function declared on the kernel side in include/linux/ioprio.h.
Also improve checks on the class value by checking the upper bound
value.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 include/linux/ioprio.h      | 10 ++++++++++
 include/uapi/linux/ioprio.h |  2 --
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/linux/ioprio.h b/include/linux/ioprio.h
index ef9ad4fb245f..2ee3373684b1 100644
--- a/include/linux/ioprio.h
+++ b/include/linux/ioprio.h
@@ -8,6 +8,16 @@
 
 #include <uapi/linux/ioprio.h>
 
+/*
+ * Check that a priority value has a valid class.
+ */
+static inline bool ioprio_valid(unsigned short ioprio)
+{
+	unsigned short class = IOPRIO_PRIO_CLASS(ioprio);
+
+	return class > IOPRIO_CLASS_NONE && class <= IOPRIO_CLASS_IDLE;
+}
+
 /*
  * if process has set io priority explicitly, use that. if not, convert
  * the cpu scheduler nice value to an io priority
diff --git a/include/uapi/linux/ioprio.h b/include/uapi/linux/ioprio.h
index 6b735854aebd..5064e230374c 100644
--- a/include/uapi/linux/ioprio.h
+++ b/include/uapi/linux/ioprio.h
@@ -27,8 +27,6 @@ enum {
 	IOPRIO_CLASS_IDLE,
 };
 
-#define ioprio_valid(mask)	(IOPRIO_PRIO_CLASS((mask)) != IOPRIO_CLASS_NONE)
-
 /*
  * 8 best effort priority levels are supported
  */
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [f2fs-dev] [PATCH v4 3/6] block: change ioprio_valid() to an inline function
@ 2021-08-11  3:36   ` Damien Le Moal
  0 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-11  3:36 UTC (permalink / raw)
  To: Jens Axboe, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

Change the ioprio_valid() macro in include/usapi/linux/ioprio.h to an
inline function declared on the kernel side in include/linux/ioprio.h.
Also improve checks on the class value by checking the upper bound
value.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 include/linux/ioprio.h      | 10 ++++++++++
 include/uapi/linux/ioprio.h |  2 --
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/linux/ioprio.h b/include/linux/ioprio.h
index ef9ad4fb245f..2ee3373684b1 100644
--- a/include/linux/ioprio.h
+++ b/include/linux/ioprio.h
@@ -8,6 +8,16 @@
 
 #include <uapi/linux/ioprio.h>
 
+/*
+ * Check that a priority value has a valid class.
+ */
+static inline bool ioprio_valid(unsigned short ioprio)
+{
+	unsigned short class = IOPRIO_PRIO_CLASS(ioprio);
+
+	return class > IOPRIO_CLASS_NONE && class <= IOPRIO_CLASS_IDLE;
+}
+
 /*
  * if process has set io priority explicitly, use that. if not, convert
  * the cpu scheduler nice value to an io priority
diff --git a/include/uapi/linux/ioprio.h b/include/uapi/linux/ioprio.h
index 6b735854aebd..5064e230374c 100644
--- a/include/uapi/linux/ioprio.h
+++ b/include/uapi/linux/ioprio.h
@@ -27,8 +27,6 @@ enum {
 	IOPRIO_CLASS_IDLE,
 };
 
-#define ioprio_valid(mask)	(IOPRIO_PRIO_CLASS((mask)) != IOPRIO_CLASS_NONE)
-
 /*
  * 8 best effort priority levels are supported
  */
-- 
2.31.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 4/6] block: fix IOPRIO_PRIO_CLASS() and IOPRIO_PRIO_VALUE() macros
  2021-08-11  3:36 ` [f2fs-dev] " Damien Le Moal
@ 2021-08-11  3:37   ` Damien Le Moal
  -1 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-11  3:37 UTC (permalink / raw)
  To: Jens Axboe, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

The ki_ioprio field of struct kiocb is 16-bits (u16) but often handled
as an int in the block layer. E.g. ioprio_check_cap() takes an int as
argument.

With such implicit int casting function calls, the upper 16-bits of the
int argument may be left uninitialized by the compiler, resulting in
invalid values for the IOPRIO_PRIO_CLASS() macro (garbage upper bits)
and in an error return for functions such as ioprio_check_cap().

Fix this by masking the result of the shift by IOPRIO_CLASS_SHIFT bits
in the IOPRIO_PRIO_CLASS() macro. The new macro IOPRIO_CLASS_MASK
defines the 3-bits mask for the priority class.
Similarly, apply the IOPRIO_PRIO_MASK mask to the data argument of the
IOPRIO_PRIO_VALUE() macro to ignore the upper bits of the data value.
The IOPRIO_CLASS_MASK mask is also applied to the class argument of this
macro before shifting the result by IOPRIO_CLASS_SHIFT bits.

While at it, also change the argument name of the IOPRIO_PRIO_CLASS()
and IOPRIO_PRIO_DATA() macros from "mask" to "ioprio" to reflect the
fact that a priority value should be passed rather than a mask.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 include/uapi/linux/ioprio.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/include/uapi/linux/ioprio.h b/include/uapi/linux/ioprio.h
index 5064e230374c..936f0d8f30e1 100644
--- a/include/uapi/linux/ioprio.h
+++ b/include/uapi/linux/ioprio.h
@@ -5,12 +5,16 @@
 /*
  * Gives us 8 prio classes with 13-bits of data for each class
  */
-#define IOPRIO_CLASS_SHIFT	(13)
+#define IOPRIO_CLASS_SHIFT	13
+#define IOPRIO_CLASS_MASK	0x07
 #define IOPRIO_PRIO_MASK	((1UL << IOPRIO_CLASS_SHIFT) - 1)
 
-#define IOPRIO_PRIO_CLASS(mask)	((mask) >> IOPRIO_CLASS_SHIFT)
-#define IOPRIO_PRIO_DATA(mask)	((mask) & IOPRIO_PRIO_MASK)
-#define IOPRIO_PRIO_VALUE(class, data)	(((class) << IOPRIO_CLASS_SHIFT) | data)
+#define IOPRIO_PRIO_CLASS(ioprio)	\
+	(((ioprio) >> IOPRIO_CLASS_SHIFT) & IOPRIO_CLASS_MASK)
+#define IOPRIO_PRIO_DATA(ioprio)	((ioprio) & IOPRIO_PRIO_MASK)
+#define IOPRIO_PRIO_VALUE(class, data)	\
+	((((class) & IOPRIO_CLASS_MASK) << IOPRIO_CLASS_SHIFT) | \
+	 ((data) & IOPRIO_PRIO_MASK))
 
 /*
  * These are the io priority groups as implemented by the BFQ and mq-deadline
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [f2fs-dev] [PATCH v4 4/6] block: fix IOPRIO_PRIO_CLASS() and IOPRIO_PRIO_VALUE() macros
@ 2021-08-11  3:37   ` Damien Le Moal
  0 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-11  3:37 UTC (permalink / raw)
  To: Jens Axboe, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

The ki_ioprio field of struct kiocb is 16-bits (u16) but often handled
as an int in the block layer. E.g. ioprio_check_cap() takes an int as
argument.

With such implicit int casting function calls, the upper 16-bits of the
int argument may be left uninitialized by the compiler, resulting in
invalid values for the IOPRIO_PRIO_CLASS() macro (garbage upper bits)
and in an error return for functions such as ioprio_check_cap().

Fix this by masking the result of the shift by IOPRIO_CLASS_SHIFT bits
in the IOPRIO_PRIO_CLASS() macro. The new macro IOPRIO_CLASS_MASK
defines the 3-bits mask for the priority class.
Similarly, apply the IOPRIO_PRIO_MASK mask to the data argument of the
IOPRIO_PRIO_VALUE() macro to ignore the upper bits of the data value.
The IOPRIO_CLASS_MASK mask is also applied to the class argument of this
macro before shifting the result by IOPRIO_CLASS_SHIFT bits.

While at it, also change the argument name of the IOPRIO_PRIO_CLASS()
and IOPRIO_PRIO_DATA() macros from "mask" to "ioprio" to reflect the
fact that a priority value should be passed rather than a mask.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 include/uapi/linux/ioprio.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/include/uapi/linux/ioprio.h b/include/uapi/linux/ioprio.h
index 5064e230374c..936f0d8f30e1 100644
--- a/include/uapi/linux/ioprio.h
+++ b/include/uapi/linux/ioprio.h
@@ -5,12 +5,16 @@
 /*
  * Gives us 8 prio classes with 13-bits of data for each class
  */
-#define IOPRIO_CLASS_SHIFT	(13)
+#define IOPRIO_CLASS_SHIFT	13
+#define IOPRIO_CLASS_MASK	0x07
 #define IOPRIO_PRIO_MASK	((1UL << IOPRIO_CLASS_SHIFT) - 1)
 
-#define IOPRIO_PRIO_CLASS(mask)	((mask) >> IOPRIO_CLASS_SHIFT)
-#define IOPRIO_PRIO_DATA(mask)	((mask) & IOPRIO_PRIO_MASK)
-#define IOPRIO_PRIO_VALUE(class, data)	(((class) << IOPRIO_CLASS_SHIFT) | data)
+#define IOPRIO_PRIO_CLASS(ioprio)	\
+	(((ioprio) >> IOPRIO_CLASS_SHIFT) & IOPRIO_CLASS_MASK)
+#define IOPRIO_PRIO_DATA(ioprio)	((ioprio) & IOPRIO_PRIO_MASK)
+#define IOPRIO_PRIO_VALUE(class, data)	\
+	((((class) & IOPRIO_CLASS_MASK) << IOPRIO_CLASS_SHIFT) | \
+	 ((data) & IOPRIO_PRIO_MASK))
 
 /*
  * These are the io priority groups as implemented by the BFQ and mq-deadline
-- 
2.31.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 5/6] block: Introduce IOPRIO_NR_LEVELS
  2021-08-11  3:36 ` [f2fs-dev] " Damien Le Moal
@ 2021-08-11  3:37   ` Damien Le Moal
  -1 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-11  3:37 UTC (permalink / raw)
  To: Jens Axboe, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

The BFQ scheduler and ioprio_check_cap() both assume that the RT
priority class (IOPRIO_CLASS_RT) can have up to 8 different priority
levels, similarly to the BE class (IOPRIO_CLASS_iBE). This is
controlled using the IOPRIO_BE_NR macro , which is badly named as the
number of levels also applies to the RT class.

Introduce the class independent IOPRIO_NR_LEVELS macro, defined to 8,
to make things clear. Keep the old IOPRIO_BE_NR macro definition as an
alias for IOPRIO_NR_LEVELS.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 block/bfq-iosched.c         | 8 ++++----
 block/bfq-iosched.h         | 4 ++--
 block/bfq-wf2q.c            | 6 +++---
 block/ioprio.c              | 3 +--
 fs/f2fs/sysfs.c             | 2 +-
 include/uapi/linux/ioprio.h | 5 +++--
 6 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index e546a5f4bff9..4b434369e411 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -2508,7 +2508,7 @@ void bfq_end_wr_async_queues(struct bfq_data *bfqd,
 	int i, j;
 
 	for (i = 0; i < 2; i++)
-		for (j = 0; j < IOPRIO_BE_NR; j++)
+		for (j = 0; j < IOPRIO_NR_LEVELS; j++)
 			if (bfqg->async_bfqq[i][j])
 				bfq_bfqq_end_wr(bfqg->async_bfqq[i][j]);
 	if (bfqg->async_idle_bfqq)
@@ -5293,10 +5293,10 @@ bfq_set_next_ioprio_data(struct bfq_queue *bfqq, struct bfq_io_cq *bic)
 		break;
 	}
 
-	if (bfqq->new_ioprio >= IOPRIO_BE_NR) {
+	if (bfqq->new_ioprio >= IOPRIO_NR_LEVELS) {
 		pr_crit("bfq_set_next_ioprio_data: new_ioprio %d\n",
 			bfqq->new_ioprio);
-		bfqq->new_ioprio = IOPRIO_BE_NR - 1;
+		bfqq->new_ioprio = IOPRIO_NR_LEVELS - 1;
 	}
 
 	bfqq->entity.new_weight = bfq_ioprio_to_weight(bfqq->new_ioprio);
@@ -6825,7 +6825,7 @@ void bfq_put_async_queues(struct bfq_data *bfqd, struct bfq_group *bfqg)
 	int i, j;
 
 	for (i = 0; i < 2; i++)
-		for (j = 0; j < IOPRIO_BE_NR; j++)
+		for (j = 0; j < IOPRIO_NR_LEVELS; j++)
 			__bfq_put_async_bfqq(bfqd, &bfqg->async_bfqq[i][j]);
 
 	__bfq_put_async_bfqq(bfqd, &bfqg->async_idle_bfqq);
diff --git a/block/bfq-iosched.h b/block/bfq-iosched.h
index 99c2a3cb081e..385e28a843d1 100644
--- a/block/bfq-iosched.h
+++ b/block/bfq-iosched.h
@@ -931,7 +931,7 @@ struct bfq_group {
 
 	void *bfqd;
 
-	struct bfq_queue *async_bfqq[2][IOPRIO_BE_NR];
+	struct bfq_queue *async_bfqq[2][IOPRIO_NR_LEVELS];
 	struct bfq_queue *async_idle_bfqq;
 
 	struct bfq_entity *my_entity;
@@ -948,7 +948,7 @@ struct bfq_group {
 	struct bfq_entity entity;
 	struct bfq_sched_data sched_data;
 
-	struct bfq_queue *async_bfqq[2][IOPRIO_BE_NR];
+	struct bfq_queue *async_bfqq[2][IOPRIO_NR_LEVELS];
 	struct bfq_queue *async_idle_bfqq;
 
 	struct rb_root rq_pos_tree;
diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c
index 7a462df71f68..b74cc0da118e 100644
--- a/block/bfq-wf2q.c
+++ b/block/bfq-wf2q.c
@@ -505,7 +505,7 @@ static void bfq_active_insert(struct bfq_service_tree *st,
  */
 unsigned short bfq_ioprio_to_weight(int ioprio)
 {
-	return (IOPRIO_BE_NR - ioprio) * BFQ_WEIGHT_CONVERSION_COEFF;
+	return (IOPRIO_NR_LEVELS - ioprio) * BFQ_WEIGHT_CONVERSION_COEFF;
 }
 
 /**
@@ -514,12 +514,12 @@ unsigned short bfq_ioprio_to_weight(int ioprio)
  *
  * To preserve as much as possible the old only-ioprio user interface,
  * 0 is used as an escape ioprio value for weights (numerically) equal or
- * larger than IOPRIO_BE_NR * BFQ_WEIGHT_CONVERSION_COEFF.
+ * larger than IOPRIO_NR_LEVELS * BFQ_WEIGHT_CONVERSION_COEFF.
  */
 static unsigned short bfq_weight_to_ioprio(int weight)
 {
 	return max_t(int, 0,
-		     IOPRIO_BE_NR * BFQ_WEIGHT_CONVERSION_COEFF - weight);
+		     IOPRIO_NR_LEVELS * BFQ_WEIGHT_CONVERSION_COEFF - weight);
 }
 
 static void bfq_get_entity(struct bfq_entity *entity)
diff --git a/block/ioprio.c b/block/ioprio.c
index bee628f9f1b2..ca6b136c5586 100644
--- a/block/ioprio.c
+++ b/block/ioprio.c
@@ -74,9 +74,8 @@ int ioprio_check_cap(int ioprio)
 			fallthrough;
 			/* rt has prio field too */
 		case IOPRIO_CLASS_BE:
-			if (data >= IOPRIO_BE_NR || data < 0)
+			if (data >= IOPRIO_NR_LEVELS || data < 0)
 				return -EINVAL;
-
 			break;
 		case IOPRIO_CLASS_IDLE:
 			break;
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index 6642246206bd..daad532a4e2b 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -378,7 +378,7 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
 		ret = kstrtol(name, 10, &data);
 		if (ret)
 			return ret;
-		if (data >= IOPRIO_BE_NR || data < 0)
+		if (data >= IOPRIO_NR_LEVELS || data < 0)
 			return -EINVAL;
 
 		cprc->ckpt_thread_ioprio = IOPRIO_PRIO_VALUE(class, data);
diff --git a/include/uapi/linux/ioprio.h b/include/uapi/linux/ioprio.h
index 936f0d8f30e1..aac39338d02c 100644
--- a/include/uapi/linux/ioprio.h
+++ b/include/uapi/linux/ioprio.h
@@ -32,9 +32,10 @@ enum {
 };
 
 /*
- * 8 best effort priority levels are supported
+ * The RT and BE priority classes both support up to 8 priority levels.
  */
-#define IOPRIO_BE_NR	(8)
+#define IOPRIO_NR_LEVELS	8
+#define IOPRIO_BE_NR		IOPRIO_NR_LEVELS
 
 enum {
 	IOPRIO_WHO_PROCESS = 1,
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [f2fs-dev] [PATCH v4 5/6] block: Introduce IOPRIO_NR_LEVELS
@ 2021-08-11  3:37   ` Damien Le Moal
  0 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-11  3:37 UTC (permalink / raw)
  To: Jens Axboe, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

The BFQ scheduler and ioprio_check_cap() both assume that the RT
priority class (IOPRIO_CLASS_RT) can have up to 8 different priority
levels, similarly to the BE class (IOPRIO_CLASS_iBE). This is
controlled using the IOPRIO_BE_NR macro , which is badly named as the
number of levels also applies to the RT class.

Introduce the class independent IOPRIO_NR_LEVELS macro, defined to 8,
to make things clear. Keep the old IOPRIO_BE_NR macro definition as an
alias for IOPRIO_NR_LEVELS.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 block/bfq-iosched.c         | 8 ++++----
 block/bfq-iosched.h         | 4 ++--
 block/bfq-wf2q.c            | 6 +++---
 block/ioprio.c              | 3 +--
 fs/f2fs/sysfs.c             | 2 +-
 include/uapi/linux/ioprio.h | 5 +++--
 6 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index e546a5f4bff9..4b434369e411 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -2508,7 +2508,7 @@ void bfq_end_wr_async_queues(struct bfq_data *bfqd,
 	int i, j;
 
 	for (i = 0; i < 2; i++)
-		for (j = 0; j < IOPRIO_BE_NR; j++)
+		for (j = 0; j < IOPRIO_NR_LEVELS; j++)
 			if (bfqg->async_bfqq[i][j])
 				bfq_bfqq_end_wr(bfqg->async_bfqq[i][j]);
 	if (bfqg->async_idle_bfqq)
@@ -5293,10 +5293,10 @@ bfq_set_next_ioprio_data(struct bfq_queue *bfqq, struct bfq_io_cq *bic)
 		break;
 	}
 
-	if (bfqq->new_ioprio >= IOPRIO_BE_NR) {
+	if (bfqq->new_ioprio >= IOPRIO_NR_LEVELS) {
 		pr_crit("bfq_set_next_ioprio_data: new_ioprio %d\n",
 			bfqq->new_ioprio);
-		bfqq->new_ioprio = IOPRIO_BE_NR - 1;
+		bfqq->new_ioprio = IOPRIO_NR_LEVELS - 1;
 	}
 
 	bfqq->entity.new_weight = bfq_ioprio_to_weight(bfqq->new_ioprio);
@@ -6825,7 +6825,7 @@ void bfq_put_async_queues(struct bfq_data *bfqd, struct bfq_group *bfqg)
 	int i, j;
 
 	for (i = 0; i < 2; i++)
-		for (j = 0; j < IOPRIO_BE_NR; j++)
+		for (j = 0; j < IOPRIO_NR_LEVELS; j++)
 			__bfq_put_async_bfqq(bfqd, &bfqg->async_bfqq[i][j]);
 
 	__bfq_put_async_bfqq(bfqd, &bfqg->async_idle_bfqq);
diff --git a/block/bfq-iosched.h b/block/bfq-iosched.h
index 99c2a3cb081e..385e28a843d1 100644
--- a/block/bfq-iosched.h
+++ b/block/bfq-iosched.h
@@ -931,7 +931,7 @@ struct bfq_group {
 
 	void *bfqd;
 
-	struct bfq_queue *async_bfqq[2][IOPRIO_BE_NR];
+	struct bfq_queue *async_bfqq[2][IOPRIO_NR_LEVELS];
 	struct bfq_queue *async_idle_bfqq;
 
 	struct bfq_entity *my_entity;
@@ -948,7 +948,7 @@ struct bfq_group {
 	struct bfq_entity entity;
 	struct bfq_sched_data sched_data;
 
-	struct bfq_queue *async_bfqq[2][IOPRIO_BE_NR];
+	struct bfq_queue *async_bfqq[2][IOPRIO_NR_LEVELS];
 	struct bfq_queue *async_idle_bfqq;
 
 	struct rb_root rq_pos_tree;
diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c
index 7a462df71f68..b74cc0da118e 100644
--- a/block/bfq-wf2q.c
+++ b/block/bfq-wf2q.c
@@ -505,7 +505,7 @@ static void bfq_active_insert(struct bfq_service_tree *st,
  */
 unsigned short bfq_ioprio_to_weight(int ioprio)
 {
-	return (IOPRIO_BE_NR - ioprio) * BFQ_WEIGHT_CONVERSION_COEFF;
+	return (IOPRIO_NR_LEVELS - ioprio) * BFQ_WEIGHT_CONVERSION_COEFF;
 }
 
 /**
@@ -514,12 +514,12 @@ unsigned short bfq_ioprio_to_weight(int ioprio)
  *
  * To preserve as much as possible the old only-ioprio user interface,
  * 0 is used as an escape ioprio value for weights (numerically) equal or
- * larger than IOPRIO_BE_NR * BFQ_WEIGHT_CONVERSION_COEFF.
+ * larger than IOPRIO_NR_LEVELS * BFQ_WEIGHT_CONVERSION_COEFF.
  */
 static unsigned short bfq_weight_to_ioprio(int weight)
 {
 	return max_t(int, 0,
-		     IOPRIO_BE_NR * BFQ_WEIGHT_CONVERSION_COEFF - weight);
+		     IOPRIO_NR_LEVELS * BFQ_WEIGHT_CONVERSION_COEFF - weight);
 }
 
 static void bfq_get_entity(struct bfq_entity *entity)
diff --git a/block/ioprio.c b/block/ioprio.c
index bee628f9f1b2..ca6b136c5586 100644
--- a/block/ioprio.c
+++ b/block/ioprio.c
@@ -74,9 +74,8 @@ int ioprio_check_cap(int ioprio)
 			fallthrough;
 			/* rt has prio field too */
 		case IOPRIO_CLASS_BE:
-			if (data >= IOPRIO_BE_NR || data < 0)
+			if (data >= IOPRIO_NR_LEVELS || data < 0)
 				return -EINVAL;
-
 			break;
 		case IOPRIO_CLASS_IDLE:
 			break;
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index 6642246206bd..daad532a4e2b 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -378,7 +378,7 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
 		ret = kstrtol(name, 10, &data);
 		if (ret)
 			return ret;
-		if (data >= IOPRIO_BE_NR || data < 0)
+		if (data >= IOPRIO_NR_LEVELS || data < 0)
 			return -EINVAL;
 
 		cprc->ckpt_thread_ioprio = IOPRIO_PRIO_VALUE(class, data);
diff --git a/include/uapi/linux/ioprio.h b/include/uapi/linux/ioprio.h
index 936f0d8f30e1..aac39338d02c 100644
--- a/include/uapi/linux/ioprio.h
+++ b/include/uapi/linux/ioprio.h
@@ -32,9 +32,10 @@ enum {
 };
 
 /*
- * 8 best effort priority levels are supported
+ * The RT and BE priority classes both support up to 8 priority levels.
  */
-#define IOPRIO_BE_NR	(8)
+#define IOPRIO_NR_LEVELS	8
+#define IOPRIO_BE_NR		IOPRIO_NR_LEVELS
 
 enum {
 	IOPRIO_WHO_PROCESS = 1,
-- 
2.31.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 6/6] block: fix default IO priority handling
  2021-08-11  3:36 ` [f2fs-dev] " Damien Le Moal
@ 2021-08-11  3:37   ` Damien Le Moal
  -1 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-11  3:37 UTC (permalink / raw)
  To: Jens Axboe, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

The default IO priority is the best effort (BE) class with the
normal priority level IOPRIO_NORM (4). However, get_task_ioprio()
returns IOPRIO_CLASS_NONE/IOPRIO_NORM as the default priority and
get_current_ioprio() returns IOPRIO_CLASS_NONE/0. Let's be consistent
with the defined default and have both of these functions return the
default priority IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_NORM) when
the user did not define another default IO priority for the task.

In include/uapi/linux/ioprio.h, introduce the IOPRIO_BE_NORM macro as
an alias to IOPRIO_NORM to clarify that this default level applies to
the BE priotity class. In include/linux/ioprio.h, define the macro
IOPRIO_DEFAULT as IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM)
and use this new macro when setting a priority to the default.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 block/bfq-iosched.c          | 2 +-
 block/ioprio.c               | 6 +++---
 drivers/nvme/host/lightnvm.c | 2 +-
 include/linux/ioprio.h       | 7 ++++++-
 include/uapi/linux/ioprio.h  | 5 +++--
 5 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 4b434369e411..e92bc0348433 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -5411,7 +5411,7 @@ static struct bfq_queue **bfq_async_queue_prio(struct bfq_data *bfqd,
 	case IOPRIO_CLASS_RT:
 		return &bfqg->async_bfqq[0][ioprio];
 	case IOPRIO_CLASS_NONE:
-		ioprio = IOPRIO_NORM;
+		ioprio = IOPRIO_BE_NORM;
 		fallthrough;
 	case IOPRIO_CLASS_BE:
 		return &bfqg->async_bfqq[1][ioprio];
diff --git a/block/ioprio.c b/block/ioprio.c
index ca6b136c5586..0e4ff245f2bf 100644
--- a/block/ioprio.c
+++ b/block/ioprio.c
@@ -170,7 +170,7 @@ static int get_task_ioprio(struct task_struct *p)
 	ret = security_task_getioprio(p);
 	if (ret)
 		goto out;
-	ret = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, IOPRIO_NORM);
+	ret = IOPRIO_DEFAULT;
 	task_lock(p);
 	if (p->io_context)
 		ret = p->io_context->ioprio;
@@ -182,9 +182,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_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_NORM);
+		aprio = IOPRIO_DEFAULT;
 	if (!ioprio_valid(bprio))
-		bprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_NORM);
+		bprio = IOPRIO_DEFAULT;
 
 	return min(aprio, bprio);
 }
diff --git a/drivers/nvme/host/lightnvm.c b/drivers/nvme/host/lightnvm.c
index e9d9ad47f70f..0fbbff0b3edb 100644
--- a/drivers/nvme/host/lightnvm.c
+++ b/drivers/nvme/host/lightnvm.c
@@ -662,7 +662,7 @@ static struct request *nvme_nvm_alloc_request(struct request_queue *q,
 	if (rqd->bio)
 		blk_rq_append_bio(rq, rqd->bio);
 	else
-		rq->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_NORM);
+		rq->ioprio = IOPRIO_DEFAULT;
 
 	return rq;
 }
diff --git a/include/linux/ioprio.h b/include/linux/ioprio.h
index 2ee3373684b1..3f53bc27a19b 100644
--- a/include/linux/ioprio.h
+++ b/include/linux/ioprio.h
@@ -8,6 +8,11 @@
 
 #include <uapi/linux/ioprio.h>
 
+/*
+ * Default IO priority.
+ */
+#define IOPRIO_DEFAULT	IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM)
+
 /*
  * Check that a priority value has a valid class.
  */
@@ -51,7 +56,7 @@ static inline int get_current_ioprio(void)
 
 	if (ioc)
 		return ioc->ioprio;
-	return IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0);
+	return IOPRIO_DEFAULT;
 }
 
 /*
diff --git a/include/uapi/linux/ioprio.h b/include/uapi/linux/ioprio.h
index aac39338d02c..f70f2596a6bf 100644
--- a/include/uapi/linux/ioprio.h
+++ b/include/uapi/linux/ioprio.h
@@ -44,8 +44,9 @@ enum {
 };
 
 /*
- * Fallback BE priority
+ * Fallback BE priority level.
  */
-#define IOPRIO_NORM	(4)
+#define IOPRIO_NORM	4
+#define IOPRIO_BE_NORM	IOPRIO_NORM
 
 #endif /* _UAPI_LINUX_IOPRIO_H */
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [f2fs-dev] [PATCH v4 6/6] block: fix default IO priority handling
@ 2021-08-11  3:37   ` Damien Le Moal
  0 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-11  3:37 UTC (permalink / raw)
  To: Jens Axboe, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

The default IO priority is the best effort (BE) class with the
normal priority level IOPRIO_NORM (4). However, get_task_ioprio()
returns IOPRIO_CLASS_NONE/IOPRIO_NORM as the default priority and
get_current_ioprio() returns IOPRIO_CLASS_NONE/0. Let's be consistent
with the defined default and have both of these functions return the
default priority IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_NORM) when
the user did not define another default IO priority for the task.

In include/uapi/linux/ioprio.h, introduce the IOPRIO_BE_NORM macro as
an alias to IOPRIO_NORM to clarify that this default level applies to
the BE priotity class. In include/linux/ioprio.h, define the macro
IOPRIO_DEFAULT as IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM)
and use this new macro when setting a priority to the default.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 block/bfq-iosched.c          | 2 +-
 block/ioprio.c               | 6 +++---
 drivers/nvme/host/lightnvm.c | 2 +-
 include/linux/ioprio.h       | 7 ++++++-
 include/uapi/linux/ioprio.h  | 5 +++--
 5 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 4b434369e411..e92bc0348433 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -5411,7 +5411,7 @@ static struct bfq_queue **bfq_async_queue_prio(struct bfq_data *bfqd,
 	case IOPRIO_CLASS_RT:
 		return &bfqg->async_bfqq[0][ioprio];
 	case IOPRIO_CLASS_NONE:
-		ioprio = IOPRIO_NORM;
+		ioprio = IOPRIO_BE_NORM;
 		fallthrough;
 	case IOPRIO_CLASS_BE:
 		return &bfqg->async_bfqq[1][ioprio];
diff --git a/block/ioprio.c b/block/ioprio.c
index ca6b136c5586..0e4ff245f2bf 100644
--- a/block/ioprio.c
+++ b/block/ioprio.c
@@ -170,7 +170,7 @@ static int get_task_ioprio(struct task_struct *p)
 	ret = security_task_getioprio(p);
 	if (ret)
 		goto out;
-	ret = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, IOPRIO_NORM);
+	ret = IOPRIO_DEFAULT;
 	task_lock(p);
 	if (p->io_context)
 		ret = p->io_context->ioprio;
@@ -182,9 +182,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_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_NORM);
+		aprio = IOPRIO_DEFAULT;
 	if (!ioprio_valid(bprio))
-		bprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_NORM);
+		bprio = IOPRIO_DEFAULT;
 
 	return min(aprio, bprio);
 }
diff --git a/drivers/nvme/host/lightnvm.c b/drivers/nvme/host/lightnvm.c
index e9d9ad47f70f..0fbbff0b3edb 100644
--- a/drivers/nvme/host/lightnvm.c
+++ b/drivers/nvme/host/lightnvm.c
@@ -662,7 +662,7 @@ static struct request *nvme_nvm_alloc_request(struct request_queue *q,
 	if (rqd->bio)
 		blk_rq_append_bio(rq, rqd->bio);
 	else
-		rq->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_NORM);
+		rq->ioprio = IOPRIO_DEFAULT;
 
 	return rq;
 }
diff --git a/include/linux/ioprio.h b/include/linux/ioprio.h
index 2ee3373684b1..3f53bc27a19b 100644
--- a/include/linux/ioprio.h
+++ b/include/linux/ioprio.h
@@ -8,6 +8,11 @@
 
 #include <uapi/linux/ioprio.h>
 
+/*
+ * Default IO priority.
+ */
+#define IOPRIO_DEFAULT	IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM)
+
 /*
  * Check that a priority value has a valid class.
  */
@@ -51,7 +56,7 @@ static inline int get_current_ioprio(void)
 
 	if (ioc)
 		return ioc->ioprio;
-	return IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0);
+	return IOPRIO_DEFAULT;
 }
 
 /*
diff --git a/include/uapi/linux/ioprio.h b/include/uapi/linux/ioprio.h
index aac39338d02c..f70f2596a6bf 100644
--- a/include/uapi/linux/ioprio.h
+++ b/include/uapi/linux/ioprio.h
@@ -44,8 +44,9 @@ enum {
 };
 
 /*
- * Fallback BE priority
+ * Fallback BE priority level.
  */
-#define IOPRIO_NORM	(4)
+#define IOPRIO_NORM	4
+#define IOPRIO_BE_NORM	IOPRIO_NORM
 
 #endif /* _UAPI_LINUX_IOPRIO_H */
-- 
2.31.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH v4 3/6] block: change ioprio_valid() to an inline function
  2021-08-11  3:36   ` [f2fs-dev] " Damien Le Moal
@ 2021-08-11  7:56     ` Johannes Thumshirn
  -1 siblings, 0 replies; 26+ messages in thread
From: Johannes Thumshirn @ 2021-08-11  7:56 UTC (permalink / raw)
  To: Damien Le Moal, Jens Axboe, linux-block, Paolo Valente,
	linux-f2fs-devel, Jaegeuk Kim, Chao Yu

On 11/08/2021 05:37, Damien Le Moal wrote:
> Change the ioprio_valid() macro in include/usapi/linux/ioprio.h to an                                        uapi ~^

> inline function declared on the kernel side in include/linux/ioprio.h.
> Also improve checks on the class value by checking the upper bound
> value.

But I think it needs to stay in include/uapi/linux/ioprio.h as it's there
since the 2.6.x days (I've checked back to v2.6.39.4) so the chance of
user-space using it is quite high.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [f2fs-dev] [PATCH v4 3/6] block: change ioprio_valid() to an inline function
@ 2021-08-11  7:56     ` Johannes Thumshirn
  0 siblings, 0 replies; 26+ messages in thread
From: Johannes Thumshirn @ 2021-08-11  7:56 UTC (permalink / raw)
  To: Damien Le Moal, Jens Axboe, linux-block, Paolo Valente,
	linux-f2fs-devel, Jaegeuk Kim, Chao Yu

On 11/08/2021 05:37, Damien Le Moal wrote:
> Change the ioprio_valid() macro in include/usapi/linux/ioprio.h to an                                        uapi ~^

> inline function declared on the kernel side in include/linux/ioprio.h.
> Also improve checks on the class value by checking the upper bound
> value.

But I think it needs to stay in include/uapi/linux/ioprio.h as it's there
since the 2.6.x days (I've checked back to v2.6.39.4) so the chance of
user-space using it is quite high.


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v4 3/6] block: change ioprio_valid() to an inline function
  2021-08-11  7:56     ` [f2fs-dev] " Johannes Thumshirn
@ 2021-08-11  8:51       ` Damien Le Moal
  -1 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-11  8:51 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe, linux-block, Paolo Valente,
	linux-f2fs-devel, Jaegeuk Kim, Chao Yu

On 2021/08/11 16:56, Johannes Thumshirn wrote:
> On 11/08/2021 05:37, Damien Le Moal wrote:
>> Change the ioprio_valid() macro in include/usapi/linux/ioprio.h to an                                        uapi ~^
> 
>> inline function declared on the kernel side in include/linux/ioprio.h.
>> Also improve checks on the class value by checking the upper bound
>> value.
> 
> But I think it needs to stay in include/uapi/linux/ioprio.h as it's there
> since the 2.6.x days (I've checked back to v2.6.39.4) so the chance of
> user-space using it is quite high.

include/uapi/linux/ioprio.h is being introduced with kernel 5.15. This user
header did not exist now and in previous kernels. include/linux/ioprio.h has
been around for a while though, but that is a kernel header, not an application
header.


-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [f2fs-dev] [PATCH v4 3/6] block: change ioprio_valid() to an inline function
@ 2021-08-11  8:51       ` Damien Le Moal
  0 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-11  8:51 UTC (permalink / raw)
  To: Johannes Thumshirn, Jens Axboe, linux-block, Paolo Valente,
	linux-f2fs-devel, Jaegeuk Kim, Chao Yu

On 2021/08/11 16:56, Johannes Thumshirn wrote:
> On 11/08/2021 05:37, Damien Le Moal wrote:
>> Change the ioprio_valid() macro in include/usapi/linux/ioprio.h to an                                        uapi ~^
> 
>> inline function declared on the kernel side in include/linux/ioprio.h.
>> Also improve checks on the class value by checking the upper bound
>> value.
> 
> But I think it needs to stay in include/uapi/linux/ioprio.h as it's there
> since the 2.6.x days (I've checked back to v2.6.39.4) so the chance of
> user-space using it is quite high.

include/uapi/linux/ioprio.h is being introduced with kernel 5.15. This user
header did not exist now and in previous kernels. include/linux/ioprio.h has
been around for a while though, but that is a kernel header, not an application
header.


-- 
Damien Le Moal
Western Digital Research


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v4 3/6] block: change ioprio_valid() to an inline function
  2021-08-11  8:51       ` [f2fs-dev] " Damien Le Moal
@ 2021-08-11  9:14         ` Johannes Thumshirn
  -1 siblings, 0 replies; 26+ messages in thread
From: Johannes Thumshirn @ 2021-08-11  9:14 UTC (permalink / raw)
  To: Damien Le Moal, Jens Axboe, linux-block, Paolo Valente,
	linux-f2fs-devel, Jaegeuk Kim, Chao Yu

On 11/08/2021 10:51, Damien Le Moal wrote:
> On 2021/08/11 16:56, Johannes Thumshirn wrote:
>> On 11/08/2021 05:37, Damien Le Moal wrote:
>>> Change the ioprio_valid() macro in include/usapi/linux/ioprio.h to an                                        uapi ~^
>>
>>> inline function declared on the kernel side in include/linux/ioprio.h.
>>> Also improve checks on the class value by checking the upper bound
>>> value.
>>
>> But I think it needs to stay in include/uapi/linux/ioprio.h as it's there
>> since the 2.6.x days (I've checked back to v2.6.39.4) so the chance of
>> user-space using it is quite high.
> 
> include/uapi/linux/ioprio.h is being introduced with kernel 5.15. This user
> header did not exist now and in previous kernels. include/linux/ioprio.h has
> been around for a while though, but that is a kernel header, not an application
> header.
> 
> 

Ah ok this was the now or never one, I thought it was about one of the constants.
Sorry for the noise.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [f2fs-dev] [PATCH v4 3/6] block: change ioprio_valid() to an inline function
@ 2021-08-11  9:14         ` Johannes Thumshirn
  0 siblings, 0 replies; 26+ messages in thread
From: Johannes Thumshirn @ 2021-08-11  9:14 UTC (permalink / raw)
  To: Damien Le Moal, Jens Axboe, linux-block, Paolo Valente,
	linux-f2fs-devel, Jaegeuk Kim, Chao Yu

On 11/08/2021 10:51, Damien Le Moal wrote:
> On 2021/08/11 16:56, Johannes Thumshirn wrote:
>> On 11/08/2021 05:37, Damien Le Moal wrote:
>>> Change the ioprio_valid() macro in include/usapi/linux/ioprio.h to an                                        uapi ~^
>>
>>> inline function declared on the kernel side in include/linux/ioprio.h.
>>> Also improve checks on the class value by checking the upper bound
>>> value.
>>
>> But I think it needs to stay in include/uapi/linux/ioprio.h as it's there
>> since the 2.6.x days (I've checked back to v2.6.39.4) so the chance of
>> user-space using it is quite high.
> 
> include/uapi/linux/ioprio.h is being introduced with kernel 5.15. This user
> header did not exist now and in previous kernels. include/linux/ioprio.h has
> been around for a while though, but that is a kernel header, not an application
> header.
> 
> 

Ah ok this was the now or never one, I thought it was about one of the constants.
Sorry for the noise.


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v4 0/6] IO priority fixes and improvements
  2021-08-11  3:36 ` [f2fs-dev] " Damien Le Moal
@ 2021-08-18  9:53   ` Damien Le Moal
  -1 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-18  9:53 UTC (permalink / raw)
  To: Jens Axboe, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

On 2021/08/11 12:37, Damien Le Moal wrote:
> This series fixes problems with IO priority values handling and cleans
> up several macro names and code for clarity.

Jens,

Any comment on this ?

> 
> Changes from v3:
> * Split former patch 2 into patches 2, 3 and 4 to facilitate review and
>   have more descriptive commit titles.
> * In patch 5, keep IOPRIO_BE_NR as an alias for the new IOPRIO_NR_LEVELS
>   macro. Change this patch title and commit message accordingly.
> * In patch 6, define IOPRIO_BE_NORM as an alias of IOPRIO_NORM.
> 
> Changes from v2:
> * Fixed typo in a comment in patch 3
> * Added reviewed-by tags
> 
> Changes from v1:
> * Added patch 4 to unify the default priority value used in various
>   places.
> * Fixed patch 2 as suggested by Bart: remove extra parenthesis and move
>   ioprio_valid() from the uapi header to the kernel header.
> * In patch 2, add priority value masking.
> 
> Damien Le Moal (6):
>   block: bfq: fix bfq_set_next_ioprio_data()
>   block: improve ioprio class description comment
>   block: change ioprio_valid() to an inline function
>   block: fix IOPRIO_PRIO_CLASS() and IOPRIO_PRIO_VALUE() macros
>   block: Introduce IOPRIO_NR_LEVELS
>   block: fix default IO priority handling
> 
>  block/bfq-iosched.c          | 10 +++++-----
>  block/bfq-iosched.h          |  4 ++--
>  block/bfq-wf2q.c             |  6 +++---
>  block/ioprio.c               |  9 ++++-----
>  drivers/nvme/host/lightnvm.c |  2 +-
>  fs/f2fs/sysfs.c              |  2 +-
>  include/linux/ioprio.h       | 17 ++++++++++++++++-
>  include/uapi/linux/ioprio.h  | 34 ++++++++++++++++++++--------------
>  8 files changed, 52 insertions(+), 32 deletions(-)
> 


-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [f2fs-dev] [PATCH v4 0/6] IO priority fixes and improvements
@ 2021-08-18  9:53   ` Damien Le Moal
  0 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-18  9:53 UTC (permalink / raw)
  To: Jens Axboe, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

On 2021/08/11 12:37, Damien Le Moal wrote:
> This series fixes problems with IO priority values handling and cleans
> up several macro names and code for clarity.

Jens,

Any comment on this ?

> 
> Changes from v3:
> * Split former patch 2 into patches 2, 3 and 4 to facilitate review and
>   have more descriptive commit titles.
> * In patch 5, keep IOPRIO_BE_NR as an alias for the new IOPRIO_NR_LEVELS
>   macro. Change this patch title and commit message accordingly.
> * In patch 6, define IOPRIO_BE_NORM as an alias of IOPRIO_NORM.
> 
> Changes from v2:
> * Fixed typo in a comment in patch 3
> * Added reviewed-by tags
> 
> Changes from v1:
> * Added patch 4 to unify the default priority value used in various
>   places.
> * Fixed patch 2 as suggested by Bart: remove extra parenthesis and move
>   ioprio_valid() from the uapi header to the kernel header.
> * In patch 2, add priority value masking.
> 
> Damien Le Moal (6):
>   block: bfq: fix bfq_set_next_ioprio_data()
>   block: improve ioprio class description comment
>   block: change ioprio_valid() to an inline function
>   block: fix IOPRIO_PRIO_CLASS() and IOPRIO_PRIO_VALUE() macros
>   block: Introduce IOPRIO_NR_LEVELS
>   block: fix default IO priority handling
> 
>  block/bfq-iosched.c          | 10 +++++-----
>  block/bfq-iosched.h          |  4 ++--
>  block/bfq-wf2q.c             |  6 +++---
>  block/ioprio.c               |  9 ++++-----
>  drivers/nvme/host/lightnvm.c |  2 +-
>  fs/f2fs/sysfs.c              |  2 +-
>  include/linux/ioprio.h       | 17 ++++++++++++++++-
>  include/uapi/linux/ioprio.h  | 34 ++++++++++++++++++++--------------
>  8 files changed, 52 insertions(+), 32 deletions(-)
> 


-- 
Damien Le Moal
Western Digital Research


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v4 0/6] IO priority fixes and improvements
  2021-08-11  3:36 ` [f2fs-dev] " Damien Le Moal
@ 2021-08-18 13:24   ` Jens Axboe
  -1 siblings, 0 replies; 26+ messages in thread
From: Jens Axboe @ 2021-08-18 13:24 UTC (permalink / raw)
  To: Damien Le Moal, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

On 8/10/21 9:36 PM, Damien Le Moal wrote:
> This series fixes problems with IO priority values handling and cleans
> up several macro names and code for clarity.

Applied for 5.15 - note that I dropped the lightnvm change from 6/6,
as it isn't strictly needed and lightnvm is deleted from the 5.15
drivers branch anyway.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [f2fs-dev] [PATCH v4 0/6] IO priority fixes and improvements
@ 2021-08-18 13:24   ` Jens Axboe
  0 siblings, 0 replies; 26+ messages in thread
From: Jens Axboe @ 2021-08-18 13:24 UTC (permalink / raw)
  To: Damien Le Moal, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

On 8/10/21 9:36 PM, Damien Le Moal wrote:
> This series fixes problems with IO priority values handling and cleans
> up several macro names and code for clarity.

Applied for 5.15 - note that I dropped the lightnvm change from 6/6,
as it isn't strictly needed and lightnvm is deleted from the 5.15
drivers branch anyway.

-- 
Jens Axboe



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v4 0/6] IO priority fixes and improvements
  2021-08-18 13:24   ` [f2fs-dev] " Jens Axboe
@ 2021-08-18 21:52     ` Damien Le Moal
  -1 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-18 21:52 UTC (permalink / raw)
  To: Jens Axboe, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

On 2021/08/18 22:24, Jens Axboe wrote:
> On 8/10/21 9:36 PM, Damien Le Moal wrote:
>> This series fixes problems with IO priority values handling and cleans
>> up several macro names and code for clarity.
> 
> Applied for 5.15 - note that I dropped the lightnvm change from 6/6,
> as it isn't strictly needed and lightnvm is deleted from the 5.15
> drivers branch anyway.

OK. Thanks !



-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [f2fs-dev] [PATCH v4 0/6] IO priority fixes and improvements
@ 2021-08-18 21:52     ` Damien Le Moal
  0 siblings, 0 replies; 26+ messages in thread
From: Damien Le Moal @ 2021-08-18 21:52 UTC (permalink / raw)
  To: Jens Axboe, linux-block, Paolo Valente, linux-f2fs-devel,
	Jaegeuk Kim, Chao Yu

On 2021/08/18 22:24, Jens Axboe wrote:
> On 8/10/21 9:36 PM, Damien Le Moal wrote:
>> This series fixes problems with IO priority values handling and cleans
>> up several macro names and code for clarity.
> 
> Applied for 5.15 - note that I dropped the lightnvm change from 6/6,
> as it isn't strictly needed and lightnvm is deleted from the 5.15
> drivers branch anyway.

OK. Thanks !



-- 
Damien Le Moal
Western Digital Research


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2021-08-18 21:52 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-11  3:36 [PATCH v4 0/6] IO priority fixes and improvements Damien Le Moal
2021-08-11  3:36 ` [f2fs-dev] " Damien Le Moal
2021-08-11  3:36 ` [PATCH v4 1/6] block: bfq: fix bfq_set_next_ioprio_data() Damien Le Moal
2021-08-11  3:36   ` [f2fs-dev] " Damien Le Moal
2021-08-11  3:36 ` [PATCH v4 2/6] block: improve ioprio class description comment Damien Le Moal
2021-08-11  3:36   ` [f2fs-dev] " Damien Le Moal
2021-08-11  3:36 ` [PATCH v4 3/6] block: change ioprio_valid() to an inline function Damien Le Moal
2021-08-11  3:36   ` [f2fs-dev] " Damien Le Moal
2021-08-11  7:56   ` Johannes Thumshirn
2021-08-11  7:56     ` [f2fs-dev] " Johannes Thumshirn
2021-08-11  8:51     ` Damien Le Moal
2021-08-11  8:51       ` [f2fs-dev] " Damien Le Moal
2021-08-11  9:14       ` Johannes Thumshirn
2021-08-11  9:14         ` [f2fs-dev] " Johannes Thumshirn
2021-08-11  3:37 ` [PATCH v4 4/6] block: fix IOPRIO_PRIO_CLASS() and IOPRIO_PRIO_VALUE() macros Damien Le Moal
2021-08-11  3:37   ` [f2fs-dev] " Damien Le Moal
2021-08-11  3:37 ` [PATCH v4 5/6] block: Introduce IOPRIO_NR_LEVELS Damien Le Moal
2021-08-11  3:37   ` [f2fs-dev] " Damien Le Moal
2021-08-11  3:37 ` [PATCH v4 6/6] block: fix default IO priority handling Damien Le Moal
2021-08-11  3:37   ` [f2fs-dev] " Damien Le Moal
2021-08-18  9:53 ` [PATCH v4 0/6] IO priority fixes and improvements Damien Le Moal
2021-08-18  9:53   ` [f2fs-dev] " Damien Le Moal
2021-08-18 13:24 ` Jens Axboe
2021-08-18 13:24   ` [f2fs-dev] " Jens Axboe
2021-08-18 21:52   ` Damien Le Moal
2021-08-18 21:52     ` [f2fs-dev] " Damien Le Moal

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.