History

blk-mq: new multi-queue block IO queueing mechanism

Linux currently has two models for block devices: - The classic request_fn based approach, where drivers use struct request units for IO. The block layer provides various helper functionalities to let drivers share code, things like tag management, timeout handling, queueing, etc. - The "stacked" approach, where a driver squeezes in between the block layer and IO submitter. Since this bypasses the IO stack, driver generally have to manage everything themselves. With drivers being written for new high IOPS devices, the classic request_fn based driver doesn't work well enough. The design dates back to when both SMP and high IOPS was rare. It has problems with scaling to bigger machines, and runs into scaling issues even on smaller machines when you have IOPS in the hundreds of thousands per device. The stacked approach is then most often selected as the model for the driver. But this means that everybody has to re-invent everything, and along with that we get all the problems again that the shared approach solved. This commit introduces blk-mq, block multi queue support. The design is centered around per-cpu queues for queueing IO, which then funnel down into x number of hardware submission queues. We might have a 1:1 mapping between the two, or it might be an N:M mapping. That all depends on what the hardware supports. blk-mq provides various helper functions, which include: - Scalable support for request tagging. Most devices need to be able to uniquely identify a request both in the driver and to the hardware. The tagging uses per-cpu caches for freed tags, to enable cache hot reuse. - Timeout handling without tracking request on a per-device basis. Basically the driver should be able to get a notification, if a request happens to fail. - Optional support for non 1:1 mappings between issue and submission queues. blk-mq can redirect IO completions to the desired location. - Support for per-request payloads. Drivers almost always need to associate a request structure with some driver private command structure. Drivers can tell blk-mq this at init time, and then any request handed to the driver will have the required size of memory associated with it. - Support for merging of IO, and plugging. The stacked model gets neither of these. Even for high IOPS devices, merging sequential IO reduces per-command overhead and thus increases bandwidth. For now, this is provided as a potential 3rd queueing model, with the hope being that, as it matures, it can replace both the classic and stacked model. That would get us back to having just 1 real model for block devices, leaving the stacked approach to dm/md devices (as it was originally intended). Contributions in this patch from the following people: Shaohua Li <shli@fusionio.com> Alexander Gordeev <agordeev@redhat.com> Christoph Hellwig <hch@infradead.org> Mike Christie <michaelc@cs.wisc.edu> Matias Bjorling <m@bjorling.me> Jeff Moyer <jmoyer@redhat.com>

Jens Axboe committed 13 years ago

Commit 320ae511 parent 1dddc0118 files · +2890 −109Browse files

Showing the changes to include/linux/blkdev.h (1 of 18 files). Show all

Unified · Split

