2008-01-29 14:53:40 +01:00
|
|
|
/*
|
2017-08-24 20:09:25 +02:00
|
|
|
* Functions to sequence PREFLUSH and FUA writes.
|
2011-01-25 12:43:54 +01:00
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Max Planck Institute for Gravitational Physics
|
|
|
|
* Copyright (C) 2011 Tejun Heo <tj@kernel.org>
|
|
|
|
*
|
|
|
|
* This file is released under the GPLv2.
|
|
|
|
*
|
2017-08-24 20:09:25 +02:00
|
|
|
* REQ_{PREFLUSH|FUA} requests are decomposed to sequences consisted of three
|
2011-01-25 12:43:54 +01:00
|
|
|
* optional steps - PREFLUSH, DATA and POSTFLUSH - according to the request
|
|
|
|
* properties and hardware capability.
|
|
|
|
*
|
2016-06-05 21:32:25 +02:00
|
|
|
* If a request doesn't have data, only REQ_PREFLUSH makes sense, which
|
|
|
|
* indicates a simple flush request. If there is data, REQ_PREFLUSH indicates
|
2011-01-25 12:43:54 +01:00
|
|
|
* that the device cache should be flushed before the data is executed, and
|
|
|
|
* REQ_FUA means that the data must be on non-volatile media on request
|
|
|
|
* completion.
|
|
|
|
*
|
2017-08-24 20:09:25 +02:00
|
|
|
* If the device doesn't have writeback cache, PREFLUSH and FUA don't make any
|
|
|
|
* difference. The requests are either completed immediately if there's no data
|
|
|
|
* or executed as normal requests otherwise.
|
2011-01-25 12:43:54 +01:00
|
|
|
*
|
2016-06-05 21:32:25 +02:00
|
|
|
* If the device has writeback cache and supports FUA, REQ_PREFLUSH is
|
2011-01-25 12:43:54 +01:00
|
|
|
* translated to PREFLUSH but REQ_FUA is passed down directly with DATA.
|
|
|
|
*
|
2016-06-05 21:32:25 +02:00
|
|
|
* If the device has writeback cache and doesn't support FUA, REQ_PREFLUSH
|
|
|
|
* is translated to PREFLUSH and REQ_FUA to POSTFLUSH.
|
2011-01-25 12:43:54 +01:00
|
|
|
*
|
|
|
|
* The actual execution of flush is double buffered. Whenever a request
|
|
|
|
* needs to execute PRE or POSTFLUSH, it queues at
|
2014-09-25 17:23:43 +02:00
|
|
|
* fq->flush_queue[fq->flush_pending_idx]. Once certain criteria are met, a
|
2016-06-05 21:32:23 +02:00
|
|
|
* REQ_OP_FLUSH is issued and the pending_idx is toggled. When the flush
|
2011-01-25 12:43:54 +01:00
|
|
|
* completes, all the requests which were pending are proceeded to the next
|
2017-08-24 20:09:25 +02:00
|
|
|
* step. This allows arbitrary merging of different types of PREFLUSH/FUA
|
2011-01-25 12:43:54 +01:00
|
|
|
* requests.
|
|
|
|
*
|
|
|
|
* Currently, the following conditions are used to determine when to issue
|
|
|
|
* flush.
|
|
|
|
*
|
|
|
|
* C1. At any given time, only one flush shall be in progress. This makes
|
|
|
|
* double buffering sufficient.
|
|
|
|
*
|
|
|
|
* C2. Flush is deferred if any request is executing DATA of its sequence.
|
|
|
|
* This avoids issuing separate POSTFLUSHes for requests which shared
|
|
|
|
* PREFLUSH.
|
|
|
|
*
|
|
|
|
* C3. The second condition is ignored if there is a request which has
|
|
|
|
* waited longer than FLUSH_PENDING_TIMEOUT. This is to avoid
|
|
|
|
* starvation in the unlikely case where there are continuous stream of
|
2017-08-24 20:09:25 +02:00
|
|
|
* FUA (without PREFLUSH) requests.
|
2011-01-25 12:43:54 +01:00
|
|
|
*
|
|
|
|
* For devices which support FUA, it isn't clear whether C2 (and thus C3)
|
|
|
|
* is beneficial.
|
|
|
|
*
|
2017-08-24 20:09:25 +02:00
|
|
|
* Note that a sequenced PREFLUSH/FUA request with DATA is completed twice.
|
2011-01-25 12:43:54 +01:00
|
|
|
* Once while executing DATA and again after the whole sequence is
|
|
|
|
* complete. The first completion updates the contained bio but doesn't
|
|
|
|
* finish it so that the bio submitter is notified only after the whole
|
2016-10-20 15:12:13 +02:00
|
|
|
* sequence is complete. This is implemented by testing RQF_FLUSH_SEQ in
|
2011-01-25 12:43:54 +01:00
|
|
|
* req_bio_endio().
|
|
|
|
*
|
2017-08-24 20:09:25 +02:00
|
|
|
* The above peculiarity requires that each PREFLUSH/FUA request has only one
|
2011-01-25 12:43:54 +01:00
|
|
|
* bio attached to it, which is guaranteed as they aren't allowed to be
|
|
|
|
* merged in the usual way.
|
2008-01-29 14:53:40 +01:00
|
|
|
*/
|
2011-01-25 12:43:54 +01:00
|
|
|
|
2008-01-29 14:53:40 +01:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/bio.h>
|
|
|
|
#include <linux/blkdev.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 09:04:11 +01:00
|
|
|
#include <linux/gfp.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 10:20:05 +02:00
|
|
|
#include <linux/blk-mq.h>
|
2008-01-29 14:53:40 +01:00
|
|
|
|
|
|
|
#include "blk.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 10:20:05 +02:00
|
|
|
#include "blk-mq.h"
|
2015-08-09 09:41:51 +02:00
|
|
|
#include "blk-mq-tag.h"
|
2017-01-17 14:03:22 +01:00
|
|
|
#include "blk-mq-sched.h"
|
2008-01-29 14:53:40 +01:00
|
|
|
|
2017-08-24 20:09:25 +02:00
|
|
|
/* PREFLUSH/FUA sequences */
|
2010-09-03 11:56:17 +02:00
|
|
|
enum {
|
2011-01-25 12:43:54 +01:00
|
|
|
REQ_FSEQ_PREFLUSH = (1 << 0), /* pre-flushing in progress */
|
|
|
|
REQ_FSEQ_DATA = (1 << 1), /* data write in progress */
|
|
|
|
REQ_FSEQ_POSTFLUSH = (1 << 2), /* post-flushing in progress */
|
|
|
|
REQ_FSEQ_DONE = (1 << 3),
|
|
|
|
|
|
|
|
REQ_FSEQ_ACTIONS = REQ_FSEQ_PREFLUSH | REQ_FSEQ_DATA |
|
|
|
|
REQ_FSEQ_POSTFLUSH,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If flush has been pending longer than the following timeout,
|
|
|
|
* it's issued even if flush_data requests are still in flight.
|
|
|
|
*/
|
|
|
|
FLUSH_PENDING_TIMEOUT = 5 * HZ,
|
2010-09-03 11:56:17 +02:00
|
|
|
};
|
|
|
|
|
2014-09-25 17:23:45 +02:00
|
|
|
static bool blk_kick_flush(struct request_queue *q,
|
2018-06-06 16:21:40 +02:00
|
|
|
struct blk_flush_queue *fq, unsigned int flags);
|
2010-09-03 11:56:16 +02:00
|
|
|
|
2016-04-13 21:33:19 +02:00
|
|
|
static unsigned int blk_flush_policy(unsigned long fflags, struct request *rq)
|
2008-01-29 14:53:40 +01:00
|
|
|
{
|
2011-01-25 12:43:54 +01:00
|
|
|
unsigned int policy = 0;
|
2008-01-29 14:53:40 +01:00
|
|
|
|
2011-08-09 20:32:09 +02:00
|
|
|
if (blk_rq_sectors(rq))
|
|
|
|
policy |= REQ_FSEQ_DATA;
|
|
|
|
|
2016-04-13 21:33:19 +02:00
|
|
|
if (fflags & (1UL << QUEUE_FLAG_WC)) {
|
2016-06-05 21:32:25 +02:00
|
|
|
if (rq->cmd_flags & REQ_PREFLUSH)
|
2011-01-25 12:43:54 +01:00
|
|
|
policy |= REQ_FSEQ_PREFLUSH;
|
2016-04-13 21:33:19 +02:00
|
|
|
if (!(fflags & (1UL << QUEUE_FLAG_FUA)) &&
|
|
|
|
(rq->cmd_flags & REQ_FUA))
|
2011-01-25 12:43:54 +01:00
|
|
|
policy |= REQ_FSEQ_POSTFLUSH;
|
2010-09-03 11:56:16 +02:00
|
|
|
}
|
2011-01-25 12:43:54 +01:00
|
|
|
return policy;
|
2008-01-29 14:53:40 +01:00
|
|
|
}
|
|
|
|
|
2011-01-25 12:43:54 +01:00
|
|
|
static unsigned int blk_flush_cur_seq(struct request *rq)
|
2010-09-03 11:56:17 +02:00
|
|
|
{
|
2011-01-25 12:43:54 +01:00
|
|
|
return 1 << ffz(rq->flush.seq);
|
|
|
|
}
|
2010-09-03 11:56:17 +02:00
|
|
|
|
2011-01-25 12:43:54 +01:00
|
|
|
static void blk_flush_restore_request(struct request *rq)
|
|
|
|
{
|
2010-09-03 11:56:17 +02:00
|
|
|
/*
|
2011-01-25 12:43:54 +01:00
|
|
|
* After flush data completion, @rq->bio is %NULL but we need to
|
|
|
|
* complete the bio again. @rq->biotail is guaranteed to equal the
|
|
|
|
* original @rq->bio. Restore it.
|
2010-09-03 11:56:17 +02:00
|
|
|
*/
|
2011-01-25 12:43:54 +01:00
|
|
|
rq->bio = rq->biotail;
|
|
|
|
|
|
|
|
/* make @rq a normal request */
|
2016-10-20 15:12:13 +02:00
|
|
|
rq->rq_flags &= ~RQF_FLUSH_SEQ;
|
block: fix flush machinery for stacking drivers with differring flush flags
Commit ae1b1539622fb46e51b4d13b3f9e5f4c713f86ae, block: reimplement
FLUSH/FUA to support merge, introduced a performance regression when
running any sort of fsyncing workload using dm-multipath and certain
storage (in our case, an HP EVA). The test I ran was fs_mark, and it
dropped from ~800 files/sec on ext4 to ~100 files/sec. It turns out
that dm-multipath always advertised flush+fua support, and passed
commands on down the stack, where those flags used to get stripped off.
The above commit changed that behavior:
static inline struct request *__elv_next_request(struct request_queue *q)
{
struct request *rq;
while (1) {
- while (!list_empty(&q->queue_head)) {
+ if (!list_empty(&q->queue_head)) {
rq = list_entry_rq(q->queue_head.next);
- if (!(rq->cmd_flags & (REQ_FLUSH | REQ_FUA)) ||
- (rq->cmd_flags & REQ_FLUSH_SEQ))
- return rq;
- rq = blk_do_flush(q, rq);
- if (rq)
- return rq;
+ return rq;
}
Note that previously, a command would come in here, have
REQ_FLUSH|REQ_FUA set, and then get handed off to blk_do_flush:
struct request *blk_do_flush(struct request_queue *q, struct request *rq)
{
unsigned int fflags = q->flush_flags; /* may change, cache it */
bool has_flush = fflags & REQ_FLUSH, has_fua = fflags & REQ_FUA;
bool do_preflush = has_flush && (rq->cmd_flags & REQ_FLUSH);
bool do_postflush = has_flush && !has_fua && (rq->cmd_flags &
REQ_FUA);
unsigned skip = 0;
...
if (blk_rq_sectors(rq) && !do_preflush && !do_postflush) {
rq->cmd_flags &= ~REQ_FLUSH;
if (!has_fua)
rq->cmd_flags &= ~REQ_FUA;
return rq;
}
So, the flush machinery was bypassed in such cases (q->flush_flags == 0
&& rq->cmd_flags & (REQ_FLUSH|REQ_FUA)).
Now, however, we don't get into the flush machinery at all. Instead,
__elv_next_request just hands a request with flush and fua bits set to
the scsi_request_fn, even if the underlying request_queue does not
support flush or fua.
The agreed upon approach is to fix the flush machinery to allow
stacking. While this isn't used in practice (since there is only one
request-based dm target, and that target will now reflect the flush
flags of the underlying device), it does future-proof the solution, and
make it function as designed.
In order to make this work, I had to add a field to the struct request,
inside the flush structure (to store the original req->end_io). Shaohua
had suggested overloading the union with rb_node and completion_data,
but the completion data is used by device mapper and can also be used by
other drivers. So, I didn't see a way around the additional field.
I tested this patch on an HP EVA with both ext4 and xfs, and it recovers
the lost performance. Comments and other testers, as always, are
appreciated.
Cheers,
Jeff
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
2011-08-15 21:37:25 +02:00
|
|
|
rq->end_io = rq->flush.saved_end_io;
|
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 10:20:05 +02:00
|
|
|
}
|
|
|
|
|
2014-03-09 04:19:20 +01:00
|
|
|
static bool blk_flush_queue_rq(struct request *rq, bool add_front)
|
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 10:20:05 +02:00
|
|
|
{
|
2018-10-13 23:44:12 +02:00
|
|
|
blk_mq_add_to_requeue_list(rq, add_front, true);
|
|
|
|
return false;
|
2010-09-03 11:56:17 +02:00
|
|
|
}
|
|
|
|
|
2011-01-25 12:43:54 +01:00
|
|
|
/**
|
|
|
|
* blk_flush_complete_seq - complete flush sequence
|
2017-08-24 20:09:25 +02:00
|
|
|
* @rq: PREFLUSH/FUA request being sequenced
|
2014-09-25 17:23:45 +02:00
|
|
|
* @fq: flush queue
|
2011-01-25 12:43:54 +01:00
|
|
|
* @seq: sequences to complete (mask of %REQ_FSEQ_*, can be zero)
|
|
|
|
* @error: whether an error occurred
|
|
|
|
*
|
|
|
|
* @rq just completed @seq part of its flush sequence, record the
|
|
|
|
* completion and trigger the next step.
|
|
|
|
*
|
|
|
|
* CONTEXT:
|
2014-09-25 17:23:43 +02:00
|
|
|
* spin_lock_irq(q->queue_lock or fq->mq_flush_lock)
|
2011-01-25 12:43:54 +01:00
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* %true if requests were added to the dispatch queue, %false otherwise.
|
|
|
|
*/
|
2014-09-25 17:23:45 +02:00
|
|
|
static bool blk_flush_complete_seq(struct request *rq,
|
|
|
|
struct blk_flush_queue *fq,
|
2017-06-03 09:38:04 +02:00
|
|
|
unsigned int seq, blk_status_t error)
|
2008-01-29 14:53:40 +01:00
|
|
|
{
|
2011-01-25 12:43:54 +01:00
|
|
|
struct request_queue *q = rq->q;
|
2014-09-25 17:23:43 +02:00
|
|
|
struct list_head *pending = &fq->flush_queue[fq->flush_pending_idx];
|
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 10:20:05 +02:00
|
|
|
bool queued = false, kicked;
|
2018-06-09 14:37:14 +02:00
|
|
|
unsigned int cmd_flags;
|
2011-01-25 12:43:54 +01:00
|
|
|
|
|
|
|
BUG_ON(rq->flush.seq & seq);
|
|
|
|
rq->flush.seq |= seq;
|
2018-06-09 14:37:14 +02:00
|
|
|
cmd_flags = rq->cmd_flags;
|
2011-01-25 12:43:54 +01:00
|
|
|
|
|
|
|
if (likely(!error))
|
|
|
|
seq = blk_flush_cur_seq(rq);
|
|
|
|
else
|
|
|
|
seq = REQ_FSEQ_DONE;
|
|
|
|
|
|
|
|
switch (seq) {
|
|
|
|
case REQ_FSEQ_PREFLUSH:
|
|
|
|
case REQ_FSEQ_POSTFLUSH:
|
|
|
|
/* queue for flush */
|
|
|
|
if (list_empty(pending))
|
2014-09-25 17:23:43 +02:00
|
|
|
fq->flush_pending_since = jiffies;
|
2011-01-25 12:43:54 +01:00
|
|
|
list_move_tail(&rq->flush.list, pending);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REQ_FSEQ_DATA:
|
2014-09-25 17:23:43 +02:00
|
|
|
list_move_tail(&rq->flush.list, &fq->flush_data_in_flight);
|
2014-03-09 04:19:20 +01:00
|
|
|
queued = blk_flush_queue_rq(rq, true);
|
2011-01-25 12:43:54 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case REQ_FSEQ_DONE:
|
|
|
|
/*
|
|
|
|
* @rq was previously adjusted by blk_flush_issue() for
|
|
|
|
* flush sequencing and may already have gone through the
|
|
|
|
* flush data request completion path. Restore @rq for
|
|
|
|
* normal completion and end it.
|
|
|
|
*/
|
|
|
|
BUG_ON(!list_empty(&rq->queuelist));
|
|
|
|
list_del_init(&rq->flush.list);
|
|
|
|
blk_flush_restore_request(rq);
|
2018-10-13 23:44:12 +02:00
|
|
|
blk_mq_end_request(rq, error);
|
2011-01-25 12:43:54 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
|
2018-06-09 14:37:14 +02:00
|
|
|
kicked = blk_kick_flush(q, fq, cmd_flags);
|
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 10:20:05 +02:00
|
|
|
return kicked | queued;
|
2008-01-29 14:53:40 +01:00
|
|
|
}
|
|
|
|
|
2017-06-03 09:38:04 +02:00
|
|
|
static void flush_end_io(struct request *flush_rq, blk_status_t error)
|
2008-01-29 14:53:40 +01:00
|
|
|
{
|
2011-01-25 12:43:54 +01:00
|
|
|
struct request_queue *q = flush_rq->q;
|
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 10:20:05 +02:00
|
|
|
struct list_head *running;
|
2011-01-25 12:43:54 +01:00
|
|
|
bool queued = false;
|
|
|
|
struct request *rq, *n;
|
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 10:20:05 +02:00
|
|
|
unsigned long flags = 0;
|
2014-09-25 17:23:46 +02:00
|
|
|
struct blk_flush_queue *fq = blk_get_flush_queue(q, flush_rq->mq_ctx);
|
2018-10-13 23:44:12 +02:00
|
|
|
struct blk_mq_hw_ctx *hctx;
|
2011-01-25 12:43:54 +01:00
|
|
|
|
2018-10-13 23:44:12 +02:00
|
|
|
/* release the tag's ownership to the req cloned from */
|
|
|
|
spin_lock_irqsave(&fq->mq_flush_lock, flags);
|
|
|
|
hctx = blk_mq_map_queue(q, flush_rq->mq_ctx->cpu);
|
|
|
|
if (!q->elevator) {
|
|
|
|
blk_mq_tag_set_rq(hctx, flush_rq->tag, fq->orig_rq);
|
|
|
|
flush_rq->tag = -1;
|
|
|
|
} else {
|
|
|
|
blk_mq_put_driver_tag_hctx(hctx, flush_rq);
|
|
|
|
flush_rq->internal_tag = -1;
|
2014-05-30 16:06:42 +02:00
|
|
|
}
|
2014-02-10 17:29:00 +01:00
|
|
|
|
2014-09-25 17:23:43 +02:00
|
|
|
running = &fq->flush_queue[fq->flush_running_idx];
|
|
|
|
BUG_ON(fq->flush_pending_idx == fq->flush_running_idx);
|
2011-01-25 12:43:54 +01:00
|
|
|
|
|
|
|
/* account completion of the flush request */
|
2014-09-25 17:23:43 +02:00
|
|
|
fq->flush_running_idx ^= 1;
|
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 10:20:05 +02:00
|
|
|
|
2011-01-25 12:43:54 +01:00
|
|
|
/* and push the waiting requests to the next stage */
|
|
|
|
list_for_each_entry_safe(rq, n, running, flush.list) {
|
|
|
|
unsigned int seq = blk_flush_cur_seq(rq);
|
|
|
|
|
|
|
|
BUG_ON(seq != REQ_FSEQ_PREFLUSH && seq != REQ_FSEQ_POSTFLUSH);
|
2014-09-25 17:23:45 +02:00
|
|
|
queued |= blk_flush_complete_seq(rq, fq, seq, error);
|
2011-01-25 12:43:54 +01:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:23:43 +02:00
|
|
|
fq->flush_queue_delayed = 0;
|
2018-10-13 23:44:12 +02:00
|
|
|
spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
|
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 10:20:05 +02:00
|
|
|
}
|
|
|
|
|
2011-01-25 12:43:54 +01:00
|
|
|
/**
|
|
|
|
* blk_kick_flush - consider issuing flush request
|
|
|
|
* @q: request_queue being kicked
|
2014-09-25 17:23:45 +02:00
|
|
|
* @fq: flush queue
|
2018-06-06 16:21:40 +02:00
|
|
|
* @flags: cmd_flags of the original request
|
2011-01-25 12:43:54 +01:00
|
|
|
*
|
|
|
|
* Flush related states of @q have changed, consider issuing flush request.
|
|
|
|
* Please read the comment at the top of this file for more info.
|
|
|
|
*
|
|
|
|
* CONTEXT:
|
2014-09-25 17:23:43 +02:00
|
|
|
* spin_lock_irq(q->queue_lock or fq->mq_flush_lock)
|
2011-01-25 12:43:54 +01:00
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* %true if flush was issued, %false otherwise.
|
|
|
|
*/
|
2018-06-06 16:21:40 +02:00
|
|
|
static bool blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq,
|
|
|
|
unsigned int flags)
|
2008-01-29 14:53:40 +01:00
|
|
|
{
|
2014-09-25 17:23:43 +02:00
|
|
|
struct list_head *pending = &fq->flush_queue[fq->flush_pending_idx];
|
2011-01-25 12:43:54 +01:00
|
|
|
struct request *first_rq =
|
|
|
|
list_first_entry(pending, struct request, flush.list);
|
2014-09-25 17:23:43 +02:00
|
|
|
struct request *flush_rq = fq->flush_rq;
|
2018-10-13 23:44:12 +02:00
|
|
|
struct blk_mq_hw_ctx *hctx;
|
2011-01-25 12:43:54 +01:00
|
|
|
|
|
|
|
/* C1 described at the top of this file */
|
2014-09-25 17:23:43 +02:00
|
|
|
if (fq->flush_pending_idx != fq->flush_running_idx || list_empty(pending))
|
2011-01-25 12:43:54 +01:00
|
|
|
return false;
|
|
|
|
|
2017-02-17 19:40:44 +01:00
|
|
|
/* C2 and C3
|
|
|
|
*
|
|
|
|
* For blk-mq + scheduling, we can risk having all driver tags
|
|
|
|
* assigned to empty flushes, and we deadlock if we are expecting
|
|
|
|
* other requests to make progress. Don't defer for that case.
|
|
|
|
*/
|
2014-09-25 17:23:43 +02:00
|
|
|
if (!list_empty(&fq->flush_data_in_flight) &&
|
2017-02-17 19:40:44 +01:00
|
|
|
!(q->mq_ops && q->elevator) &&
|
2011-01-25 12:43:54 +01:00
|
|
|
time_before(jiffies,
|
2014-09-25 17:23:43 +02:00
|
|
|
fq->flush_pending_since + FLUSH_PENDING_TIMEOUT))
|
2011-01-25 12:43:54 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Issue flush and toggle pending_idx. This makes pending_idx
|
|
|
|
* different from running_idx, which means flush is in flight.
|
|
|
|
*/
|
2014-09-25 17:23:43 +02:00
|
|
|
fq->flush_pending_idx ^= 1;
|
2014-02-10 17:29:00 +01:00
|
|
|
|
2014-09-25 17:23:42 +02:00
|
|
|
blk_rq_init(q, flush_rq);
|
2014-09-25 17:23:47 +02:00
|
|
|
|
|
|
|
/*
|
2017-11-02 16:24:38 +01:00
|
|
|
* In case of none scheduler, borrow tag from the first request
|
|
|
|
* since they can't be in flight at the same time. And acquire
|
|
|
|
* the tag's ownership for flush req.
|
|
|
|
*
|
|
|
|
* In case of IO scheduler, flush rq need to borrow scheduler tag
|
|
|
|
* just for cheating put/get driver tag.
|
2014-09-25 17:23:47 +02:00
|
|
|
*/
|
2018-10-13 23:44:12 +02:00
|
|
|
flush_rq->mq_ctx = first_rq->mq_ctx;
|
|
|
|
|
|
|
|
if (!q->elevator) {
|
|
|
|
fq->orig_rq = first_rq;
|
|
|
|
flush_rq->tag = first_rq->tag;
|
|
|
|
hctx = blk_mq_map_queue(q, first_rq->mq_ctx->cpu);
|
|
|
|
blk_mq_tag_set_rq(hctx, first_rq->tag, flush_rq);
|
|
|
|
} else {
|
|
|
|
flush_rq->internal_tag = first_rq->internal_tag;
|
2014-09-25 17:23:47 +02: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 10:20:05 +02:00
|
|
|
|
2016-11-01 14:40:10 +01:00
|
|
|
flush_rq->cmd_flags = REQ_OP_FLUSH | REQ_PREFLUSH;
|
2018-06-06 16:21:40 +02:00
|
|
|
flush_rq->cmd_flags |= (flags & REQ_DRV) | (flags & REQ_FAILFAST_MASK);
|
2016-10-20 15:12:13 +02:00
|
|
|
flush_rq->rq_flags |= RQF_FLUSH_SEQ;
|
2014-09-25 17:23:42 +02:00
|
|
|
flush_rq->rq_disk = first_rq->rq_disk;
|
|
|
|
flush_rq->end_io = flush_end_io;
|
2011-01-25 12:43:54 +01:00
|
|
|
|
2014-09-25 17:23:42 +02:00
|
|
|
return blk_flush_queue_rq(flush_rq, false);
|
2008-01-29 14:53:40 +01:00
|
|
|
}
|
|
|
|
|
2017-06-03 09:38:04 +02:00
|
|
|
static void mq_flush_data_end_io(struct request *rq, blk_status_t error)
|
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 10:20:05 +02:00
|
|
|
{
|
|
|
|
struct request_queue *q = rq->q;
|
|
|
|
struct blk_mq_hw_ctx *hctx;
|
2014-09-25 17:23:46 +02:00
|
|
|
struct blk_mq_ctx *ctx = rq->mq_ctx;
|
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 10:20:05 +02:00
|
|
|
unsigned long flags;
|
2014-09-25 17:23:46 +02:00
|
|
|
struct blk_flush_queue *fq = blk_get_flush_queue(q, ctx);
|
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 10:20:05 +02:00
|
|
|
|
2016-09-14 16:18:54 +02:00
|
|
|
hctx = blk_mq_map_queue(q, ctx->cpu);
|
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 10:20:05 +02:00
|
|
|
|
2017-11-02 16:24:38 +01:00
|
|
|
if (q->elevator) {
|
|
|
|
WARN_ON(rq->tag < 0);
|
|
|
|
blk_mq_put_driver_tag_hctx(hctx, rq);
|
|
|
|
}
|
|
|
|
|
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 10:20:05 +02:00
|
|
|
/*
|
|
|
|
* After populating an empty queue, kick it to avoid stall. Read
|
|
|
|
* the comment in flush_end_io().
|
|
|
|
*/
|
2014-09-25 17:23:43 +02:00
|
|
|
spin_lock_irqsave(&fq->mq_flush_lock, flags);
|
2017-01-17 14:03:22 +01:00
|
|
|
blk_flush_complete_seq(rq, fq, REQ_FSEQ_DATA, error);
|
2014-09-25 17:23:43 +02:00
|
|
|
spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
|
2017-01-17 14:03:22 +01:00
|
|
|
|
|
|
|
blk_mq_run_hw_queue(hctx, true);
|
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 10:20:05 +02:00
|
|
|
}
|
|
|
|
|
2011-01-25 12:43:54 +01:00
|
|
|
/**
|
2017-08-24 20:09:25 +02:00
|
|
|
* blk_insert_flush - insert a new PREFLUSH/FUA request
|
2011-01-25 12:43:54 +01:00
|
|
|
* @rq: request to insert
|
|
|
|
*
|
2011-03-30 09:52:30 +02:00
|
|
|
* To be called from __elv_add_request() for %ELEVATOR_INSERT_FLUSH insertions.
|
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 10:20:05 +02:00
|
|
|
* or __blk_mq_run_hw_queue() to dispatch request.
|
2011-01-25 12:43:54 +01:00
|
|
|
* @rq is being submitted. Analyze what needs to be done and put it on the
|
|
|
|
* right queue.
|
|
|
|
*/
|
|
|
|
void blk_insert_flush(struct request *rq)
|
2008-01-29 14:53:40 +01:00
|
|
|
{
|
2011-01-25 12:43:54 +01:00
|
|
|
struct request_queue *q = rq->q;
|
2016-04-13 21:33:19 +02:00
|
|
|
unsigned long fflags = q->queue_flags; /* may change, cache */
|
2011-01-25 12:43:54 +01:00
|
|
|
unsigned int policy = blk_flush_policy(fflags, rq);
|
2014-09-25 17:23:46 +02:00
|
|
|
struct blk_flush_queue *fq = blk_get_flush_queue(q, rq->mq_ctx);
|
2008-01-29 14:53:40 +01:00
|
|
|
|
2011-01-25 12:43:54 +01:00
|
|
|
/*
|
|
|
|
* @policy now records what operations need to be done. Adjust
|
2016-06-05 21:32:25 +02:00
|
|
|
* REQ_PREFLUSH and FUA for the driver.
|
2011-01-25 12:43:54 +01:00
|
|
|
*/
|
2016-06-05 21:32:25 +02:00
|
|
|
rq->cmd_flags &= ~REQ_PREFLUSH;
|
2016-04-13 21:33:19 +02:00
|
|
|
if (!(fflags & (1UL << QUEUE_FLAG_FUA)))
|
2011-01-25 12:43:54 +01:00
|
|
|
rq->cmd_flags &= ~REQ_FUA;
|
|
|
|
|
2016-11-09 03:39:28 +01:00
|
|
|
/*
|
|
|
|
* REQ_PREFLUSH|REQ_FUA implies REQ_SYNC, so if we clear any
|
|
|
|
* of those flags, we have to set REQ_SYNC to avoid skewing
|
|
|
|
* the request accounting.
|
|
|
|
*/
|
|
|
|
rq->cmd_flags |= REQ_SYNC;
|
|
|
|
|
block: fix flush machinery for stacking drivers with differring flush flags
Commit ae1b1539622fb46e51b4d13b3f9e5f4c713f86ae, block: reimplement
FLUSH/FUA to support merge, introduced a performance regression when
running any sort of fsyncing workload using dm-multipath and certain
storage (in our case, an HP EVA). The test I ran was fs_mark, and it
dropped from ~800 files/sec on ext4 to ~100 files/sec. It turns out
that dm-multipath always advertised flush+fua support, and passed
commands on down the stack, where those flags used to get stripped off.
The above commit changed that behavior:
static inline struct request *__elv_next_request(struct request_queue *q)
{
struct request *rq;
while (1) {
- while (!list_empty(&q->queue_head)) {
+ if (!list_empty(&q->queue_head)) {
rq = list_entry_rq(q->queue_head.next);
- if (!(rq->cmd_flags & (REQ_FLUSH | REQ_FUA)) ||
- (rq->cmd_flags & REQ_FLUSH_SEQ))
- return rq;
- rq = blk_do_flush(q, rq);
- if (rq)
- return rq;
+ return rq;
}
Note that previously, a command would come in here, have
REQ_FLUSH|REQ_FUA set, and then get handed off to blk_do_flush:
struct request *blk_do_flush(struct request_queue *q, struct request *rq)
{
unsigned int fflags = q->flush_flags; /* may change, cache it */
bool has_flush = fflags & REQ_FLUSH, has_fua = fflags & REQ_FUA;
bool do_preflush = has_flush && (rq->cmd_flags & REQ_FLUSH);
bool do_postflush = has_flush && !has_fua && (rq->cmd_flags &
REQ_FUA);
unsigned skip = 0;
...
if (blk_rq_sectors(rq) && !do_preflush && !do_postflush) {
rq->cmd_flags &= ~REQ_FLUSH;
if (!has_fua)
rq->cmd_flags &= ~REQ_FUA;
return rq;
}
So, the flush machinery was bypassed in such cases (q->flush_flags == 0
&& rq->cmd_flags & (REQ_FLUSH|REQ_FUA)).
Now, however, we don't get into the flush machinery at all. Instead,
__elv_next_request just hands a request with flush and fua bits set to
the scsi_request_fn, even if the underlying request_queue does not
support flush or fua.
The agreed upon approach is to fix the flush machinery to allow
stacking. While this isn't used in practice (since there is only one
request-based dm target, and that target will now reflect the flush
flags of the underlying device), it does future-proof the solution, and
make it function as designed.
In order to make this work, I had to add a field to the struct request,
inside the flush structure (to store the original req->end_io). Shaohua
had suggested overloading the union with rb_node and completion_data,
but the completion data is used by device mapper and can also be used by
other drivers. So, I didn't see a way around the additional field.
I tested this patch on an HP EVA with both ext4 and xfs, and it recovers
the lost performance. Comments and other testers, as always, are
appreciated.
Cheers,
Jeff
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
2011-08-15 21:37:25 +02:00
|
|
|
/*
|
|
|
|
* An empty flush handed down from a stacking driver may
|
|
|
|
* translate into nothing if the underlying device does not
|
|
|
|
* advertise a write-back cache. In this case, simply
|
|
|
|
* complete the request.
|
|
|
|
*/
|
|
|
|
if (!policy) {
|
2018-10-13 23:44:12 +02:00
|
|
|
blk_mq_end_request(rq, 0);
|
block: fix flush machinery for stacking drivers with differring flush flags
Commit ae1b1539622fb46e51b4d13b3f9e5f4c713f86ae, block: reimplement
FLUSH/FUA to support merge, introduced a performance regression when
running any sort of fsyncing workload using dm-multipath and certain
storage (in our case, an HP EVA). The test I ran was fs_mark, and it
dropped from ~800 files/sec on ext4 to ~100 files/sec. It turns out
that dm-multipath always advertised flush+fua support, and passed
commands on down the stack, where those flags used to get stripped off.
The above commit changed that behavior:
static inline struct request *__elv_next_request(struct request_queue *q)
{
struct request *rq;
while (1) {
- while (!list_empty(&q->queue_head)) {
+ if (!list_empty(&q->queue_head)) {
rq = list_entry_rq(q->queue_head.next);
- if (!(rq->cmd_flags & (REQ_FLUSH | REQ_FUA)) ||
- (rq->cmd_flags & REQ_FLUSH_SEQ))
- return rq;
- rq = blk_do_flush(q, rq);
- if (rq)
- return rq;
+ return rq;
}
Note that previously, a command would come in here, have
REQ_FLUSH|REQ_FUA set, and then get handed off to blk_do_flush:
struct request *blk_do_flush(struct request_queue *q, struct request *rq)
{
unsigned int fflags = q->flush_flags; /* may change, cache it */
bool has_flush = fflags & REQ_FLUSH, has_fua = fflags & REQ_FUA;
bool do_preflush = has_flush && (rq->cmd_flags & REQ_FLUSH);
bool do_postflush = has_flush && !has_fua && (rq->cmd_flags &
REQ_FUA);
unsigned skip = 0;
...
if (blk_rq_sectors(rq) && !do_preflush && !do_postflush) {
rq->cmd_flags &= ~REQ_FLUSH;
if (!has_fua)
rq->cmd_flags &= ~REQ_FUA;
return rq;
}
So, the flush machinery was bypassed in such cases (q->flush_flags == 0
&& rq->cmd_flags & (REQ_FLUSH|REQ_FUA)).
Now, however, we don't get into the flush machinery at all. Instead,
__elv_next_request just hands a request with flush and fua bits set to
the scsi_request_fn, even if the underlying request_queue does not
support flush or fua.
The agreed upon approach is to fix the flush machinery to allow
stacking. While this isn't used in practice (since there is only one
request-based dm target, and that target will now reflect the flush
flags of the underlying device), it does future-proof the solution, and
make it function as designed.
In order to make this work, I had to add a field to the struct request,
inside the flush structure (to store the original req->end_io). Shaohua
had suggested overloading the union with rb_node and completion_data,
but the completion data is used by device mapper and can also be used by
other drivers. So, I didn't see a way around the additional field.
I tested this patch on an HP EVA with both ext4 and xfs, and it recovers
the lost performance. Comments and other testers, as always, are
appreciated.
Cheers,
Jeff
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
2011-08-15 21:37:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-17 12:57:22 +02:00
|
|
|
BUG_ON(rq->bio != rq->biotail); /*assumes zero or single bio rq */
|
block: fix flush machinery for stacking drivers with differring flush flags
Commit ae1b1539622fb46e51b4d13b3f9e5f4c713f86ae, block: reimplement
FLUSH/FUA to support merge, introduced a performance regression when
running any sort of fsyncing workload using dm-multipath and certain
storage (in our case, an HP EVA). The test I ran was fs_mark, and it
dropped from ~800 files/sec on ext4 to ~100 files/sec. It turns out
that dm-multipath always advertised flush+fua support, and passed
commands on down the stack, where those flags used to get stripped off.
The above commit changed that behavior:
static inline struct request *__elv_next_request(struct request_queue *q)
{
struct request *rq;
while (1) {
- while (!list_empty(&q->queue_head)) {
+ if (!list_empty(&q->queue_head)) {
rq = list_entry_rq(q->queue_head.next);
- if (!(rq->cmd_flags & (REQ_FLUSH | REQ_FUA)) ||
- (rq->cmd_flags & REQ_FLUSH_SEQ))
- return rq;
- rq = blk_do_flush(q, rq);
- if (rq)
- return rq;
+ return rq;
}
Note that previously, a command would come in here, have
REQ_FLUSH|REQ_FUA set, and then get handed off to blk_do_flush:
struct request *blk_do_flush(struct request_queue *q, struct request *rq)
{
unsigned int fflags = q->flush_flags; /* may change, cache it */
bool has_flush = fflags & REQ_FLUSH, has_fua = fflags & REQ_FUA;
bool do_preflush = has_flush && (rq->cmd_flags & REQ_FLUSH);
bool do_postflush = has_flush && !has_fua && (rq->cmd_flags &
REQ_FUA);
unsigned skip = 0;
...
if (blk_rq_sectors(rq) && !do_preflush && !do_postflush) {
rq->cmd_flags &= ~REQ_FLUSH;
if (!has_fua)
rq->cmd_flags &= ~REQ_FUA;
return rq;
}
So, the flush machinery was bypassed in such cases (q->flush_flags == 0
&& rq->cmd_flags & (REQ_FLUSH|REQ_FUA)).
Now, however, we don't get into the flush machinery at all. Instead,
__elv_next_request just hands a request with flush and fua bits set to
the scsi_request_fn, even if the underlying request_queue does not
support flush or fua.
The agreed upon approach is to fix the flush machinery to allow
stacking. While this isn't used in practice (since there is only one
request-based dm target, and that target will now reflect the flush
flags of the underlying device), it does future-proof the solution, and
make it function as designed.
In order to make this work, I had to add a field to the struct request,
inside the flush structure (to store the original req->end_io). Shaohua
had suggested overloading the union with rb_node and completion_data,
but the completion data is used by device mapper and can also be used by
other drivers. So, I didn't see a way around the additional field.
I tested this patch on an HP EVA with both ext4 and xfs, and it recovers
the lost performance. Comments and other testers, as always, are
appreciated.
Cheers,
Jeff
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
2011-08-15 21:37:25 +02:00
|
|
|
|
2011-01-25 12:43:54 +01:00
|
|
|
/*
|
|
|
|
* If there's data but flush is not necessary, the request can be
|
|
|
|
* processed directly without going through flush machinery. Queue
|
|
|
|
* for normal execution.
|
|
|
|
*/
|
|
|
|
if ((policy & REQ_FSEQ_DATA) &&
|
|
|
|
!(policy & (REQ_FSEQ_PREFLUSH | REQ_FSEQ_POSTFLUSH))) {
|
2018-10-13 23:44:12 +02:00
|
|
|
blk_mq_request_bypass_insert(rq, false);
|
2011-01-25 12:43:54 +01:00
|
|
|
return;
|
2010-09-03 11:56:16 +02:00
|
|
|
}
|
2010-09-03 11:56:17 +02:00
|
|
|
|
2011-01-25 12:43:54 +01:00
|
|
|
/*
|
|
|
|
* @rq should go through flush machinery. Mark it part of flush
|
|
|
|
* sequence and submit for further processing.
|
|
|
|
*/
|
|
|
|
memset(&rq->flush, 0, sizeof(rq->flush));
|
|
|
|
INIT_LIST_HEAD(&rq->flush.list);
|
2016-10-20 15:12:13 +02:00
|
|
|
rq->rq_flags |= RQF_FLUSH_SEQ;
|
block: fix flush machinery for stacking drivers with differring flush flags
Commit ae1b1539622fb46e51b4d13b3f9e5f4c713f86ae, block: reimplement
FLUSH/FUA to support merge, introduced a performance regression when
running any sort of fsyncing workload using dm-multipath and certain
storage (in our case, an HP EVA). The test I ran was fs_mark, and it
dropped from ~800 files/sec on ext4 to ~100 files/sec. It turns out
that dm-multipath always advertised flush+fua support, and passed
commands on down the stack, where those flags used to get stripped off.
The above commit changed that behavior:
static inline struct request *__elv_next_request(struct request_queue *q)
{
struct request *rq;
while (1) {
- while (!list_empty(&q->queue_head)) {
+ if (!list_empty(&q->queue_head)) {
rq = list_entry_rq(q->queue_head.next);
- if (!(rq->cmd_flags & (REQ_FLUSH | REQ_FUA)) ||
- (rq->cmd_flags & REQ_FLUSH_SEQ))
- return rq;
- rq = blk_do_flush(q, rq);
- if (rq)
- return rq;
+ return rq;
}
Note that previously, a command would come in here, have
REQ_FLUSH|REQ_FUA set, and then get handed off to blk_do_flush:
struct request *blk_do_flush(struct request_queue *q, struct request *rq)
{
unsigned int fflags = q->flush_flags; /* may change, cache it */
bool has_flush = fflags & REQ_FLUSH, has_fua = fflags & REQ_FUA;
bool do_preflush = has_flush && (rq->cmd_flags & REQ_FLUSH);
bool do_postflush = has_flush && !has_fua && (rq->cmd_flags &
REQ_FUA);
unsigned skip = 0;
...
if (blk_rq_sectors(rq) && !do_preflush && !do_postflush) {
rq->cmd_flags &= ~REQ_FLUSH;
if (!has_fua)
rq->cmd_flags &= ~REQ_FUA;
return rq;
}
So, the flush machinery was bypassed in such cases (q->flush_flags == 0
&& rq->cmd_flags & (REQ_FLUSH|REQ_FUA)).
Now, however, we don't get into the flush machinery at all. Instead,
__elv_next_request just hands a request with flush and fua bits set to
the scsi_request_fn, even if the underlying request_queue does not
support flush or fua.
The agreed upon approach is to fix the flush machinery to allow
stacking. While this isn't used in practice (since there is only one
request-based dm target, and that target will now reflect the flush
flags of the underlying device), it does future-proof the solution, and
make it function as designed.
In order to make this work, I had to add a field to the struct request,
inside the flush structure (to store the original req->end_io). Shaohua
had suggested overloading the union with rb_node and completion_data,
but the completion data is used by device mapper and can also be used by
other drivers. So, I didn't see a way around the additional field.
I tested this patch on an HP EVA with both ext4 and xfs, and it recovers
the lost performance. Comments and other testers, as always, are
appreciated.
Cheers,
Jeff
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
2011-08-15 21:37:25 +02:00
|
|
|
rq->flush.saved_end_io = rq->end_io; /* Usually 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 10:20:05 +02:00
|
|
|
|
2018-10-13 23:44:12 +02:00
|
|
|
rq->end_io = mq_flush_data_end_io;
|
2011-01-25 12:43:54 +01:00
|
|
|
|
2018-10-13 23:44:12 +02:00
|
|
|
spin_lock_irq(&fq->mq_flush_lock);
|
2014-09-25 17:23:45 +02:00
|
|
|
blk_flush_complete_seq(rq, fq, REQ_FSEQ_ACTIONS & ~policy, 0);
|
2018-10-13 23:44:12 +02:00
|
|
|
spin_unlock_irq(&fq->mq_flush_lock);
|
2008-01-29 14:53:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* blkdev_issue_flush - queue a flush
|
|
|
|
* @bdev: blockdev to issue flush for
|
2010-04-28 15:55:06 +02:00
|
|
|
* @gfp_mask: memory allocation flags (for bio_alloc)
|
2008-01-29 14:53:40 +01:00
|
|
|
* @error_sector: error sector
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Issue a flush for the block device in question. Caller can supply
|
|
|
|
* room for storing the error offset in case of a flush error, if they
|
2017-01-23 20:43:21 +01:00
|
|
|
* wish to.
|
2008-01-29 14:53:40 +01:00
|
|
|
*/
|
2010-04-28 15:55:06 +02:00
|
|
|
int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
|
2010-09-16 20:51:46 +02:00
|
|
|
sector_t *error_sector)
|
2008-01-29 14:53:40 +01:00
|
|
|
{
|
|
|
|
struct request_queue *q;
|
|
|
|
struct bio *bio;
|
2010-04-28 15:55:06 +02:00
|
|
|
int ret = 0;
|
2008-01-29 14:53:40 +01:00
|
|
|
|
|
|
|
if (bdev->bd_disk == NULL)
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
q = bdev_get_queue(bdev);
|
|
|
|
if (!q)
|
|
|
|
return -ENXIO;
|
|
|
|
|
2010-07-13 09:50:50 +02:00
|
|
|
/*
|
|
|
|
* some block devices may not have their queue correctly set up here
|
|
|
|
* (e.g. loop device without a backing file) and so issuing a flush
|
|
|
|
* here will panic. Ensure there is a request function before issuing
|
2010-09-03 11:56:17 +02:00
|
|
|
* the flush.
|
2010-07-13 09:50:50 +02:00
|
|
|
*/
|
|
|
|
if (!q->make_request_fn)
|
|
|
|
return -ENXIO;
|
|
|
|
|
2010-04-28 15:55:06 +02:00
|
|
|
bio = bio_alloc(gfp_mask, 0);
|
2017-08-23 19:10:32 +02:00
|
|
|
bio_set_dev(bio, bdev);
|
2016-11-01 14:40:10 +01:00
|
|
|
bio->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH;
|
2008-01-29 14:53:40 +01:00
|
|
|
|
2016-06-05 21:31:41 +02:00
|
|
|
ret = submit_bio_wait(bio);
|
2010-09-16 20:51:46 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The driver must store the error location in ->bi_sector, if
|
|
|
|
* it supports it. For non-stacked drivers, this should be
|
|
|
|
* copied from blk_rq_pos(rq).
|
|
|
|
*/
|
|
|
|
if (error_sector)
|
2013-10-12 00:44:27 +02:00
|
|
|
*error_sector = bio->bi_iter.bi_sector;
|
2008-01-29 14:53:40 +01:00
|
|
|
|
|
|
|
bio_put(bio);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(blkdev_issue_flush);
|
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 10:20:05 +02:00
|
|
|
|
2014-09-25 17:23:47 +02:00
|
|
|
struct blk_flush_queue *blk_alloc_flush_queue(struct request_queue *q,
|
2018-10-12 12:07:26 +02:00
|
|
|
int node, int cmd_size, gfp_t flags)
|
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 10:20:05 +02:00
|
|
|
{
|
2014-09-25 17:23:43 +02:00
|
|
|
struct blk_flush_queue *fq;
|
|
|
|
int rq_sz = sizeof(struct request);
|
2014-09-25 17:23:39 +02:00
|
|
|
|
2018-10-12 12:07:26 +02:00
|
|
|
fq = kzalloc_node(sizeof(*fq), flags, node);
|
2014-09-25 17:23:43 +02:00
|
|
|
if (!fq)
|
|
|
|
goto fail;
|
2014-09-25 17:23:39 +02:00
|
|
|
|
2018-10-13 23:44:12 +02:00
|
|
|
spin_lock_init(&fq->mq_flush_lock);
|
2014-09-25 17:23:43 +02:00
|
|
|
|
2017-01-27 17:51:45 +01:00
|
|
|
rq_sz = round_up(rq_sz + cmd_size, cache_line_size());
|
2018-10-12 12:07:26 +02:00
|
|
|
fq->flush_rq = kzalloc_node(rq_sz, flags, node);
|
2014-09-25 17:23:43 +02:00
|
|
|
if (!fq->flush_rq)
|
|
|
|
goto fail_rq;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&fq->flush_queue[0]);
|
|
|
|
INIT_LIST_HEAD(&fq->flush_queue[1]);
|
|
|
|
INIT_LIST_HEAD(&fq->flush_data_in_flight);
|
|
|
|
|
|
|
|
return fq;
|
|
|
|
|
|
|
|
fail_rq:
|
|
|
|
kfree(fq);
|
|
|
|
fail:
|
|
|
|
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 10:20:05 +02:00
|
|
|
}
|
2014-09-25 17:23:40 +02:00
|
|
|
|
2014-09-25 17:23:44 +02:00
|
|
|
void blk_free_flush_queue(struct blk_flush_queue *fq)
|
2014-09-25 17:23:40 +02:00
|
|
|
{
|
2014-09-25 17:23:43 +02:00
|
|
|
/* bio based request queue hasn't flush queue */
|
|
|
|
if (!fq)
|
|
|
|
return;
|
2014-09-25 17:23:41 +02:00
|
|
|
|
2014-09-25 17:23:43 +02:00
|
|
|
kfree(fq->flush_rq);
|
|
|
|
kfree(fq);
|
|
|
|
}
|