History

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.

Damien Le Moal committed 3 years ago

Commit eca20401 parent ac9a7863 files · +21 −12Browse files

Unified · Split

3 files
  1. block/bfq-iosched.c +4 −4
  2. block/ioprio.c +3 −3
  3. include/uapi/linux/ioprio.h +14 −5
block/bfq-iosched.c+4−4
@@ -5524,16 +5524,16 @@ bfq_set_next_ioprio_data(struct bfq_queue *bfqq, struct bfq_io_cq *bic) · 5523 unmodified lines
5524 bfqq->new_ioprio_class = task_nice_ioclass(tsk);5524 bfqq->new_ioprio_class = task_nice_ioclass(tsk);
5525 break;5525 break;
5526 case IOPRIO_CLASS_RT:5526 case IOPRIO_CLASS_RT:
5527 bfqq->new_ioprio = IOPRIO_PRIO_DATA(bic->ioprio);5527 bfqq->new_ioprio = IOPRIO_PRIO_LEVEL(bic->ioprio);
5528 bfqq->new_ioprio_class = IOPRIO_CLASS_RT;5528 bfqq->new_ioprio_class = IOPRIO_CLASS_RT;
5529 break;5529 break;
5530 case IOPRIO_CLASS_BE:5530 case IOPRIO_CLASS_BE:
5531 bfqq->new_ioprio = IOPRIO_PRIO_DATA(bic->ioprio);5531 bfqq->new_ioprio = IOPRIO_PRIO_LEVEL(bic->ioprio);
5532 bfqq->new_ioprio_class = IOPRIO_CLASS_BE;5532 bfqq->new_ioprio_class = IOPRIO_CLASS_BE;
5533 break;5533 break;
5534 case IOPRIO_CLASS_IDLE:5534 case IOPRIO_CLASS_IDLE:
5535 bfqq->new_ioprio_class = IOPRIO_CLASS_IDLE;5535 bfqq->new_ioprio_class = IOPRIO_CLASS_IDLE;
5536 bfqq->new_ioprio = 7;5536 bfqq->new_ioprio = IOPRIO_NR_LEVELS - 1;
5537 break;5537 break;
5538 }5538 }
5539 5539
@@ -5830,7 +5830,7 @@ static struct bfq_queue *bfq_get_queue(struct bfq_data *bfqd, · 290 unmodified lines
5830 struct bfq_io_cq *bic,5830 struct bfq_io_cq *bic,
5831 bool respawn)5831 bool respawn)
5832{5832{
5833 const int ioprio = IOPRIO_PRIO_DATA(bic->ioprio);5833 const int ioprio = IOPRIO_PRIO_LEVEL(bic->ioprio);
5834 const int ioprio_class = IOPRIO_PRIO_CLASS(bic->ioprio);5834 const int ioprio_class = IOPRIO_PRIO_CLASS(bic->ioprio);
5835 struct bfq_queue **async_bfqq = NULL;5835 struct bfq_queue **async_bfqq = NULL;
5836 struct bfq_queue *bfqq;5836 struct bfq_queue *bfqq;
block/ioprio.c+3−3
@@ -33,7 +33,7 @@ · 32 unmodified lines
33int ioprio_check_cap(int ioprio)33int ioprio_check_cap(int ioprio)
34{34{
35 int class = IOPRIO_PRIO_CLASS(ioprio);35 int class = IOPRIO_PRIO_CLASS(ioprio);
36 int data = IOPRIO_PRIO_DATA(ioprio);36 int level = IOPRIO_PRIO_LEVEL(ioprio);
37 37
38 switch (class) {38 switch (class) {
39 case IOPRIO_CLASS_RT:39 case IOPRIO_CLASS_RT:
@@ -49,13 +49,13 @@ int ioprio_check_cap(int ioprio) · 9 unmodified lines
49 fallthrough;49 fallthrough;
50 /* rt has prio field too */50 /* rt has prio field too */
51 case IOPRIO_CLASS_BE:51 case IOPRIO_CLASS_BE:
52 if (data >= IOPRIO_NR_LEVELS || data < 0)52 if (level >= IOPRIO_NR_LEVELS)
53 return -EINVAL;53 return -EINVAL;
54 break;54 break;
55 case IOPRIO_CLASS_IDLE:55 case IOPRIO_CLASS_IDLE:
56 break;56 break;
57 case IOPRIO_CLASS_NONE:57 case IOPRIO_CLASS_NONE:
58 if (data)58 if (level)
59 return -EINVAL;59 return -EINVAL;
60 break;60 break;
61 default:61 default:
include/uapi/linux/ioprio.h+14−5
@@ -17,7 +17,7 @@ · 16 unmodified lines
17 ((data) & IOPRIO_PRIO_MASK))17 ((data) & IOPRIO_PRIO_MASK))
18 18
19/*19/*
20 * These are the io priority groups as implemented by the BFQ and mq-deadline20 * These are the io priority classes as implemented by the BFQ and mq-deadline
21 * schedulers. RT is the realtime class, it always gets premium service. For21 * schedulers. RT is the realtime class, it always gets premium service. For
22 * ATA disks supporting NCQ IO priority, RT class IOs will be processed using22 * ATA disks supporting NCQ IO priority, RT class IOs will be processed using
23 * high priority NCQ commands. BE is the best-effort scheduling class, the23 * high priority NCQ commands. BE is the best-effort scheduling class, the
@@ -32,11 +32,20 @@ enum { · 8 unmodified lines
32};32};
33 33
34/*34/*
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.
36 */37 */
37#define IOPRIO_NR_LEVELS 838#define IOPRIO_LEVEL_NR_BITS 3
38#define IOPRIO_BE_NR IOPRIO_NR_LEVELS39#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)
39 42
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 */
40enum {49enum {
41 IOPRIO_WHO_PROCESS = 1,50 IOPRIO_WHO_PROCESS = 1,
42 IOPRIO_WHO_PGRP,51 IOPRIO_WHO_PGRP,
@@ -44,7 +53,7 @@ enum { · 1 unmodified line
44};53};
45 54
46/*55/*
47 * Fallback BE priority level.56 * Fallback BE class priority level.
48 */57 */
49#define IOPRIO_NORM 458#define IOPRIO_NORM 4
50#define IOPRIO_BE_NORM IOPRIO_NORM59#define IOPRIO_BE_NORM IOPRIO_NORM

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t