Skip to content

Commit b175c86

Browse files
Chengming Zhouaxboe
authored andcommitted
blk-flush: count inflight flush_data requests
The flush state machine use a double list to link all inflight flush_data requests, to avoid issuing separate post-flushes for these flush_data requests which shared PREFLUSH. So we can't reuse rq->queuelist, this is why we need rq->flush.list In preparation of the next patch that reuse rq->queuelist for flush state machine, we change the double linked list to unsigned long counter, which count all inflight flush_data requests. This is ok since we only need to know if there is any inflight flush_data request, so unsigned long counter is good. Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com> Reviewed-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20230717040058.3993930-4-chengming.zhou@linux.dev Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 28b2412 commit b175c86

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

block/blk-flush.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ static void blk_flush_complete_seq(struct request *rq,
187187
break;
188188

189189
case REQ_FSEQ_DATA:
190-
list_move_tail(&rq->flush.list, &fq->flush_data_in_flight);
190+
list_del_init(&rq->flush.list);
191+
fq->flush_data_in_flight++;
191192
spin_lock(&q->requeue_lock);
192193
list_add(&rq->queuelist, &q->requeue_list);
193194
spin_unlock(&q->requeue_lock);
@@ -299,7 +300,7 @@ static void blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq,
299300
return;
300301

301302
/* C2 and C3 */
302-
if (!list_empty(&fq->flush_data_in_flight) &&
303+
if (fq->flush_data_in_flight &&
303304
time_before(jiffies,
304305
fq->flush_pending_since + FLUSH_PENDING_TIMEOUT))
305306
return;
@@ -374,6 +375,7 @@ static enum rq_end_io_ret mq_flush_data_end_io(struct request *rq,
374375
* the comment in flush_end_io().
375376
*/
376377
spin_lock_irqsave(&fq->mq_flush_lock, flags);
378+
fq->flush_data_in_flight--;
377379
blk_flush_complete_seq(rq, fq, REQ_FSEQ_DATA, error);
378380
spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
379381

@@ -445,7 +447,7 @@ bool blk_insert_flush(struct request *rq)
445447
blk_rq_init_flush(rq);
446448
rq->flush.seq |= REQ_FSEQ_PREFLUSH;
447449
spin_lock_irq(&fq->mq_flush_lock);
448-
list_move_tail(&rq->flush.list, &fq->flush_data_in_flight);
450+
fq->flush_data_in_flight++;
449451
spin_unlock_irq(&fq->mq_flush_lock);
450452
return false;
451453
default:
@@ -496,7 +498,6 @@ struct blk_flush_queue *blk_alloc_flush_queue(int node, int cmd_size,
496498

497499
INIT_LIST_HEAD(&fq->flush_queue[0]);
498500
INIT_LIST_HEAD(&fq->flush_queue[1]);
499-
INIT_LIST_HEAD(&fq->flush_data_in_flight);
500501

501502
return fq;
502503

block/blk.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@ struct elevator_type;
1515
extern struct dentry *blk_debugfs_root;
1616

1717
struct blk_flush_queue {
18+
spinlock_t mq_flush_lock;
1819
unsigned int flush_pending_idx:1;
1920
unsigned int flush_running_idx:1;
2021
blk_status_t rq_status;
2122
unsigned long flush_pending_since;
2223
struct list_head flush_queue[2];
23-
struct list_head flush_data_in_flight;
24+
unsigned long flush_data_in_flight;
2425
struct request *flush_rq;
25-
26-
spinlock_t mq_flush_lock;
2726
};
2827

2928
bool is_flush_rq(struct request *req);

0 commit comments

Comments
 (0)