Skip to content

Commit 0a72e7f

Browse files
committed
block: add accessors for setting/querying request deadline
We reduce the resolution of request expiry, but since we're already using jiffies for this where resolution depends on the kernel configuration and since the timeout resolution is coarse anyway, that should be fine. Reviewed-by: Bart Van Assche <[email protected]> Reviewed-by: Omar Sandoval <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 76a86f9 commit 0a72e7f

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

block/blk-mq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ static void blk_mq_check_expired(struct blk_mq_hw_ctx *hctx,
858858
while (true) {
859859
start = read_seqcount_begin(&rq->gstate_seq);
860860
gstate = READ_ONCE(rq->gstate);
861-
deadline = rq->deadline;
861+
deadline = blk_rq_deadline(rq);
862862
if (!read_seqcount_retry(&rq->gstate_seq, start))
863863
break;
864864
cond_resched();

block/blk-timeout.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,18 @@ static void blk_rq_timed_out(struct request *req)
112112
static void blk_rq_check_expired(struct request *rq, unsigned long *next_timeout,
113113
unsigned int *next_set)
114114
{
115-
if (time_after_eq(jiffies, rq->deadline)) {
115+
const unsigned long deadline = blk_rq_deadline(rq);
116+
117+
if (time_after_eq(jiffies, deadline)) {
116118
list_del_init(&rq->timeout_list);
117119

118120
/*
119121
* Check if we raced with end io completion
120122
*/
121123
if (!blk_mark_rq_complete(rq))
122124
blk_rq_timed_out(rq);
123-
} else if (!*next_set || time_after(*next_timeout, rq->deadline)) {
124-
*next_timeout = rq->deadline;
125+
} else if (!*next_set || time_after(*next_timeout, deadline)) {
126+
*next_timeout = deadline;
125127
*next_set = 1;
126128
}
127129
}
@@ -162,7 +164,7 @@ void blk_abort_request(struct request *req)
162164
* immediately and that scan sees the new timeout value.
163165
* No need for fancy synchronizations.
164166
*/
165-
req->deadline = jiffies;
167+
blk_rq_set_deadline(req, jiffies);
166168
mod_timer(&req->q->timeout, 0);
167169
} else {
168170
if (blk_mark_rq_complete(req))
@@ -213,7 +215,7 @@ void blk_add_timer(struct request *req)
213215
if (!req->timeout)
214216
req->timeout = q->rq_timeout;
215217

216-
req->deadline = jiffies + req->timeout;
218+
blk_rq_set_deadline(req, jiffies + req->timeout);
217219
req->rq_flags &= ~RQF_MQ_TIMEOUT_EXPIRED;
218220

219221
/*
@@ -228,7 +230,7 @@ void blk_add_timer(struct request *req)
228230
* than an existing one, modify the timer. Round up to next nearest
229231
* second.
230232
*/
231-
expiry = blk_rq_timeout(round_jiffies_up(req->deadline));
233+
expiry = blk_rq_timeout(round_jiffies_up(blk_rq_deadline(req)));
232234

233235
if (!timer_pending(&q->timeout) ||
234236
time_before(expiry, q->timeout.expires)) {

block/blk.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,21 @@ static inline void req_set_nomerge(struct request_queue *q, struct request *req)
236236
q->last_merge = NULL;
237237
}
238238

239+
/*
240+
* Steal a bit from this field for legacy IO path atomic IO marking. Note that
241+
* setting the deadline clears the bottom bit, potentially clearing the
242+
* completed bit. The user has to be OK with this (current ones are fine).
243+
*/
244+
static inline void blk_rq_set_deadline(struct request *rq, unsigned long time)
245+
{
246+
rq->__deadline = time & ~0x1UL;
247+
}
248+
249+
static inline unsigned long blk_rq_deadline(struct request *rq)
250+
{
251+
return rq->__deadline & ~0x1UL;
252+
}
253+
239254
/*
240255
* Internal io_context interface
241256
*/

include/linux/blkdev.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ struct request {
257257
struct u64_stats_sync aborted_gstate_sync;
258258
u64 aborted_gstate;
259259

260-
unsigned long deadline;
260+
/* access through blk_rq_set_deadline, blk_rq_deadline */
261+
unsigned long __deadline;
262+
261263
struct list_head timeout_list;
262264

263265
/*

0 commit comments

Comments
 (0)