Skip to content

Commit eca2040

Browse files
damien-lemoalmartinkpetersen
authored andcommitted
scsi: block: ioprio: Clean up interface definition
The I/O priority user interface defines the 16-bits ioprio values as the combination of the upper 3-bits for an I/O priority class and the lower 13-bits as priority data. However, the kernel only uses the lower 3-bits of the priority data to define priority levels for the RT and BE priority classes. The data part of an ioprio value is completely ignored for the IDLE and NONE classes. This is enforced by checks done in ioprio_check_cap(), which is called for all paths that allow defining an I/O priority for I/Os: the per-context ioprio_set() system call, aio interface and io_uring interface. Clarify this fact in the uapi ioprio.h header file and introduce the IOPRIO_PRIO_LEVEL_MASK and IOPRIO_PRIO_LEVEL() macros for users to define and get priority levels in an ioprio value. The coarser macro IOPRIO_PRIO_DATA() is retained for backward compatibility with old applications already using it. There is no functional change introduced with this. In-kernel users of the IOPRIO_PRIO_DATA() macro which are explicitly handling I/O priority data as a priority level are modified to use the new IOPRIO_PRIO_LEVEL() macro without any functional change. Since f2fs is the only user of this macro not explicitly using that value as a priority level, it is left unchanged. Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Niklas Cassel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent ac9a786 commit eca2040

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

block/bfq-iosched.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5524,16 +5524,16 @@ bfq_set_next_ioprio_data(struct bfq_queue *bfqq, struct bfq_io_cq *bic)
55245524
bfqq->new_ioprio_class = task_nice_ioclass(tsk);
55255525
break;
55265526
case IOPRIO_CLASS_RT:
5527-
bfqq->new_ioprio = IOPRIO_PRIO_DATA(bic->ioprio);
5527+
bfqq->new_ioprio = IOPRIO_PRIO_LEVEL(bic->ioprio);
55285528
bfqq->new_ioprio_class = IOPRIO_CLASS_RT;
55295529
break;
55305530
case IOPRIO_CLASS_BE:
5531-
bfqq->new_ioprio = IOPRIO_PRIO_DATA(bic->ioprio);
5531+
bfqq->new_ioprio = IOPRIO_PRIO_LEVEL(bic->ioprio);
55325532
bfqq->new_ioprio_class = IOPRIO_CLASS_BE;
55335533
break;
55345534
case IOPRIO_CLASS_IDLE:
55355535
bfqq->new_ioprio_class = IOPRIO_CLASS_IDLE;
5536-
bfqq->new_ioprio = 7;
5536+
bfqq->new_ioprio = IOPRIO_NR_LEVELS - 1;
55375537
break;
55385538
}
55395539

@@ -5830,7 +5830,7 @@ static struct bfq_queue *bfq_get_queue(struct bfq_data *bfqd,
58305830
struct bfq_io_cq *bic,
58315831
bool respawn)
58325832
{
5833-
const int ioprio = IOPRIO_PRIO_DATA(bic->ioprio);
5833+
const int ioprio = IOPRIO_PRIO_LEVEL(bic->ioprio);
58345834
const int ioprio_class = IOPRIO_PRIO_CLASS(bic->ioprio);
58355835
struct bfq_queue **async_bfqq = NULL;
58365836
struct bfq_queue *bfqq;

block/ioprio.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
int ioprio_check_cap(int ioprio)
3434
{
3535
int class = IOPRIO_PRIO_CLASS(ioprio);
36-
int data = IOPRIO_PRIO_DATA(ioprio);
36+
int level = IOPRIO_PRIO_LEVEL(ioprio);
3737

3838
switch (class) {
3939
case IOPRIO_CLASS_RT:
@@ -49,13 +49,13 @@ int ioprio_check_cap(int ioprio)
4949
fallthrough;
5050
/* rt has prio field too */
5151
case IOPRIO_CLASS_BE:
52-
if (data >= IOPRIO_NR_LEVELS || data < 0)
52+
if (level >= IOPRIO_NR_LEVELS)
5353
return -EINVAL;
5454
break;
5555
case IOPRIO_CLASS_IDLE:
5656
break;
5757
case IOPRIO_CLASS_NONE:
58-
if (data)
58+
if (level)
5959
return -EINVAL;
6060
break;
6161
default:

include/uapi/linux/ioprio.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
((data) & IOPRIO_PRIO_MASK))
1818

1919
/*
20-
* These are the io priority groups as implemented by the BFQ and mq-deadline
20+
* These are the io priority classes as implemented by the BFQ and mq-deadline
2121
* schedulers. RT is the realtime class, it always gets premium service. For
2222
* ATA disks supporting NCQ IO priority, RT class IOs will be processed using
2323
* high priority NCQ commands. BE is the best-effort scheduling class, the
@@ -32,19 +32,28 @@ enum {
3232
};
3333

3434
/*
35-
* The RT and BE priority classes both support up to 8 priority levels.
35+
* The RT and BE priority classes both support up to 8 priority levels that
36+
* can be specified using the lower 3-bits of the priority data.
3637
*/
37-
#define IOPRIO_NR_LEVELS 8
38-
#define IOPRIO_BE_NR IOPRIO_NR_LEVELS
38+
#define IOPRIO_LEVEL_NR_BITS 3
39+
#define IOPRIO_NR_LEVELS (1 << IOPRIO_LEVEL_NR_BITS)
40+
#define IOPRIO_LEVEL_MASK (IOPRIO_NR_LEVELS - 1)
41+
#define IOPRIO_PRIO_LEVEL(ioprio) ((ioprio) & IOPRIO_LEVEL_MASK)
3942

43+
#define IOPRIO_BE_NR IOPRIO_NR_LEVELS
44+
45+
/*
46+
* Possible values for the "which" argument of the ioprio_get() and
47+
* ioprio_set() system calls (see "man ioprio_set").
48+
*/
4049
enum {
4150
IOPRIO_WHO_PROCESS = 1,
4251
IOPRIO_WHO_PGRP,
4352
IOPRIO_WHO_USER,
4453
};
4554

4655
/*
47-
* Fallback BE priority level.
56+
* Fallback BE class priority level.
4857
*/
4958
#define IOPRIO_NORM 4
5059
#define IOPRIO_BE_NORM IOPRIO_NORM

0 commit comments

Comments
 (0)