Skip to content

Commit 0c368a1

Browse files
jankarasmb49
authored andcommitted
block: fix default IO priority handling again
BugLink: https://bugs.launchpad.net/bugs/1989221 commit e589f46445960c274cc813a1cc8e2fc73b2a1849 upstream. Commit e70344c ("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 e70344c 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 e70344c. 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. CC: [email protected] Fixes: e70344c ("block: fix default IO priority handling") Reviewed-by: Damien Le Moal <[email protected]> Tested-by: Damien Le Moal <[email protected]> Signed-off-by: Jan Kara <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Stefan Bader <[email protected]>
1 parent f1b4a78 commit 0c368a1

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

block/blk-ioc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ int create_task_io_context(struct task_struct *task, gfp_t gfp_flags, int node)
265265
INIT_RADIX_TREE(&ioc->icq_tree, GFP_ATOMIC);
266266
INIT_HLIST_HEAD(&ioc->icq_list);
267267
INIT_WORK(&ioc->release_work, ioc_release_fn);
268+
ioc->ioprio = IOPRIO_DEFAULT;
268269

269270
/*
270271
* Try to install. ioc shouldn't be installed if someone else

block/ioprio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ static int get_task_ioprio(struct task_struct *p)
189189
int ioprio_best(unsigned short aprio, unsigned short bprio)
190190
{
191191
if (!ioprio_valid(aprio))
192-
aprio = IOPRIO_DEFAULT;
192+
aprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM);
193193
if (!ioprio_valid(bprio))
194-
bprio = IOPRIO_DEFAULT;
194+
bprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM);
195195

196196
return min(aprio, bprio);
197197
}

include/linux/ioprio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/*
1212
* Default IO priority.
1313
*/
14-
#define IOPRIO_DEFAULT IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM)
14+
#define IOPRIO_DEFAULT IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0)
1515

1616
/*
1717
* Check that a priority value has a valid class.

0 commit comments

Comments
 (0)