2014-05-29 00:15:41 +08:00
|
|
|
/*
|
|
|
|
* Fast and scalable bitmap tagging variant. Uses sparser bitmaps spread
|
|
|
|
* over multiple cachelines to avoid ping-pong between multiple submitters
|
|
|
|
* or submitter and completer. Uses rolling wakeups to avoid falling of
|
|
|
|
* the scaling cliff when we run out of tags and have to start putting
|
|
|
|
* submitters to sleep.
|
|
|
|
*
|
|
|
|
* Uses active queue tracking to support fairer distribution of tags
|
|
|
|
* between multiple submitters when a shared tag map is used.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2014 Jens Axboe
|
|
|
|
*/
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
2014-05-09 23:36:49 +08:00
|
|
|
#include <linux/random.h>
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
|
|
|
|
#include <linux/blk-mq.h>
|
|
|
|
#include "blk.h"
|
|
|
|
#include "blk-mq.h"
|
|
|
|
#include "blk-mq-tag.h"
|
|
|
|
|
2014-05-09 23:36:49 +08:00
|
|
|
static bool bt_has_free_tags(struct blk_mq_bitmap_tags *bt)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < bt->map_nr; i++) {
|
2014-05-19 23:17:48 +08:00
|
|
|
struct blk_align_bitmap *bm = &bt->map[i];
|
2014-05-09 23:36:49 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = find_first_zero_bit(&bm->word, bm->depth);
|
|
|
|
if (ret < bm->depth)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool blk_mq_has_free_tags(struct blk_mq_tags *tags)
|
|
|
|
{
|
2014-05-09 23:36:49 +08:00
|
|
|
if (!tags)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return bt_has_free_tags(&tags->bitmap_tags);
|
|
|
|
}
|
|
|
|
|
2014-06-18 13:12:35 +08:00
|
|
|
static inline int bt_index_inc(int index)
|
2014-05-14 05:10:52 +08:00
|
|
|
{
|
2014-06-18 13:12:35 +08:00
|
|
|
return (index + 1) & (BT_WAIT_QUEUES - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void bt_index_atomic_inc(atomic_t *index)
|
|
|
|
{
|
|
|
|
int old = atomic_read(index);
|
|
|
|
int new = bt_index_inc(old);
|
|
|
|
atomic_cmpxchg(index, old, new);
|
2014-05-14 05:10:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If a previously inactive queue goes active, bump the active user count.
|
|
|
|
*/
|
|
|
|
bool __blk_mq_tag_busy(struct blk_mq_hw_ctx *hctx)
|
|
|
|
{
|
|
|
|
if (!test_bit(BLK_MQ_S_TAG_ACTIVE, &hctx->state) &&
|
|
|
|
!test_and_set_bit(BLK_MQ_S_TAG_ACTIVE, &hctx->state))
|
|
|
|
atomic_inc(&hctx->tags->active_queues);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-12-23 05:04:42 +08:00
|
|
|
* Wakeup all potentially sleeping on tags
|
2014-05-14 05:10:52 +08:00
|
|
|
*/
|
2014-12-23 05:04:42 +08:00
|
|
|
void blk_mq_tag_wakeup_all(struct blk_mq_tags *tags, bool include_reserve)
|
2014-05-14 05:10:52 +08:00
|
|
|
{
|
|
|
|
struct blk_mq_bitmap_tags *bt;
|
|
|
|
int i, wake_index;
|
|
|
|
|
blk-mq: fix waitqueue_active without memory barrier in block/blk-mq-tag.c
blk_mq_tag_update_depth() seems to be missing a memory barrier which
might cause the waker to not notice the waiter and fail to send a
wake_up as in the following figure.
blk_mq_tag_update_depth bt_get
------------------------------------------------------------------------
if (waitqueue_active(&bs->wait))
/* The CPU might reorder the test for
the waitqueue up here, before
prior writes complete */
prepare_to_wait(&bs->wait, &wait,
TASK_UNINTERRUPTIBLE);
tag = __bt_get(hctx, bt, last_tag,
tags);
/* Value set in bt_update_count not
visible yet */
bt_update_count(&tags->bitmap_tags, tdepth);
/* blk_mq_tag_wakeup_all(tags, false); */
bt = &tags->bitmap_tags;
wake_index = atomic_read(&bt->wake_index);
...
io_schedule();
------------------------------------------------------------------------
This patch adds the missing memory barrier.
I found this issue when I was looking through the linux source code
for places calling waitqueue_active() before wake_up*(), but without
preceding memory barriers, after sending a patch to fix a similar
issue in drivers/tty/n_tty.c (Details about the original issue can be
found here: https://lkml.org/lkml/2015/9/28/849).
Signed-off-by: Kosuke Tatsukawa <tatsu@ab.jp.nec.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-10-09 08:35:38 +08:00
|
|
|
/*
|
|
|
|
* Make sure all changes prior to this are visible from other CPUs.
|
|
|
|
*/
|
|
|
|
smp_mb();
|
2014-05-14 05:10:52 +08:00
|
|
|
bt = &tags->bitmap_tags;
|
2014-06-18 13:12:35 +08:00
|
|
|
wake_index = atomic_read(&bt->wake_index);
|
2014-05-14 05:10:52 +08:00
|
|
|
for (i = 0; i < BT_WAIT_QUEUES; i++) {
|
|
|
|
struct bt_wait_state *bs = &bt->bs[wake_index];
|
|
|
|
|
|
|
|
if (waitqueue_active(&bs->wait))
|
|
|
|
wake_up(&bs->wait);
|
|
|
|
|
2014-06-18 13:12:35 +08:00
|
|
|
wake_index = bt_index_inc(wake_index);
|
2014-05-14 05:10:52 +08:00
|
|
|
}
|
2014-12-23 05:04:42 +08:00
|
|
|
|
|
|
|
if (include_reserve) {
|
|
|
|
bt = &tags->breserved_tags;
|
|
|
|
if (waitqueue_active(&bt->bs[0].wait))
|
|
|
|
wake_up(&bt->bs[0].wait);
|
|
|
|
}
|
2014-05-14 05:10:52 +08:00
|
|
|
}
|
|
|
|
|
2014-05-21 01:49:02 +08:00
|
|
|
/*
|
|
|
|
* If a previously busy queue goes inactive, potential waiters could now
|
|
|
|
* be allowed to queue. Wake them up and check.
|
|
|
|
*/
|
|
|
|
void __blk_mq_tag_idle(struct blk_mq_hw_ctx *hctx)
|
|
|
|
{
|
|
|
|
struct blk_mq_tags *tags = hctx->tags;
|
|
|
|
|
|
|
|
if (!test_and_clear_bit(BLK_MQ_S_TAG_ACTIVE, &hctx->state))
|
|
|
|
return;
|
|
|
|
|
|
|
|
atomic_dec(&tags->active_queues);
|
|
|
|
|
2014-12-23 05:04:42 +08:00
|
|
|
blk_mq_tag_wakeup_all(tags, false);
|
2014-05-21 01:49:02 +08:00
|
|
|
}
|
|
|
|
|
2014-05-14 05:10:52 +08:00
|
|
|
/*
|
|
|
|
* For shared tag users, we track the number of currently active users
|
|
|
|
* and attempt to provide a fair share of the tag depth for each of them.
|
|
|
|
*/
|
|
|
|
static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx,
|
|
|
|
struct blk_mq_bitmap_tags *bt)
|
|
|
|
{
|
|
|
|
unsigned int depth, users;
|
|
|
|
|
|
|
|
if (!hctx || !(hctx->flags & BLK_MQ_F_TAG_SHARED))
|
|
|
|
return true;
|
|
|
|
if (!test_bit(BLK_MQ_S_TAG_ACTIVE, &hctx->state))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't try dividing an ant
|
|
|
|
*/
|
|
|
|
if (bt->depth == 1)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
users = atomic_read(&hctx->tags->active_queues);
|
|
|
|
if (!users)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allow at least some tags
|
|
|
|
*/
|
|
|
|
depth = max((bt->depth + users - 1) / users, 4U);
|
|
|
|
return atomic_read(&hctx->nr_active) < depth;
|
|
|
|
}
|
|
|
|
|
2015-01-24 05:18:00 +08:00
|
|
|
static int __bt_get_word(struct blk_align_bitmap *bm, unsigned int last_tag,
|
|
|
|
bool nowrap)
|
2014-05-09 23:36:49 +08:00
|
|
|
{
|
2015-01-14 23:49:55 +08:00
|
|
|
int tag, org_last_tag = last_tag;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
tag = find_next_zero_bit(&bm->word, bm->depth, last_tag);
|
|
|
|
if (unlikely(tag >= bm->depth)) {
|
2014-05-09 23:36:49 +08:00
|
|
|
/*
|
2015-01-14 23:49:55 +08:00
|
|
|
* We started with an offset, and we didn't reset the
|
|
|
|
* offset to 0 in a failure case, so start from 0 to
|
2014-05-09 23:36:49 +08:00
|
|
|
* exhaust the map.
|
|
|
|
*/
|
2015-01-24 05:18:00 +08:00
|
|
|
if (org_last_tag && last_tag && !nowrap) {
|
2015-01-14 23:49:55 +08:00
|
|
|
last_tag = org_last_tag = 0;
|
|
|
|
continue;
|
2014-05-09 23:36:49 +08:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2015-01-14 23:49:55 +08:00
|
|
|
|
|
|
|
if (!test_and_set_bit(tag, &bm->word))
|
|
|
|
break;
|
|
|
|
|
2014-05-09 23:36:49 +08:00
|
|
|
last_tag = tag + 1;
|
2015-01-14 23:49:55 +08:00
|
|
|
if (last_tag >= bm->depth - 1)
|
|
|
|
last_tag = 0;
|
|
|
|
}
|
2014-05-09 23:36:49 +08:00
|
|
|
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
2015-01-24 05:18:00 +08:00
|
|
|
#define BT_ALLOC_RR(tags) (tags->alloc_policy == BLK_TAG_ALLOC_RR)
|
|
|
|
|
2014-05-09 23:36:49 +08:00
|
|
|
/*
|
|
|
|
* Straight forward bitmap tag implementation, where each bit is a tag
|
|
|
|
* (cleared == free, and set == busy). The small twist is using per-cpu
|
|
|
|
* last_tag caches, which blk-mq stores in the blk_mq_ctx software queue
|
|
|
|
* contexts. This enables us to drastically limit the space searched,
|
|
|
|
* without dirtying an extra shared cacheline like we would if we stored
|
|
|
|
* the cache value inside the shared blk_mq_bitmap_tags structure. On top
|
|
|
|
* of that, each word of tags is in a separate cacheline. This means that
|
|
|
|
* multiple users will tend to stick to different cachelines, at least
|
|
|
|
* until the map is exhausted.
|
|
|
|
*/
|
2014-05-14 05:10:52 +08:00
|
|
|
static int __bt_get(struct blk_mq_hw_ctx *hctx, struct blk_mq_bitmap_tags *bt,
|
2015-01-24 05:18:00 +08:00
|
|
|
unsigned int *tag_cache, struct blk_mq_tags *tags)
|
2014-05-09 23:36:49 +08:00
|
|
|
{
|
|
|
|
unsigned int last_tag, org_last_tag;
|
|
|
|
int index, i, tag;
|
|
|
|
|
2014-05-14 05:10:52 +08:00
|
|
|
if (!hctx_may_queue(hctx, bt))
|
|
|
|
return -1;
|
|
|
|
|
2014-05-09 23:36:49 +08:00
|
|
|
last_tag = org_last_tag = *tag_cache;
|
2014-05-10 03:41:15 +08:00
|
|
|
index = TAG_TO_INDEX(bt, last_tag);
|
2014-05-09 23:36:49 +08:00
|
|
|
|
|
|
|
for (i = 0; i < bt->map_nr; i++) {
|
2015-01-24 05:18:00 +08:00
|
|
|
tag = __bt_get_word(&bt->map[index], TAG_TO_BIT(bt, last_tag),
|
|
|
|
BT_ALLOC_RR(tags));
|
2014-05-09 23:36:49 +08:00
|
|
|
if (tag != -1) {
|
2014-05-10 03:41:15 +08:00
|
|
|
tag += (index << bt->bits_per_word);
|
2014-05-09 23:36:49 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2015-01-14 23:49:55 +08:00
|
|
|
/*
|
|
|
|
* Jump to next index, and reset the last tag to be the
|
|
|
|
* first tag of that index
|
|
|
|
*/
|
|
|
|
index++;
|
|
|
|
last_tag = (index << bt->bits_per_word);
|
|
|
|
|
|
|
|
if (index >= bt->map_nr) {
|
2014-05-09 23:36:49 +08:00
|
|
|
index = 0;
|
2015-01-14 23:49:55 +08:00
|
|
|
last_tag = 0;
|
|
|
|
}
|
2014-05-09 23:36:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
*tag_cache = 0;
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only update the cache from the allocation path, if we ended
|
|
|
|
* up using the specific cached tag.
|
|
|
|
*/
|
|
|
|
done:
|
2015-01-24 05:18:00 +08:00
|
|
|
if (tag == org_last_tag || unlikely(BT_ALLOC_RR(tags))) {
|
2014-05-09 23:36:49 +08:00
|
|
|
last_tag = tag + 1;
|
|
|
|
if (last_tag >= bt->depth - 1)
|
|
|
|
last_tag = 0;
|
|
|
|
|
|
|
|
*tag_cache = last_tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct bt_wait_state *bt_wait_ptr(struct blk_mq_bitmap_tags *bt,
|
|
|
|
struct blk_mq_hw_ctx *hctx)
|
|
|
|
{
|
|
|
|
struct bt_wait_state *bs;
|
2014-06-18 13:12:35 +08:00
|
|
|
int wait_index;
|
2014-05-09 23:36:49 +08:00
|
|
|
|
|
|
|
if (!hctx)
|
|
|
|
return &bt->bs[0];
|
|
|
|
|
2014-06-18 13:12:35 +08:00
|
|
|
wait_index = atomic_read(&hctx->wait_index);
|
|
|
|
bs = &bt->bs[wait_index];
|
|
|
|
bt_index_atomic_inc(&hctx->wait_index);
|
2014-05-09 23:36:49 +08:00
|
|
|
return bs;
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
}
|
|
|
|
|
2014-06-01 00:43:37 +08:00
|
|
|
static int bt_get(struct blk_mq_alloc_data *data,
|
|
|
|
struct blk_mq_bitmap_tags *bt,
|
|
|
|
struct blk_mq_hw_ctx *hctx,
|
2015-01-24 05:18:00 +08:00
|
|
|
unsigned int *last_tag, struct blk_mq_tags *tags)
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
{
|
2014-05-09 23:36:49 +08:00
|
|
|
struct bt_wait_state *bs;
|
|
|
|
DEFINE_WAIT(wait);
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
int tag;
|
|
|
|
|
2015-01-24 05:18:00 +08:00
|
|
|
tag = __bt_get(hctx, bt, last_tag, tags);
|
2014-05-09 23:36:49 +08:00
|
|
|
if (tag != -1)
|
|
|
|
return tag;
|
|
|
|
|
2015-11-26 16:13:05 +08:00
|
|
|
if (data->flags & BLK_MQ_REQ_NOWAIT)
|
2014-05-09 23:36:49 +08:00
|
|
|
return -1;
|
|
|
|
|
2014-12-15 23:30:26 +08:00
|
|
|
bs = bt_wait_ptr(bt, hctx);
|
2014-05-09 23:36:49 +08:00
|
|
|
do {
|
|
|
|
prepare_to_wait(&bs->wait, &wait, TASK_UNINTERRUPTIBLE);
|
|
|
|
|
2015-01-24 05:18:00 +08:00
|
|
|
tag = __bt_get(hctx, bt, last_tag, tags);
|
2014-05-09 23:36:49 +08:00
|
|
|
if (tag != -1)
|
|
|
|
break;
|
|
|
|
|
2014-12-08 23:46:34 +08:00
|
|
|
/*
|
|
|
|
* We're out of tags on this hardware queue, kick any
|
|
|
|
* pending IO submits before going to sleep waiting for
|
2015-03-19 07:06:18 +08:00
|
|
|
* some to complete. Note that hctx can be NULL here for
|
|
|
|
* reserved tag allocation.
|
2014-12-08 23:46:34 +08:00
|
|
|
*/
|
2015-03-19 07:06:18 +08:00
|
|
|
if (hctx)
|
|
|
|
blk_mq_run_hw_queue(hctx, false);
|
2014-12-08 23:46:34 +08:00
|
|
|
|
2014-12-08 23:49:06 +08:00
|
|
|
/*
|
|
|
|
* Retry tag allocation after running the hardware queue,
|
|
|
|
* as running the queue may also have found completions.
|
|
|
|
*/
|
2015-01-24 05:18:00 +08:00
|
|
|
tag = __bt_get(hctx, bt, last_tag, tags);
|
2014-12-08 23:49:06 +08:00
|
|
|
if (tag != -1)
|
|
|
|
break;
|
|
|
|
|
2014-06-01 00:43:37 +08:00
|
|
|
blk_mq_put_ctx(data->ctx);
|
|
|
|
|
2014-05-09 23:36:49 +08:00
|
|
|
io_schedule();
|
2014-06-01 00:43:37 +08:00
|
|
|
|
|
|
|
data->ctx = blk_mq_get_ctx(data->q);
|
|
|
|
data->hctx = data->q->mq_ops->map_queue(data->q,
|
|
|
|
data->ctx->cpu);
|
2015-11-26 16:13:05 +08:00
|
|
|
if (data->flags & BLK_MQ_REQ_RESERVED) {
|
2014-06-01 00:43:37 +08:00
|
|
|
bt = &data->hctx->tags->breserved_tags;
|
|
|
|
} else {
|
|
|
|
last_tag = &data->ctx->last_tag;
|
|
|
|
hctx = data->hctx;
|
|
|
|
bt = &hctx->tags->bitmap_tags;
|
|
|
|
}
|
2014-12-15 23:30:26 +08:00
|
|
|
finish_wait(&bs->wait, &wait);
|
|
|
|
bs = bt_wait_ptr(bt, hctx);
|
2014-05-09 23:36:49 +08:00
|
|
|
} while (1);
|
|
|
|
|
|
|
|
finish_wait(&bs->wait, &wait);
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
2014-06-01 00:43:37 +08:00
|
|
|
static unsigned int __blk_mq_get_tag(struct blk_mq_alloc_data *data)
|
2014-05-09 23:36:49 +08:00
|
|
|
{
|
|
|
|
int tag;
|
|
|
|
|
2014-06-01 00:43:37 +08:00
|
|
|
tag = bt_get(data, &data->hctx->tags->bitmap_tags, data->hctx,
|
2015-01-24 05:18:00 +08:00
|
|
|
&data->ctx->last_tag, data->hctx->tags);
|
2014-05-09 23:36:49 +08:00
|
|
|
if (tag >= 0)
|
2014-06-01 00:43:37 +08:00
|
|
|
return tag + data->hctx->tags->nr_reserved_tags;
|
2014-05-09 23:36:49 +08:00
|
|
|
|
|
|
|
return BLK_MQ_TAG_FAIL;
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
}
|
|
|
|
|
2014-06-01 00:43:37 +08:00
|
|
|
static unsigned int __blk_mq_get_reserved_tag(struct blk_mq_alloc_data *data)
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
{
|
2014-05-09 23:36:49 +08:00
|
|
|
int tag, zero = 0;
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
|
2014-06-01 00:43:37 +08:00
|
|
|
if (unlikely(!data->hctx->tags->nr_reserved_tags)) {
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
WARN_ON_ONCE(1);
|
|
|
|
return BLK_MQ_TAG_FAIL;
|
|
|
|
}
|
|
|
|
|
2015-01-24 05:18:00 +08:00
|
|
|
tag = bt_get(data, &data->hctx->tags->breserved_tags, NULL, &zero,
|
|
|
|
data->hctx->tags);
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
if (tag < 0)
|
|
|
|
return BLK_MQ_TAG_FAIL;
|
2014-05-09 23:36:49 +08:00
|
|
|
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
2014-06-01 00:43:37 +08:00
|
|
|
unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data)
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
{
|
2015-11-26 16:13:05 +08:00
|
|
|
if (data->flags & BLK_MQ_REQ_RESERVED)
|
|
|
|
return __blk_mq_get_reserved_tag(data);
|
|
|
|
return __blk_mq_get_tag(data);
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
}
|
|
|
|
|
2014-05-09 23:36:49 +08:00
|
|
|
static struct bt_wait_state *bt_wake_ptr(struct blk_mq_bitmap_tags *bt)
|
|
|
|
{
|
|
|
|
int i, wake_index;
|
|
|
|
|
2014-06-18 13:12:35 +08:00
|
|
|
wake_index = atomic_read(&bt->wake_index);
|
2014-05-09 23:36:49 +08:00
|
|
|
for (i = 0; i < BT_WAIT_QUEUES; i++) {
|
|
|
|
struct bt_wait_state *bs = &bt->bs[wake_index];
|
|
|
|
|
|
|
|
if (waitqueue_active(&bs->wait)) {
|
2014-06-18 13:12:35 +08:00
|
|
|
int o = atomic_read(&bt->wake_index);
|
|
|
|
if (wake_index != o)
|
|
|
|
atomic_cmpxchg(&bt->wake_index, o, wake_index);
|
2014-05-09 23:36:49 +08:00
|
|
|
|
|
|
|
return bs;
|
|
|
|
}
|
|
|
|
|
2014-06-18 13:12:35 +08:00
|
|
|
wake_index = bt_index_inc(wake_index);
|
2014-05-09 23:36:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bt_clear_tag(struct blk_mq_bitmap_tags *bt, unsigned int tag)
|
|
|
|
{
|
2014-05-10 03:41:15 +08:00
|
|
|
const int index = TAG_TO_INDEX(bt, tag);
|
2014-05-09 23:36:49 +08:00
|
|
|
struct bt_wait_state *bs;
|
2014-06-12 23:05:37 +08:00
|
|
|
int wait_cnt;
|
2014-05-09 23:36:49 +08:00
|
|
|
|
2014-12-09 23:58:35 +08:00
|
|
|
clear_bit(TAG_TO_BIT(bt, tag), &bt->map[index].word);
|
|
|
|
|
|
|
|
/* Ensure that the wait list checks occur after clear_bit(). */
|
|
|
|
smp_mb();
|
2014-05-09 23:36:49 +08:00
|
|
|
|
|
|
|
bs = bt_wake_ptr(bt);
|
2014-06-12 23:05:37 +08:00
|
|
|
if (!bs)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wait_cnt = atomic_dec_return(&bs->wait_cnt);
|
2014-10-07 22:45:21 +08:00
|
|
|
if (unlikely(wait_cnt < 0))
|
|
|
|
wait_cnt = atomic_inc_return(&bs->wait_cnt);
|
2014-06-12 23:05:37 +08:00
|
|
|
if (wait_cnt == 0) {
|
|
|
|
atomic_add(bt->wake_cnt, &bs->wait_cnt);
|
2014-06-18 13:12:35 +08:00
|
|
|
bt_index_atomic_inc(&bt->wake_index);
|
2014-05-09 23:36:49 +08:00
|
|
|
wake_up(&bs->wait);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 05:10:52 +08:00
|
|
|
void blk_mq_put_tag(struct blk_mq_hw_ctx *hctx, unsigned int tag,
|
2014-05-09 23:36:49 +08:00
|
|
|
unsigned int *last_tag)
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
{
|
2014-05-14 05:10:52 +08:00
|
|
|
struct blk_mq_tags *tags = hctx->tags;
|
|
|
|
|
2014-05-09 23:36:49 +08:00
|
|
|
if (tag >= tags->nr_reserved_tags) {
|
|
|
|
const int real_tag = tag - tags->nr_reserved_tags;
|
|
|
|
|
2014-11-25 06:52:30 +08:00
|
|
|
BUG_ON(real_tag >= tags->nr_tags);
|
|
|
|
bt_clear_tag(&tags->bitmap_tags, real_tag);
|
2015-01-24 05:18:00 +08:00
|
|
|
if (likely(tags->alloc_policy == BLK_TAG_ALLOC_FIFO))
|
|
|
|
*last_tag = real_tag;
|
2014-11-25 06:52:30 +08:00
|
|
|
} else {
|
|
|
|
BUG_ON(tag >= tags->nr_reserved_tags);
|
|
|
|
bt_clear_tag(&tags->breserved_tags, tag);
|
|
|
|
}
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
}
|
|
|
|
|
2014-09-14 07:40:11 +08:00
|
|
|
static void bt_for_each(struct blk_mq_hw_ctx *hctx,
|
|
|
|
struct blk_mq_bitmap_tags *bt, unsigned int off,
|
|
|
|
busy_iter_fn *fn, void *data, bool reserved)
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
{
|
2014-09-14 07:40:11 +08:00
|
|
|
struct request *rq;
|
|
|
|
int bit, i;
|
2014-05-09 23:36:49 +08:00
|
|
|
|
|
|
|
for (i = 0; i < bt->map_nr; i++) {
|
2014-05-19 23:17:48 +08:00
|
|
|
struct blk_align_bitmap *bm = &bt->map[i];
|
2014-05-09 23:36:49 +08:00
|
|
|
|
2014-09-14 07:40:11 +08:00
|
|
|
for (bit = find_first_bit(&bm->word, bm->depth);
|
|
|
|
bit < bm->depth;
|
|
|
|
bit = find_next_bit(&bm->word, bm->depth, bit + 1)) {
|
2015-08-09 15:41:51 +08:00
|
|
|
rq = hctx->tags->rqs[off + bit];
|
2014-09-14 07:40:11 +08:00
|
|
|
if (rq->q == hctx->queue)
|
|
|
|
fn(hctx, rq, data, reserved);
|
|
|
|
}
|
2014-05-09 23:36:49 +08:00
|
|
|
|
2014-05-10 03:41:15 +08:00
|
|
|
off += (1 << bt->bits_per_word);
|
2014-05-09 23:36:49 +08:00
|
|
|
}
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
}
|
|
|
|
|
2015-06-01 23:29:53 +08:00
|
|
|
static void bt_tags_for_each(struct blk_mq_tags *tags,
|
|
|
|
struct blk_mq_bitmap_tags *bt, unsigned int off,
|
|
|
|
busy_tag_iter_fn *fn, void *data, bool reserved)
|
|
|
|
{
|
|
|
|
struct request *rq;
|
|
|
|
int bit, i;
|
|
|
|
|
|
|
|
if (!tags->rqs)
|
|
|
|
return;
|
|
|
|
for (i = 0; i < bt->map_nr; i++) {
|
|
|
|
struct blk_align_bitmap *bm = &bt->map[i];
|
|
|
|
|
|
|
|
for (bit = find_first_bit(&bm->word, bm->depth);
|
|
|
|
bit < bm->depth;
|
|
|
|
bit = find_next_bit(&bm->word, bm->depth, bit + 1)) {
|
2015-08-09 15:41:51 +08:00
|
|
|
rq = tags->rqs[off + bit];
|
2015-06-01 23:29:53 +08:00
|
|
|
fn(rq, data, reserved);
|
|
|
|
}
|
|
|
|
|
|
|
|
off += (1 << bt->bits_per_word);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-10 19:58:49 +08:00
|
|
|
static void blk_mq_all_tag_busy_iter(struct blk_mq_tags *tags,
|
|
|
|
busy_tag_iter_fn *fn, void *priv)
|
2015-06-01 23:29:53 +08:00
|
|
|
{
|
|
|
|
if (tags->nr_reserved_tags)
|
|
|
|
bt_tags_for_each(tags, &tags->breserved_tags, 0, fn, priv, true);
|
|
|
|
bt_tags_for_each(tags, &tags->bitmap_tags, tags->nr_reserved_tags, fn, priv,
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
|
2016-03-10 19:58:46 +08:00
|
|
|
void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
|
|
|
|
busy_tag_iter_fn *fn, void *priv)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < tagset->nr_hw_queues; i++) {
|
|
|
|
if (tagset->tags && tagset->tags[i])
|
|
|
|
blk_mq_all_tag_busy_iter(tagset->tags[i], fn, priv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(blk_mq_tagset_busy_iter);
|
|
|
|
|
2015-09-28 03:01:51 +08:00
|
|
|
void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_iter_fn *fn,
|
2014-09-14 07:40:11 +08:00
|
|
|
void *priv)
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
{
|
2015-09-28 03:01:51 +08:00
|
|
|
struct blk_mq_hw_ctx *hctx;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
|
|
queue_for_each_hw_ctx(q, hctx, i) {
|
|
|
|
struct blk_mq_tags *tags = hctx->tags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If not software queues are currently mapped to this
|
|
|
|
* hardware queue, there's nothing to check
|
|
|
|
*/
|
|
|
|
if (!blk_mq_hw_queue_mapped(hctx))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (tags->nr_reserved_tags)
|
|
|
|
bt_for_each(hctx, &tags->breserved_tags, 0, fn, priv, true);
|
|
|
|
bt_for_each(hctx, &tags->bitmap_tags, tags->nr_reserved_tags, fn, priv,
|
|
|
|
false);
|
|
|
|
}
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-05-09 23:36:49 +08:00
|
|
|
static unsigned int bt_unused_tags(struct blk_mq_bitmap_tags *bt)
|
|
|
|
{
|
|
|
|
unsigned int i, used;
|
|
|
|
|
|
|
|
for (i = 0, used = 0; i < bt->map_nr; i++) {
|
2014-05-19 23:17:48 +08:00
|
|
|
struct blk_align_bitmap *bm = &bt->map[i];
|
2014-05-09 23:36:49 +08:00
|
|
|
|
|
|
|
used += bitmap_weight(&bm->word, bm->depth);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bt->depth - used;
|
|
|
|
}
|
|
|
|
|
2014-05-21 01:49:02 +08:00
|
|
|
static void bt_update_count(struct blk_mq_bitmap_tags *bt,
|
|
|
|
unsigned int depth)
|
|
|
|
{
|
|
|
|
unsigned int tags_per_word = 1U << bt->bits_per_word;
|
|
|
|
unsigned int map_depth = depth;
|
|
|
|
|
|
|
|
if (depth) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < bt->map_nr; i++) {
|
|
|
|
bt->map[i].depth = min(map_depth, tags_per_word);
|
|
|
|
map_depth -= bt->map[i].depth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bt->wake_cnt = BT_WAIT_BATCH;
|
2014-10-07 22:39:20 +08:00
|
|
|
if (bt->wake_cnt > depth / BT_WAIT_QUEUES)
|
|
|
|
bt->wake_cnt = max(1U, depth / BT_WAIT_QUEUES);
|
2014-05-21 01:49:02 +08:00
|
|
|
|
|
|
|
bt->depth = depth;
|
|
|
|
}
|
|
|
|
|
2014-05-09 23:36:49 +08:00
|
|
|
static int bt_alloc(struct blk_mq_bitmap_tags *bt, unsigned int depth,
|
|
|
|
int node, bool reserved)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2014-05-10 03:41:15 +08:00
|
|
|
bt->bits_per_word = ilog2(BITS_PER_LONG);
|
|
|
|
|
2014-05-09 23:36:49 +08:00
|
|
|
/*
|
|
|
|
* Depth can be zero for reserved tags, that's not a failure
|
|
|
|
* condition.
|
|
|
|
*/
|
|
|
|
if (depth) {
|
2014-05-21 01:49:02 +08:00
|
|
|
unsigned int nr, tags_per_word;
|
2014-05-10 03:41:15 +08:00
|
|
|
|
|
|
|
tags_per_word = (1 << bt->bits_per_word);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the tag space is small, shrink the number of tags
|
|
|
|
* per word so we spread over a few cachelines, at least.
|
|
|
|
* If less than 4 tags, just forget about it, it's not
|
|
|
|
* going to work optimally anyway.
|
|
|
|
*/
|
|
|
|
if (depth >= 4) {
|
|
|
|
while (tags_per_word * 4 > depth) {
|
|
|
|
bt->bits_per_word--;
|
|
|
|
tags_per_word = (1 << bt->bits_per_word);
|
|
|
|
}
|
|
|
|
}
|
2014-05-09 23:36:49 +08:00
|
|
|
|
2014-05-10 03:41:15 +08:00
|
|
|
nr = ALIGN(depth, tags_per_word) / tags_per_word;
|
2014-05-19 23:17:48 +08:00
|
|
|
bt->map = kzalloc_node(nr * sizeof(struct blk_align_bitmap),
|
2014-05-09 23:36:49 +08:00
|
|
|
GFP_KERNEL, node);
|
|
|
|
if (!bt->map)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
bt->map_nr = nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt->bs = kzalloc(BT_WAIT_QUEUES * sizeof(*bt->bs), GFP_KERNEL);
|
|
|
|
if (!bt->bs) {
|
|
|
|
kfree(bt->map);
|
2015-02-12 00:32:30 +08:00
|
|
|
bt->map = NULL;
|
2014-05-09 23:36:49 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2014-06-18 04:37:23 +08:00
|
|
|
bt_update_count(bt, depth);
|
|
|
|
|
|
|
|
for (i = 0; i < BT_WAIT_QUEUES; i++) {
|
2014-05-09 23:36:49 +08:00
|
|
|
init_waitqueue_head(&bt->bs[i].wait);
|
2014-06-18 04:37:23 +08:00
|
|
|
atomic_set(&bt->bs[i].wait_cnt, bt->wake_cnt);
|
|
|
|
}
|
2014-05-09 23:36:49 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bt_free(struct blk_mq_bitmap_tags *bt)
|
|
|
|
{
|
|
|
|
kfree(bt->map);
|
|
|
|
kfree(bt->bs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct blk_mq_tags *blk_mq_init_bitmap_tags(struct blk_mq_tags *tags,
|
2015-01-24 05:18:00 +08:00
|
|
|
int node, int alloc_policy)
|
2014-05-09 23:36:49 +08:00
|
|
|
{
|
|
|
|
unsigned int depth = tags->nr_tags - tags->nr_reserved_tags;
|
|
|
|
|
2015-01-24 05:18:00 +08:00
|
|
|
tags->alloc_policy = alloc_policy;
|
|
|
|
|
2014-05-09 23:36:49 +08:00
|
|
|
if (bt_alloc(&tags->bitmap_tags, depth, node, false))
|
|
|
|
goto enomem;
|
|
|
|
if (bt_alloc(&tags->breserved_tags, tags->nr_reserved_tags, node, true))
|
|
|
|
goto enomem;
|
|
|
|
|
|
|
|
return tags;
|
|
|
|
enomem:
|
|
|
|
bt_free(&tags->bitmap_tags);
|
|
|
|
kfree(tags);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags,
|
2015-01-24 05:18:00 +08:00
|
|
|
unsigned int reserved_tags,
|
|
|
|
int node, int alloc_policy)
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
{
|
|
|
|
struct blk_mq_tags *tags;
|
|
|
|
|
|
|
|
if (total_tags > BLK_MQ_TAG_MAX) {
|
|
|
|
pr_err("blk-mq: tag depth too large\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
tags = kzalloc_node(sizeof(*tags), GFP_KERNEL, node);
|
|
|
|
if (!tags)
|
|
|
|
return NULL;
|
|
|
|
|
2015-06-01 23:29:53 +08:00
|
|
|
if (!zalloc_cpumask_var(&tags->cpumask, GFP_KERNEL)) {
|
|
|
|
kfree(tags);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
tags->nr_tags = total_tags;
|
|
|
|
tags->nr_reserved_tags = reserved_tags;
|
|
|
|
|
2015-01-24 05:18:00 +08:00
|
|
|
return blk_mq_init_bitmap_tags(tags, node, alloc_policy);
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void blk_mq_free_tags(struct blk_mq_tags *tags)
|
|
|
|
{
|
2014-05-09 23:36:49 +08:00
|
|
|
bt_free(&tags->bitmap_tags);
|
|
|
|
bt_free(&tags->breserved_tags);
|
2015-10-14 13:02:15 +08:00
|
|
|
free_cpumask_var(tags->cpumask);
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
kfree(tags);
|
|
|
|
}
|
|
|
|
|
2014-05-09 23:36:49 +08:00
|
|
|
void blk_mq_tag_init_last_tag(struct blk_mq_tags *tags, unsigned int *tag)
|
|
|
|
{
|
|
|
|
unsigned int depth = tags->nr_tags - tags->nr_reserved_tags;
|
|
|
|
|
2014-05-11 05:43:14 +08:00
|
|
|
*tag = prandom_u32() % depth;
|
2014-05-09 23:36:49 +08:00
|
|
|
}
|
|
|
|
|
2014-05-21 01:49:02 +08:00
|
|
|
int blk_mq_tag_update_depth(struct blk_mq_tags *tags, unsigned int tdepth)
|
|
|
|
{
|
|
|
|
tdepth -= tags->nr_reserved_tags;
|
|
|
|
if (tdepth > tags->nr_tags)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't need (or can't) update reserved tags here, they remain
|
|
|
|
* static and should never need resizing.
|
|
|
|
*/
|
|
|
|
bt_update_count(&tags->bitmap_tags, tdepth);
|
2014-12-23 05:04:42 +08:00
|
|
|
blk_mq_tag_wakeup_all(tags, false);
|
2014-05-21 01:49:02 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-30 21:45:11 +08:00
|
|
|
/**
|
|
|
|
* blk_mq_unique_tag() - return a tag that is unique queue-wide
|
|
|
|
* @rq: request for which to compute a unique tag
|
|
|
|
*
|
|
|
|
* The tag field in struct request is unique per hardware queue but not over
|
|
|
|
* all hardware queues. Hence this function that returns a tag with the
|
|
|
|
* hardware context index in the upper bits and the per hardware queue tag in
|
|
|
|
* the lower bits.
|
|
|
|
*
|
|
|
|
* Note: When called for a request that is queued on a non-multiqueue request
|
|
|
|
* queue, the hardware context index is set to zero.
|
|
|
|
*/
|
|
|
|
u32 blk_mq_unique_tag(struct request *rq)
|
|
|
|
{
|
|
|
|
struct request_queue *q = rq->q;
|
|
|
|
struct blk_mq_hw_ctx *hctx;
|
|
|
|
int hwq = 0;
|
|
|
|
|
|
|
|
if (q->mq_ops) {
|
|
|
|
hctx = q->mq_ops->map_queue(q, rq->mq_ctx->cpu);
|
|
|
|
hwq = hctx->queue_num;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (hwq << BLK_MQ_UNIQUE_TAG_BITS) |
|
|
|
|
(rq->tag & BLK_MQ_UNIQUE_TAG_MASK);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(blk_mq_unique_tag);
|
|
|
|
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
ssize_t blk_mq_tag_sysfs_show(struct blk_mq_tags *tags, char *page)
|
|
|
|
{
|
|
|
|
char *orig_page = page;
|
2014-05-09 23:36:49 +08:00
|
|
|
unsigned int free, res;
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
|
|
|
|
if (!tags)
|
|
|
|
return 0;
|
|
|
|
|
2014-05-10 03:41:15 +08:00
|
|
|
page += sprintf(page, "nr_tags=%u, reserved_tags=%u, "
|
|
|
|
"bits_per_word=%u\n",
|
|
|
|
tags->nr_tags, tags->nr_reserved_tags,
|
|
|
|
tags->bitmap_tags.bits_per_word);
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
|
2014-05-09 23:36:49 +08:00
|
|
|
free = bt_unused_tags(&tags->bitmap_tags);
|
|
|
|
res = bt_unused_tags(&tags->breserved_tags);
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
|
2014-05-09 23:36:49 +08:00
|
|
|
page += sprintf(page, "nr_free=%u, nr_reserved=%u\n", free, res);
|
2014-05-14 05:10:52 +08:00
|
|
|
page += sprintf(page, "active_queues=%u\n", atomic_read(&tags->active_queues));
|
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>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
|
|
|
|
return page - orig_page;
|
|
|
|
}
|