Skip to content

Commit de3ec86

Browse files
committed
dm: don't start current request if it would've merged with the previous
Request-based DM's dm_request_fn() is so fast to pull requests off the queue that steps need to be taken to promote merging by avoiding request processing if it makes sense. If the current request would've merged with previous request let the current request stay on the queue longer. Suggested-by: Jens Axboe <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent d548b34 commit de3ec86

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

drivers/md/dm.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/delay.h>
2222
#include <linux/wait.h>
2323
#include <linux/kthread.h>
24+
#include <linux/elevator.h> /* for rq_end_sector() */
2425

2526
#include <trace/events/block.h>
2627

@@ -216,6 +217,10 @@ struct mapped_device {
216217

217218
struct kthread_worker kworker;
218219
struct task_struct *kworker_task;
220+
221+
/* for request-based merge heuristic in dm_request_fn() */
222+
sector_t last_rq_pos;
223+
int last_rq_rw;
219224
};
220225

221226
/*
@@ -1930,6 +1935,9 @@ static void dm_start_request(struct mapped_device *md, struct request *orig)
19301935
blk_start_request(orig);
19311936
atomic_inc(&md->pending[rq_data_dir(orig)]);
19321937

1938+
md->last_rq_pos = rq_end_sector(orig);
1939+
md->last_rq_rw = rq_data_dir(orig);
1940+
19331941
/*
19341942
* Hold the md reference here for the in-flight I/O.
19351943
* We can't rely on the reference count by device opener,
@@ -1982,6 +1990,10 @@ static void dm_request_fn(struct request_queue *q)
19821990
continue;
19831991
}
19841992

1993+
if (md_in_flight(md) && rq->bio && rq->bio->bi_vcnt == 1 &&
1994+
md->last_rq_pos == pos && md->last_rq_rw == rq_data_dir(rq))
1995+
goto delay_and_out;
1996+
19851997
if (ti->type->busy && ti->type->busy(ti))
19861998
goto delay_and_out;
19871999

0 commit comments

Comments
 (0)