Skip to content

Commit 56ebdaf

Browse files
Shaohua LiJens Axboe
authored andcommitted
block: simplify force plug flush code a little bit
Cleaning up the code a little bit. attempt_plug_merge() traverses the plug list anyway, we can do the request counting there, so stack size is reduced a little bit. The motivation here is I suspect if we should count the requests for each queue (task could handle multiple disks in the meantime), but my test doesn't show it's worthy doing. If somebody proves we should do it, below change will make that more easier. Signed-off-by: Shaohua Li <[email protected]> Signed-off-by: Shaohua Li <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent a632716 commit 56ebdaf

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

block/blk-core.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ static bool bio_attempt_front_merge(struct request_queue *q,
11671167
* true if merge was successful, otherwise false.
11681168
*/
11691169
static bool attempt_plug_merge(struct task_struct *tsk, struct request_queue *q,
1170-
struct bio *bio)
1170+
struct bio *bio, unsigned int *request_count)
11711171
{
11721172
struct blk_plug *plug;
11731173
struct request *rq;
@@ -1176,10 +1176,13 @@ static bool attempt_plug_merge(struct task_struct *tsk, struct request_queue *q,
11761176
plug = tsk->plug;
11771177
if (!plug)
11781178
goto out;
1179+
*request_count = 0;
11791180

11801181
list_for_each_entry_reverse(rq, &plug->list, queuelist) {
11811182
int el_ret;
11821183

1184+
(*request_count)++;
1185+
11831186
if (rq->q != q)
11841187
continue;
11851188

@@ -1219,6 +1222,7 @@ static int __make_request(struct request_queue *q, struct bio *bio)
12191222
struct blk_plug *plug;
12201223
int el_ret, rw_flags, where = ELEVATOR_INSERT_SORT;
12211224
struct request *req;
1225+
unsigned int request_count = 0;
12221226

12231227
/*
12241228
* low level driver can indicate that it wants pages above a
@@ -1237,7 +1241,7 @@ static int __make_request(struct request_queue *q, struct bio *bio)
12371241
* Check if we can merge with the plugged list before grabbing
12381242
* any locks.
12391243
*/
1240-
if (attempt_plug_merge(current, q, bio))
1244+
if (attempt_plug_merge(current, q, bio, &request_count))
12411245
goto out;
12421246

12431247
spin_lock_irq(q->queue_lock);
@@ -1302,9 +1306,8 @@ static int __make_request(struct request_queue *q, struct bio *bio)
13021306
if (__rq->q != q)
13031307
plug->should_sort = 1;
13041308
}
1305-
if (plug->count >= BLK_MAX_REQUEST_COUNT)
1309+
if (request_count >= BLK_MAX_REQUEST_COUNT)
13061310
blk_flush_plug_list(plug, false);
1307-
plug->count++;
13081311
list_add_tail(&req->queuelist, &plug->list);
13091312
drive_stat_acct(req, 1);
13101313
} else {
@@ -2634,7 +2637,6 @@ void blk_start_plug(struct blk_plug *plug)
26342637
INIT_LIST_HEAD(&plug->list);
26352638
INIT_LIST_HEAD(&plug->cb_list);
26362639
plug->should_sort = 0;
2637-
plug->count = 0;
26382640

26392641
/*
26402642
* If this is a nested plug, don't actually assign it. It will be
@@ -2718,7 +2720,6 @@ void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule)
27182720
return;
27192721

27202722
list_splice_init(&plug->list, &list);
2721-
plug->count = 0;
27222723

27232724
if (plug->should_sort) {
27242725
list_sort(NULL, &list, plug_rq_cmp);

include/linux/blkdev.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,6 @@ struct blk_plug {
873873
struct list_head list;
874874
struct list_head cb_list;
875875
unsigned int should_sort;
876-
unsigned int count;
877876
};
878877
#define BLK_MAX_REQUEST_COUNT 16
879878

0 commit comments

Comments
 (0)