block: I/O error occurs during SATA disk stress test
Quoted 32 lines · Gu Mi
The problem occurs in two async processes, One is when a new IO calls the
blk_mq_start_request()interface to start sending,The other is that the block layer timer process calls theblk_mq_req_expiredinterface to check whether there is an IO timeout.When an instruction out of sequence occurs between
blk_add_timerandWRITE_ONCE(rq->state,MQ_RQ_IN_FLIGHT)in the interface blk_mq_start_request,at this time, the block timer is checking the new IO timeout, Since the req status has been set toMQ_RQ_IN_FLIGHTandreq->deadlineis 0 at this time, the new IO will be misjudged as a timeout.Our repair plan is for the deadline to be 0, and we do not think that a timeout occurs. At the same time, because the jiffies of the 32-bit system will be reversed shortly after the system is turned on, we will add 1 jiffies to the deadline at this time.
Signed-off-by Gu Mi <[email protected]>---
v1->v2:
time_after_eq()can handle the overflow, so remove the change on 32-bit inblk_add_timer().block/blk-mq.c | 2 ++ 1 file changed, 2 insertions(+)block/blk-mq.c index 4b90d2d..6defaa1 renamed from block/blk-mq.c +0
-0100644
block/blk-mq.c static bool blk_mq_req_expired(struct request *rq, unsigned long *next) · line 1458
Quoted 8 lines
block/blk-mq.c +2
-0@@ -1451,6 +1451,8 @@ static bool blk_mq_req_expired(struct request *rq, unsigned long *next)return false; deadline =READ_ONCE (rq->deadline); +if (unlikely (deadline ==0 )) +return false;if (time_after_eq (jiffies, deadline))return true;
rq->deadline == 0 can be a valid deadline value so the above patch doesn't look right to me.
Thanks,
Bart.
---
in patch 1, I added another modification in blk_add_timer(). As follows,
block/blk-mq.c
Quoted 3 lines
block/blk-mq.c +3
-0+#ifndef CONFIG_64BIT +/* In case INITIAL_JIFFIES wraps on 32-bit */ + expiry |=1UL ;
The purpose of this modification is to ensure that rq->deadline is 0 means that it is initialized to 0 in blk_mq_req_expired(). In this case, make sure rq->deadline is an invalid value in blk_mq_req_expired().
Please review my workaround again.
Thanks,
Gu Mi.
Jens Axboe
maintainerQuoted 35 lines · On 8/25/22 9:25 PM, [email protected] wrote:
Quoted 34 lines · Gu Mi
The problem occurs in two async processes, One is when a new IO calls the
blk_mq_start_request()interface to start sending,The other is that the block layer timer process calls theblk_mq_req_expiredinterface to check whether there is an IO timeout.When an instruction out of sequence occurs between
blk_add_timerandWRITE_ONCE(rq->state,MQ_RQ_IN_FLIGHT)in the interface blk_mq_start_request,at this time, the block timer is checking the new IO timeout, Since the req status has been set toMQ_RQ_IN_FLIGHTandreq->deadlineis 0 at this time, the new IO will be misjudged as a timeout.Our repair plan is for the deadline to be 0, and we do not think that a timeout occurs. At the same time, because the jiffies of the 32-bit system will be reversed shortly after the system is turned on, we will add 1 jiffies to the deadline at this time.
Signed-off-by Gu Mi <[email protected]>---
v1->v2:
time_after_eq()can handle the overflow, so remove the change on 32-bit inblk_add_timer().block/blk-mq.c | 2 ++ 1 file changed, 2 insertions(+)block/blk-mq.c index 4b90d2d..6defaa1 renamed from block/blk-mq.c +0
-0100644
block/blk-mq.c +0
-0@@ -1451,6 +1451,8 @@ static bool blk_mq_req_expired(struct request *rq, unsigned long *next)return false;
Quoted 9 lines
block/blk-mq.c static bool blk_mq_req_expired(struct request *rq, unsigned long *next) · line 1458
Quoted 6 lines
block/blk-mq.c +2
-0deadline =READ_ONCE (rq->deadline); +if (unlikely (deadline ==0 )) +return false;if (time_after_eq (jiffies, deadline))return true;
rq->deadline== 0 can be a valid deadline value so the above patch doesn't look right to me.
Gu, you need to fix your quoting of emails, these are impossible to read.
That aside, I think there's a misunderstanding here. v1 has some parts and v2 has others. Please post a v3 that has the hunk that guarantees that deadline always has the lowest bit set if assigned, and the !deadline check as well.
Signature · 1 line
Jens Axboe
Quoted 4 lines · Jens Axboe
That aside, I think there's a misunderstanding here. v1 has some parts and v2 has others. Please post a v3 that has the hunk that guarantees that deadline always has the lowest bit set if assigned, and the !deadline check as well.
Hi Jens,
Would it be considered acceptable to store the request state (rq->state) in the lowest two bits of rq->deadline? This would reduce the deadline resolution a little bit but I think that's acceptable. Except for blk_abort_request(), all changes of rq->state and rq->deadline are already serialized. So with this approach only blk_abort_request() would have to use an atomic-compare-exchange loop.
Thanks,
Bart.
Jens Axboe
maintainerQuoted 6 lines · Bart Van Assche
Quoted 4 lines · Jens Axboe
That aside, I think there's a misunderstanding here. v1 has some parts and v2 has others. Please post a v3 that has the hunk that guarantees that deadline always has the lowest bit set if assigned, and the !deadline check as well.
Quoted 8 lines
Hi Jens,
Would it be considered acceptable to store the request state (
rq->state) in the lowest two bits ofrq->deadline? This would reduce the deadline resolution a little bit but I think that's acceptable. Except forblk_abort_request(), all changes ofrq->stateandrq->deadlineare already serialized. So with this approach onlyblk_abort_request()would have to use an atomic-compare-exchange loop.
Sure, I think that would be fine, as long as:
1) We keep the expensive bits in the actual timeout/abort path and not part of regular issue.
2) We rename the field while doing so.
Might even be worthwhile to look into NOT having both timeout and deadline in struct request, it's a bit annoying to waste double the space on something that should just be one field.
Signature · 1 line
Jens Axboe