Skip to content

Commit 81ada09

Browse files
Chengming Zhouaxboe
authored andcommitted
blk-flush: reuse rq queuelist in flush state machine
Since we don't need to maintain inflight flush_data requests list anymore, we can reuse rq->queuelist for flush pending list. Note in mq_flush_data_end_io(), we need to re-initialize rq->queuelist before reusing it in the state machine when end, since the rq->rq_next also reuse it, may have corrupted rq->queuelist by the driver. This patch decrease the size of struct request by 16 bytes. Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Ming Lei <ming.lei@redhat.com> Link: https://lore.kernel.org/r/20230717040058.3993930-5-chengming.zhou@linux.dev Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent b175c86 commit 81ada09

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

block/blk-flush.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,13 @@ static void blk_flush_complete_seq(struct request *rq,
183183
/* queue for flush */
184184
if (list_empty(pending))
185185
fq->flush_pending_since = jiffies;
186-
list_move_tail(&rq->flush.list, pending);
186+
list_move_tail(&rq->queuelist, pending);
187187
break;
188188

189189
case REQ_FSEQ_DATA:
190-
list_del_init(&rq->flush.list);
191190
fq->flush_data_in_flight++;
192191
spin_lock(&q->requeue_lock);
193-
list_add(&rq->queuelist, &q->requeue_list);
192+
list_move(&rq->queuelist, &q->requeue_list);
194193
spin_unlock(&q->requeue_lock);
195194
blk_mq_kick_requeue_list(q);
196195
break;
@@ -202,7 +201,7 @@ static void blk_flush_complete_seq(struct request *rq,
202201
* flush data request completion path. Restore @rq for
203202
* normal completion and end it.
204203
*/
205-
list_del_init(&rq->flush.list);
204+
list_del_init(&rq->queuelist);
206205
blk_flush_restore_request(rq);
207206
blk_mq_end_request(rq, error);
208207
break;
@@ -258,7 +257,7 @@ static enum rq_end_io_ret flush_end_io(struct request *flush_rq,
258257
fq->flush_running_idx ^= 1;
259258

260259
/* and push the waiting requests to the next stage */
261-
list_for_each_entry_safe(rq, n, running, flush.list) {
260+
list_for_each_entry_safe(rq, n, running, queuelist) {
262261
unsigned int seq = blk_flush_cur_seq(rq);
263262

264263
BUG_ON(seq != REQ_FSEQ_PREFLUSH && seq != REQ_FSEQ_POSTFLUSH);
@@ -292,7 +291,7 @@ static void blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq,
292291
{
293292
struct list_head *pending = &fq->flush_queue[fq->flush_pending_idx];
294293
struct request *first_rq =
295-
list_first_entry(pending, struct request, flush.list);
294+
list_first_entry(pending, struct request, queuelist);
296295
struct request *flush_rq = fq->flush_rq;
297296

298297
/* C1 described at the top of this file */
@@ -376,6 +375,11 @@ static enum rq_end_io_ret mq_flush_data_end_io(struct request *rq,
376375
*/
377376
spin_lock_irqsave(&fq->mq_flush_lock, flags);
378377
fq->flush_data_in_flight--;
378+
/*
379+
* May have been corrupted by rq->rq_next reuse, we need to
380+
* re-initialize rq->queuelist before reusing it here.
381+
*/
382+
INIT_LIST_HEAD(&rq->queuelist);
379383
blk_flush_complete_seq(rq, fq, REQ_FSEQ_DATA, error);
380384
spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
381385

@@ -386,7 +390,6 @@ static enum rq_end_io_ret mq_flush_data_end_io(struct request *rq,
386390
static void blk_rq_init_flush(struct request *rq)
387391
{
388392
rq->flush.seq = 0;
389-
INIT_LIST_HEAD(&rq->flush.list);
390393
rq->rq_flags |= RQF_FLUSH_SEQ;
391394
rq->flush.saved_end_io = rq->end_io; /* Usually NULL */
392395
rq->end_io = mq_flush_data_end_io;

include/linux/blk-mq.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ struct request {
178178

179179
struct {
180180
unsigned int seq;
181-
struct list_head list;
182181
rq_end_io_fn *saved_end_io;
183182
} flush;
184183

0 commit comments

Comments
 (0)