completion: move blk_wait_io to kernel/sched/completion.c
Subsystems (4)
Mikulas Patocka
maintainerPATCH 1/2 completion: move blk_wait_io to kernel/sched/completion.c
The block layer has a function blk_wait_io - it works like wait_for_completion_io, except that it doesn't warn if the wait takes too long. This commit renames the function to wait_for_completion_long_io and moves it to kernel/sched/completion.c so that other kernel subsystems can use it. It will be needed by the dm-io subsystem.
--- block/bio.c | 2 +- block/blk-mq.c | 2 +- block/blk.h | 12 ------------ include/linux/completion.h | 1 + kernel/sched/completion.c | 20 ++++++++++++++++++++ 5 files changed, 23 insertions(+), 14 deletions(-)
block/blk.h +0 -12
@@ -72,18 +72,6 @@ static inline int bio_queue_enter(structreturn __bio_queue_enter (q, bio); } -static inline void blk_wait_io (struct completion *done) -{ -/* Prevent hang_check timer from firing at us during very long I/O */ -unsigned long timeout = sysctl_hung_task_timeout_secs *HZ /2 ; - -if (timeout) -while (!wait_for_completion_io_timeout (done, timeout)) - ; -else -wait_for_completion_io (done); -} -#define BIO_INLINE_VECS 4struct bio_vec *bvec_alloc (mempool_t *pool,unsigned short *nr_vecs,gfp_t gfp_mask);
include/linux/completion.h +1 -0
@@ -112,6 +112,7 @@ extern long wait_for_completion_interrup struct completion *x, unsigned long timeout);extern long wait_for_completion_killable_timeout (struct completion *x,unsigned long timeout); +extern void wait_for_completion_long_io (struct completion *x);extern bool try_wait_for_completion (struct completion *x);extern bool completion_done (struct completion *x);
block/bio.c +1 -1
@@ -1378,7 +1378,7 @@ int submit_bio_wait(struct bio *bio) bio->bi_end_io = submit_bio_wait_endio; bio->bi_opf |=REQ_SYNC ;submit_bio (bio); -blk_wait_io (&done); +wait_for_completion_long_io (&done);return blk_status_to_errno (bio->bi_status); }
block/blk-mq.c +1 -1
@@ -1407,7 +1407,7 @@ blk_status_t blk_execute_rq(struct requeif (blk_rq_is_poll (rq))blk_rq_poll_completion (rq, &wait.done);else -blk_wait_io (&wait.done); +wait_for_completion_long_io (&wait.done);return wait.ret; }
kernel/sched/completion.c +20 -0
@@ -290,6 +290,26 @@ wait_for_completion_killable_timeout(strEXPORT_SYMBOL (wait_for_completion_killable_timeout);/** +* wait_for_completion_long_io - waits for completion of a task +* @x: holds the state of this particular completion +* +* This is like wait_for_completion_io, but it doesn't warn if the wait takes +* too long. +*/ +void wait_for_completion_long_io (struct completion *x) +{ +/* Prevent hang_check timer from firing at us during very long I/O */ +unsigned long timeout = sysctl_hung_task_timeout_secs *HZ /2 ; + +if (timeout) +while (!wait_for_completion_io_timeout (x, timeout)) + ; +else +wait_for_completion_io (x); +} +EXPORT_SYMBOL (wait_for_completion_long_io); + +/** * try_wait_for_completion - try to decrement a completion without blocking * @x: completion structure *
Peter Zijlstra
maintainerQuoted 16 lines · Mikulas Patocka
Index:
linux-2.6/kernel/sched/completion.c
===================================================================kernel/sched/completion.c +8
-0@@ -290,6 +290,26 @@ wait_for_completion_killable_timeout(strEXPORT_SYMBOL (wait_for_completion_killable_timeout);/** +* wait_for_completion_long_io - waits for completion of a task +* @x: holds the state of this particular completion +* +* This is like wait_for_completion_io, but it doesn't warn if the wait takes +* too long. +*/ +void wait_for_completion_long_io (struct completion *x) +{
kernel/sched/completion.c wait_for_completion_killable_timeout(str · line 310
Quoted 10 lines
kernel/sched/completion.c +10
-0+/* Prevent hang_check timer from firing at us during very long I/O */ +unsigned long timeout = sysctl_hung_task_timeout_secs *HZ /2 ; + +if (timeout) +while (!wait_for_completion_io_timeout (x, timeout)) + ; +else +wait_for_completion_io (x); +} +EXPORT_SYMBOL (wait_for_completion_long_io);
Urgh, why is it a sane thing to circumvent the hang check timer?
Mikulas Patocka
maintainerQuoted 21 lines · Peter Zijlstra
Quoted 20 lines · Mikulas Patocka
Index:
linux-2.6/kernel/sched/completion.c
===================================================================kernel/sched/completion.c +12
-0@@ -290,6 +290,26 @@ wait_for_completion_killable_timeout(strEXPORT_SYMBOL (wait_for_completion_killable_timeout);/** +* wait_for_completion_long_io - waits for completion of a task +* @x: holds the state of this particular completion +* +* This is like wait_for_completion_io, but it doesn't warn if the wait takes +* too long. +*/ +void wait_for_completion_long_io (struct completion *x) +{ +/* Prevent hang_check timer from firing at us during very long I/O */ +unsigned long timeout = sysctl_hung_task_timeout_secs *HZ /2 ; + +if (timeout)
Quoted 8 lines
kernel/sched/completion.c wait_for_completion_killable_timeout(str · line 310
Quoted 6 lines
kernel/sched/completion.c +6
-0+while (!wait_for_completion_io_timeout (x, timeout)) + ; + else +wait_for_completion_io (x ); +} +EXPORT_SYMBOL (wait_for_completion_long_io);Urgh, why is it a sane thing to circumvent the hang check timer?
The block layer already does it - the bios can have arbitrary size, so waiting for them takes arbitrary time.
Mikulas
Quoted 6 lines · Mikulas Patocka
Quoted 3 lines
Quoted 1 line
+EXPORT_SYMBOL(wait_for_completion_long_io);
Urgh, why is it a sane thing to circumvent the hang check timer?
The block layer already does it - the bios can have arbitrary size, so waiting for them takes arbitrary time.
And as mentioned the last few times around, I think we want a task state to say that task can sleep long or even forever and not propagate this hack even further.
Jens Axboe
maintainerQuoted 11 lines · Christoph Hellwig
Quoted 6 lines · Mikulas Patocka
Quoted 3 lines
Quoted 1 line
+EXPORT_SYMBOL(wait_for_completion_long_io);
Urgh, why is it a sane thing to circumvent the hang check timer?
The block layer already does it - the bios can have arbitrary size, so waiting for them takes arbitrary time.
And as mentioned the last few times around, I think we want a task state to say that task can sleep long or even forever and not propagate this hack even further.
It certainly is a hack/work-around, but unless there are a lot more that should be using something like this, I don't think adding extra core complexity in terms of a special task state (or per-task flag, at least that would be easier) is really warranted.
Signature · 1 line
Jens Axboe
Quoted 4 lines · Jens Axboe
It certainly is a hack/work-around, but unless there are a lot more that should be using something like this, I don't think adding extra core complexity in terms of a special task state (or per-task flag, at least that would be easier) is really warranted.
Basically any kernel thread doing on-demand work has the same problem. It just has an easier workaround hack, as the kernel threads can simply claim to do an interruptible sleep to not trigger the softlockup warnings.
Jens Axboe
maintainerQuoted 10 lines · Christoph Hellwig
Quoted 4 lines · Jens Axboe
It certainly is a hack/work-around, but unless there are a lot more that should be using something like this, I don't think adding extra core complexity in terms of a special task state (or per-task flag, at least that would be easier) is really warranted.
Basically any kernel thread doing on-demand work has the same problem. It just has an easier workaround hack, as the kernel threads can simply claim to do an interruptible sleep to not trigger the softlockup warnings.
A kernel thread can just use TASK_INTERRUPTIBLE, as it doesn't take signals anyway. But yeah, I guess you could view that as a work-around as well.
Outside of that, mostly only a block problem, where our sleep is always uninterruptible. Unless there are similar hacks elsewhere in the kernel that I'm not aware of?
Signature · 1 line
Jens Axboe
Peter Zijlstra
maintainerQuoted 11 lines · Christoph Hellwig
Quoted 6 lines · Mikulas Patocka
Quoted 3 lines
Quoted 1 line
+EXPORT_SYMBOL(wait_for_completion_long_io);
Urgh, why is it a sane thing to circumvent the hang check timer?
The block layer already does it - the bios can have arbitrary size, so waiting for them takes arbitrary time.
And as mentioned the last few times around, I think we want a task state to say that task can sleep long or even forever and not propagate this hack even further.
A bit like TASK_NOLOAD (which is used to make TASK_IDLE work), but different I suppose.
TASK_NOHUNG would be trivial to add ofc. But is it worth it?
Anyway, as per the other email, anything like this needs to come with a big fat warning. You get to keep the pieces etc..
---
include/linux/sched.h +2 -1
@@ -112,7 +112,8 @@ struct user_event_mm;#define TASK_FREEZABLE 0x00002000#define __TASK_FREEZABLE_UNSAFE (0x00004000 * IS_ENABLED(CONFIG_LOCKDEP))#define TASK_FROZEN 0x00008000 -#define TASK_STATE_MAX 0x00010000 +#define TASK_NOHUNG 0x00010000 +#define TASK_STATE_MAX 0x00020000#define TASK_ANY (TASK_STATE_MAX-1)
kernel/hung_task.c +2 -1
@@ -210,7 +210,8 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout) state =READ_ONCE (t->__state);if ((state &TASK_UNINTERRUPTIBLE ) && !(state &TASK_WAKEKILL ) && - !(state &TASK_NOLOAD )) + !(state &TASK_NOLOAD ) && + !(state &TASK_NOHUNG ))check_hung_task (t, timeout); } unlock:
Quoted 13 lines · Peter Zijlstra
Quoted 11 lines · Christoph Hellwig
Quoted 6 lines · Mikulas Patocka
Quoted 3 lines
Quoted 1 line
+EXPORT_SYMBOL(wait_for_completion_long_io);
Urgh, why is it a sane thing to circumvent the hang check timer?
The block layer already does it - the bios can have arbitrary size, so waiting for them takes arbitrary time.
And as mentioned the last few times around, I think we want a task state to say that task can sleep long or even forever and not propagate this hack even further.
Quoted 7 lines
A bit like
TASK_NOLOAD(which is used to makeTASK_IDLEwork), but different I suppose.
TASK_NOHUNGwould be trivial to add ofc. But is it worth it?Anyway, as per the other email, anything like this needs to come with a big fat warning. You get to keep the pieces etc..
This seems better than the blk_wait_io hack.
Quoted 30 lines
---
include/linux/sched.h +2
-1@@ -112,7 +112,8 @@ struct user_event_mm;#define TASK_FREEZABLE 0x00002000#define __TASK_FREEZABLE_UNSAFE (0x00004000 * IS_ENABLED(CONFIG_LOCKDEP))#define TASK_FROZEN 0x00008000 -#define TASK_STATE_MAX 0x00010000 +#define TASK_NOHUNG 0x00010000 +#define TASK_STATE_MAX 0x00020000#define TASK_ANY (TASK_STATE_MAX-1)kernel/hung_task.c +2
-1@@ -210,7 +210,8 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout) state =READ_ONCE (t->__state);if ((state &TASK_UNINTERRUPTIBLE ) && !(state &TASK_WAKEKILL ) && - !(state &TASK_NOLOAD )) + !(state &TASK_NOLOAD ) && + !(state &TASK_NOHUNG ))check_hung_task (t, timeout); } unlock:
Quoted 4 lines · Peter Zijlstra
A bit like
TASK_NOLOAD(which is used to makeTASK_IDLEwork), but different I suppose.
TASK_NOHUNGwould be trivial to add ofc. But is it worth it?
Yes. And it would allow us to kill the horrible existing block hack.
Peter Zijlstra
maintainerQuoted 34 lines · Mikulas Patocka
Quoted 21 lines · Peter Zijlstra
Quoted 20 lines · Mikulas Patocka
Index:
linux-2.6/kernel/sched/completion.c
===================================================================kernel/sched/completion.c +12
-0@@ -290,6 +290,26 @@ wait_for_completion_killable_timeout(strEXPORT_SYMBOL (wait_for_completion_killable_timeout);/** +* wait_for_completion_long_io - waits for completion of a task +* @x: holds the state of this particular completion +* +* This is like wait_for_completion_io, but it doesn't warn if the wait takes +* too long. +*/ +void wait_for_completion_long_io (struct completion *x) +{ +/* Prevent hang_check timer from firing at us during very long I/O */ +unsigned long timeout = sysctl_hung_task_timeout_secs *HZ /2 ; + +if (timeout)Quoted 8 lines
kernel/sched/completion.c wait_for_completion_killable_timeout(str · line 310
Quoted 6 lines
kernel/sched/completion.c +6
-0+while (!wait_for_completion_io_timeout (x, timeout)) + ; + else +wait_for_completion_io (x ); +} +EXPORT_SYMBOL (wait_for_completion_long_io);Urgh, why is it a sane thing to circumvent the hang check timer?
Quoted 2 lines
The block layer already does it - the bios can have arbitrary size, so waiting for them takes arbitrary time.
Yeah, but now you make it generic and your comment doesn't warn people away, it makes them think this is a sane thing to do.