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
8#include <linux/major.h>8#include <linux/major.h>
9#include <linux/genhd.h>9#include <linux/genhd.h>
10#include <linux/list.h>10#include <linux/list.h>
11#include <linux/llist.h>
11#include <linux/timer.h>12#include <linux/timer.h>
12#include <linux/workqueue.h>13#include <linux/workqueue.h>
13#include <linux/pagemap.h>14#include <linux/pagemap.h>
@@ -94,10 +95,17 @@ enum rq_cmd_type_bits { · 80 unmodified lines
94 * as well!95 * as well!
95 */96 */
96struct request {97struct request {
97 struct list_head queuelist;98 union {
98 struct call_single_data csd;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 };
99 106
100 struct request_queue *q;107 struct request_queue *q;
108 struct blk_mq_ctx *mq_ctx;
101 109
102 u64 cmd_flags;110 u64 cmd_flags;
103 enum rq_cmd_type_bits cmd_type;111 enum rq_cmd_type_bits cmd_type;
@@ -213,6 +221,8 @@ struct request_pm_state · 109 unmodified lines
213 221
214#include <linux/elevator.h>222#include <linux/elevator.h>
215 223
224struct blk_queue_ctx;
225
216typedef void (request_fn_proc) (struct request_queue *q);226typedef void (request_fn_proc) (struct request_queue *q);
217typedef void (make_request_fn) (struct request_queue *q, struct bio *bio);227typedef void (make_request_fn) (struct request_queue *q, struct bio *bio);
218typedef int (prep_rq_fn) (struct request_queue *, struct request *);228typedef int (prep_rq_fn) (struct request_queue *, struct request *);
@@ -311,6 +321,18 @@ struct request_queue { · 92 unmodified lines
311 dma_drain_needed_fn *dma_drain_needed;321 dma_drain_needed_fn *dma_drain_needed;
312 lld_busy_fn *lld_busy_fn;322 lld_busy_fn *lld_busy_fn;
313 323
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
314 /*336 /*
315 * Dispatch queue sorting337 * Dispatch queue sorting
316 */338 */
@@ -359,6 +381,11 @@ struct request_queue { · 42 unmodified lines
359 */381 */
360 struct kobject kobj;382 struct kobject kobj;
361 383
384 /*
385 * mq queue kobject
386 */
387 struct kobject mq_kobj;
388
362#ifdef CONFIG_PM_RUNTIME389#ifdef CONFIG_PM_RUNTIME
363 struct device *dev;390 struct device *dev;
364 int rpm_status;391 int rpm_status;
@@ -423,7 +450,13 @@ struct request_queue { · 58 unmodified lines
423 unsigned long flush_pending_since;450 unsigned long flush_pending_since;
424 struct list_head flush_queue[2];451 struct list_head flush_queue[2];
425 struct list_head flush_data_in_flight;452 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 };
427 460
428 struct mutex sysfs_lock;461 struct mutex sysfs_lock;
429 462
@@ -435,14 +468,14 @@ struct request_queue { · 5 unmodified lines
435 struct bsg_class_device bsg_dev;468 struct bsg_class_device bsg_dev;
436#endif469#endif
437 470
438#ifdef CONFIG_BLK_CGROUP
439 struct list_head all_q_node;
440#endif
441#ifdef CONFIG_BLK_DEV_THROTTLING471#ifdef CONFIG_BLK_DEV_THROTTLING
442 /* Throttle data */472 /* Throttle data */
443 struct throtl_data *td;473 struct throtl_data *td;
444#endif474#endif
445 struct rcu_head rcu_head;475 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;
446};479};
447 480
448#define QUEUE_FLAG_QUEUED 1 /* uses generic tag queueing */481#define QUEUE_FLAG_QUEUED 1 /* uses generic tag queueing */
@@ -465,6 +498,7 @@ struct request_queue { · 16 unmodified lines
465#define QUEUE_FLAG_SECDISCARD 17 /* supports SECDISCARD */498#define QUEUE_FLAG_SECDISCARD 17 /* supports SECDISCARD */
466#define QUEUE_FLAG_SAME_FORCE 18 /* force complete on same CPU */499#define QUEUE_FLAG_SAME_FORCE 18 /* force complete on same CPU */
467#define QUEUE_FLAG_DEAD 19 /* queue tear-down finished */500#define QUEUE_FLAG_DEAD 19 /* queue tear-down finished */
501#define QUEUE_FLAG_INIT_DONE 20 /* queue is initialized */
468 502
469#define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \503#define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \
470 (1 << QUEUE_FLAG_STACKABLE) | \504 (1 << QUEUE_FLAG_STACKABLE) | \
@@ -537,6 +571,7 @@ static inline void queue_flag_clear(unsigned int flag, struct request_queue *q) · 66 unmodified lines
537#define blk_queue_dying(q) test_bit(QUEUE_FLAG_DYING, &(q)->queue_flags)571#define blk_queue_dying(q) test_bit(QUEUE_FLAG_DYING, &(q)->queue_flags)
538#define blk_queue_dead(q) test_bit(QUEUE_FLAG_DEAD, &(q)->queue_flags)572#define blk_queue_dead(q) test_bit(QUEUE_FLAG_DEAD, &(q)->queue_flags)
539#define blk_queue_bypass(q) test_bit(QUEUE_FLAG_BYPASS, &(q)->queue_flags)573#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)
540#define blk_queue_nomerges(q) test_bit(QUEUE_FLAG_NOMERGES, &(q)->queue_flags)575#define blk_queue_nomerges(q) test_bit(QUEUE_FLAG_NOMERGES, &(q)->queue_flags)
541#define blk_queue_noxmerges(q) \576#define blk_queue_noxmerges(q) \
542 test_bit(QUEUE_FLAG_NOXMERGES, &(q)->queue_flags)577 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
1011struct blk_plug {1046struct blk_plug {
1012 unsigned long magic; /* detect uninitialized use-cases */1047 unsigned long magic; /* detect uninitialized use-cases */
1013 struct list_head list; /* requests */1048 struct list_head list; /* requests */
1049 struct list_head mq_list; /* blk-mq requests */
1014 struct list_head cb_list; /* md requires an unplug callback */1050 struct list_head cb_list; /* md requires an unplug callback */
1015};1051};
1016#define BLK_MAX_REQUEST_COUNT 161052#define BLK_MAX_REQUEST_COUNT 16
@@ -1048,7 +1084,10 @@ static inline bool blk_needs_flush_plug(struct task_struct *tsk) · 31 unmodified lines
1048{1084{
1049 struct blk_plug *plug = tsk->plug;1085 struct blk_plug *plug = tsk->plug;
1050 1086
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));
1052}1091}
1053 1092
1054/*1093/*
@@ -1323,6 +1362,7 @@ static inline void put_dev_sector(Sector p) · 268 unmodified lines
1323 1362
1324struct work_struct;1363struct work_struct;
1325int kblockd_schedule_work(struct request_queue *q, struct work_struct *work);1364int kblockd_schedule_work(struct request_queue *q, struct work_struct *work);
1365int kblockd_schedule_delayed_work(struct request_queue *q, struct delayed_work *dwork, unsigned long delay);
1326 1366
1327#ifdef CONFIG_BLK_CGROUP1367#ifdef CONFIG_BLK_CGROUP
1328/*1368/*

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