include/linux/blkdev.h+47−7
@@ -8,6 +8,7 @@ · 7 unmodified lines
88 #include <linux/major.h>
99 #include <linux/genhd.h>
1010 #include <linux/list.h>
11+#include <linux/llist.h>
1112 #include <linux/timer.h>
1213 #include <linux/workqueue.h>
1314 #include <linux/pagemap.h>
@@ -94,10 +95,17 @@ enum rq_cmd_type_bits { · 80 unmodified lines
9495 * as well!
9596 */
9697 struct request {
97− struct list_head queuelist;
98− struct call_single_data csd;
98+ union {
99+ struct list_head queuelist;
100+ struct llist_node ll_list;
101+ };
102+ union {
103+ struct call_single_data csd;
104+ struct work_struct mq_flush_data;
105+ };
99106
100107 struct request_queue *q;
108+ struct blk_mq_ctx *mq_ctx;
101109
102110 u64 cmd_flags;
103111 enum rq_cmd_type_bits cmd_type;
@@ -213,6 +221,8 @@ struct request_pm_state · 109 unmodified lines
213221
214222 #include <linux/elevator.h>
215223
224+struct blk_queue_ctx;
225+
216226 typedef void (request_fn_proc) (struct request_queue *q);
217227 typedef void (make_request_fn) (struct request_queue *q, struct bio *bio);
218228 typedef int (prep_rq_fn) (struct request_queue *, struct request *);
@@ -311,6 +321,18 @@ struct request_queue { · 92 unmodified lines
311321 dma_drain_needed_fn *dma_drain_needed;
312322 lld_busy_fn *lld_busy_fn;
313323
324+ struct blk_mq_ops *mq_ops;
325+
326+ unsigned int *mq_map;
327+
328+ /* sw queues */
329+ struct blk_mq_ctx *queue_ctx;
330+ unsigned int nr_queues;
331+
332+ /* hw dispatch queues */
333+ struct blk_mq_hw_ctx **queue_hw_ctx;
334+ unsigned int nr_hw_queues;
335+
314336 /*
315337 * Dispatch queue sorting
316338 */
@@ -359,6 +381,11 @@ struct request_queue { · 42 unmodified lines
359381 */
360382 struct kobject kobj;
361383
384+ /*
385+ * mq queue kobject
386+ */
387+ struct kobject mq_kobj;
388+
362389 #ifdef CONFIG_PM_RUNTIME
363390 struct device *dev;
364391 int rpm_status;
@@ -423,7 +450,13 @@ struct request_queue { · 58 unmodified lines
423450 unsigned long flush_pending_since;
424451 struct list_head flush_queue[2];
425452 struct list_head flush_data_in_flight;
426− struct request flush_rq;
453+ union {
454+ struct request flush_rq;
455+ struct {
456+ spinlock_t mq_flush_lock;
457+ struct work_struct mq_flush_work;
458+ };
459+ };
427460
428461 struct mutex sysfs_lock;
429462
@@ -435,14 +468,14 @@ struct request_queue { · 5 unmodified lines
435468 struct bsg_class_device bsg_dev;
436469 #endif
437470
438−#ifdef CONFIG_BLK_CGROUP
439− struct list_head all_q_node;
440−#endif
441471 #ifdef CONFIG_BLK_DEV_THROTTLING
442472 /* Throttle data */
443473 struct throtl_data *td;
444474 #endif
445475 struct rcu_head rcu_head;
476+ wait_queue_head_t mq_freeze_wq;
477+ struct percpu_counter mq_usage_counter;
478+ struct list_head all_q_node;
446479 };
447480
448481 #define QUEUE_FLAG_QUEUED 1 /* uses generic tag queueing */
@@ -465,6 +498,7 @@ struct request_queue { · 16 unmodified lines
465498 #define QUEUE_FLAG_SECDISCARD 17 /* supports SECDISCARD */
466499 #define QUEUE_FLAG_SAME_FORCE 18 /* force complete on same CPU */
467500 #define QUEUE_FLAG_DEAD 19 /* queue tear-down finished */
501+#define QUEUE_FLAG_INIT_DONE 20 /* queue is initialized */
468502
469503 #define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \
470504 (1 << QUEUE_FLAG_STACKABLE) | \
@@ -537,6 +571,7 @@ static inline void queue_flag_clear(unsigned int flag, struct request_queue *q) · 66 unmodified lines
537571 #define blk_queue_dying(q) test_bit(QUEUE_FLAG_DYING, &(q)->queue_flags)
538572 #define blk_queue_dead(q) test_bit(QUEUE_FLAG_DEAD, &(q)->queue_flags)
539573 #define blk_queue_bypass(q) test_bit(QUEUE_FLAG_BYPASS, &(q)->queue_flags)
574+#define blk_queue_init_done(q) test_bit(QUEUE_FLAG_INIT_DONE, &(q)->queue_flags)
540575 #define blk_queue_nomerges(q) test_bit(QUEUE_FLAG_NOMERGES, &(q)->queue_flags)
541576 #define blk_queue_noxmerges(q) \
542577 test_bit(QUEUE_FLAG_NOXMERGES, &(q)->queue_flags)
@@ -1011,6 +1046,7 @@ static inline void blk_post_runtime_resume(struct request_queue *q, int err) {} · 468 unmodified lines
10111046 struct blk_plug {
10121047 unsigned long magic; /* detect uninitialized use-cases */
10131048 struct list_head list; /* requests */
1049+ struct list_head mq_list; /* blk-mq requests */
10141050 struct list_head cb_list; /* md requires an unplug callback */
10151051 };
10161052 #define BLK_MAX_REQUEST_COUNT 16
@@ -1048,7 +1084,10 @@ static inline bool blk_needs_flush_plug(struct task_struct *tsk) · 31 unmodified lines
10481084 {
10491085 struct blk_plug *plug = tsk->plug;
10501086
1051− return plug && (!list_empty(&plug->list) || !list_empty(&plug->cb_list));
1087+ return plug &&
1088+ (!list_empty(&plug->list) ||
1089+ !list_empty(&plug->mq_list) ||
1090+ !list_empty(&plug->cb_list));
10521091 }
10531092
10541093 /*
@@ -1323,6 +1362,7 @@ static inline void put_dev_sector(Sector p) · 268 unmodified lines
13231362
13241363 struct work_struct;
13251364 int kblockd_schedule_work(struct request_queue *q, struct work_struct *work);
1365+int kblockd_schedule_delayed_work(struct request_queue *q, struct delayed_work *dwork, unsigned long delay);
13261366
13271367 #ifdef CONFIG_BLK_CGROUP
13281368 /*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t