2019-05-01 02:42:39 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2008-01-29 21:53:40 +08:00
|
|
|
/*
|
2017-08-25 02:09:25 +08:00
|
|
|
* Functions to sequence PREFLUSH and FUA writes.
|
2011-01-25 19:43:54 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Max Planck Institute for Gravitational Physics
|
|
|
|
* Copyright (C) 2011 Tejun Heo <tj@kernel.org>
|
|
|
|
*
|
2017-08-25 02:09:25 +08:00
|
|
|
* REQ_{PREFLUSH|FUA} requests are decomposed to sequences consisted of three
|
2011-01-25 19:43:54 +08:00
|
|
|
* optional steps - PREFLUSH, DATA and POSTFLUSH - according to the request
|
|
|
|
* properties and hardware capability.
|
|
|
|
*
|
2016-06-06 03:32:25 +08: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 19:43:54 +08: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-25 02:09:25 +08: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 19:43:54 +08:00
|
|
|
*
|
2016-06-06 03:32:25 +08:00
|
|
|
* If the device has writeback cache and supports FUA, REQ_PREFLUSH is
|
2011-01-25 19:43:54 +08:00
|
|
|
* translated to PREFLUSH but REQ_FUA is passed down directly with DATA.
|
|
|
|
*
|
2016-06-06 03:32:25 +08: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 19:43:54 +08:00
|
|
|
*
|
|
|
|
* The actual execution of flush is double buffered. Whenever a request
|
|
|
|
* needs to execute PRE or POSTFLUSH, it queues at
|
2014-09-25 23:23:43 +08:00
|
|
|
* fq->flush_queue[fq->flush_pending_idx]. Once certain criteria are met, a
|
2016-06-06 03:32:23 +08:00
|
|
|
* REQ_OP_FLUSH is issued and the pending_idx is toggled. When the flush
|
2011-01-25 19:43:54 +08:00
|
|
|
* completes, all the requests which were pending are proceeded to the next
|
2017-08-25 02:09:25 +08:00
|
|
|
* step. This allows arbitrary merging of different types of PREFLUSH/FUA
|
2011-01-25 19:43:54 +08: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-25 02:09:25 +08:00
|
|
|
* FUA (without PREFLUSH) requests.
|
2011-01-25 19:43:54 +08:00
|
|
|
*
|
|
|
|
* For devices which support FUA, it isn't clear whether C2 (and thus C3)
|
|
|
|
* is beneficial.
|
|
|
|
*
|
2017-08-25 02:09:25 +08:00
|
|
|
* Note that a sequenced PREFLUSH/FUA request with DATA is completed twice.
|
2011-01-25 19:43:54 +08: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 21:12:13 +08:00
|
|
|
* sequence is complete. This is implemented by testing RQF_FLUSH_SEQ in
|
2011-01-25 19:43:54 +08:00
|
|
|
* req_bio_endio().
|
|
|
|
*
|
2017-08-25 02:09:25 +08:00
|
|
|
* The above peculiarity requires that each PREFLUSH/FUA request has only one
|
2011-01-25 19:43:54 +08:00
|
|
|
* bio attached to it, which is guaranteed as they aren't allowed to be
|
|
|
|
* merged in the usual way.
|
2008-01-29 21:53:40 +08:00
|
|
|
*/
|
2011-01-25 19:43:54 +08:00
|
|
|
|
2008-01-29 21:53:40 +08: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 16:04:11 +08: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 16:20:05 +08:00
|
|
|
#include <linux/blk-mq.h>
|
2019-12-18 08:24:35 +08:00
|
|
|
#include <linux/lockdep.h>
|
2008-01-29 21:53:40 +08: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 16:20:05 +08:00
|
|
|
#include "blk-mq.h"
|
2015-08-09 15:41:51 +08:00
|
|
|
#include "blk-mq-tag.h"
|
2017-01-17 21:03:22 +08:00
|
|
|
#include "blk-mq-sched.h"
|
2008-01-29 21:53:40 +08:00
|
|
|
|
2017-08-25 02:09:25 +08:00
|
|
|
/* PREFLUSH/FUA sequences */
|
2010-09-03 17:56:17 +08:00
|
|
|
enum {
|
2011-01-25 19:43:54 +08: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 17:56:17 +08:00
|
|
|
};
|
|
|
|
|
2018-11-01 02:43:24 +08:00
|
|
|
static void blk_kick_flush(struct request_queue *q,
|
2018-06-06 22:21:40 +08:00
|
|
|
struct blk_flush_queue *fq, unsigned int flags);
|
2010-09-03 17:56:16 +08:00
|
|
|
|
2016-04-14 03:33:19 +08:00
|
|
|
static unsigned int blk_flush_policy(unsigned long fflags, struct request *rq)
|
2008-01-29 21:53:40 +08:00
|
|
|
{
|
2011-01-25 19:43:54 +08:00
|
|
|
unsigned int policy = 0;
|
2008-01-29 21:53:40 +08:00
|
|
|
|
2011-08-10 02:32:09 +08:00
|
|
|
if (blk_rq_sectors(rq))
|
|
|
|
policy |= REQ_FSEQ_DATA;
|
|
|
|
|
2016-04-14 03:33:19 +08:00
|
|
|
if (fflags & (1UL << QUEUE_FLAG_WC)) {
|
2016-06-06 03:32:25 +08:00
|
|
|
if (rq->cmd_flags & REQ_PREFLUSH)
|
2011-01-25 19:43:54 +08:00
|
|
|
policy |= REQ_FSEQ_PREFLUSH;
|
2016-04-14 03:33:19 +08:00
|
|
|
if (!(fflags & (1UL << QUEUE_FLAG_FUA)) &&
|
|
|
|
(rq->cmd_flags & REQ_FUA))
|
2011-01-25 19:43:54 +08:00
|
|
|
policy |= REQ_FSEQ_POSTFLUSH;
|
2010-09-03 17:56:16 +08:00
|
|
|
}
|
2011-01-25 19:43:54 +08:00
|
|
|
return policy;
|
2008-01-29 21:53:40 +08:00
|
|
|
}
|
|
|
|
|
2011-01-25 19:43:54 +08:00
|
|
|
static unsigned int blk_flush_cur_seq(struct request *rq)
|
2010-09-03 17:56:17 +08:00
|
|
|
{
|
2011-01-25 19:43:54 +08:00
|
|
|
return 1 << ffz(rq->flush.seq);
|
|
|
|
}
|
2010-09-03 17:56:17 +08:00
|
|
|
|
2011-01-25 19:43:54 +08:00
|
|
|
static void blk_flush_restore_request(struct request *rq)
|
|
|
|
{
|
2010-09-03 17:56:17 +08:00
|
|
|
/*
|
2011-01-25 19:43:54 +08: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 17:56:17 +08:00
|
|
|
*/
|
2011-01-25 19:43:54 +08:00
|
|
|
rq->bio = rq->biotail;
|
|
|
|
|
|
|
|
/* make @rq a normal request */
|
2016-10-20 21:12:13 +08: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-16 03:37:25 +08: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 16:20:05 +08:00
|
|
|
}
|
|
|
|
|
2018-11-01 02:43:24 +08:00
|
|
|
static void 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 16:20:05 +08:00
|
|
|
{
|
2018-10-14 05:44:12 +08:00
|
|
|
blk_mq_add_to_requeue_list(rq, add_front, true);
|
2010-09-03 17:56:17 +08:00
|
|
|
}
|
|
|
|
|
2019-11-21 18:40:26 +08:00
|
|
|
static void blk_account_io_flush(struct request *rq)
|
|
|
|
{
|
|
|
|
struct hd_struct *part = &rq->rq_disk->part0;
|
|
|
|
|
|
|
|
part_stat_lock();
|
|
|
|
part_stat_inc(part, ios[STAT_FLUSH]);
|
|
|
|
part_stat_add(part, nsecs[STAT_FLUSH],
|
|
|
|
ktime_get_ns() - rq->start_time_ns);
|
|
|
|
part_stat_unlock();
|
|
|
|
}
|
|
|
|
|
2011-01-25 19:43:54 +08:00
|
|
|
/**
|
|
|
|
* blk_flush_complete_seq - complete flush sequence
|
2017-08-25 02:09:25 +08:00
|
|
|
* @rq: PREFLUSH/FUA request being sequenced
|
2014-09-25 23:23:45 +08:00
|
|
|
* @fq: flush queue
|
2011-01-25 19:43:54 +08: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:
|
2018-11-15 00:02:10 +08:00
|
|
|
* spin_lock_irq(fq->mq_flush_lock)
|
2011-01-25 19:43:54 +08:00
|
|
|
*/
|
2018-11-01 02:43:24 +08:00
|
|
|
static void blk_flush_complete_seq(struct request *rq,
|
2014-09-25 23:23:45 +08:00
|
|
|
struct blk_flush_queue *fq,
|
2017-06-03 15:38:04 +08:00
|
|
|
unsigned int seq, blk_status_t error)
|
2008-01-29 21:53:40 +08:00
|
|
|
{
|
2011-01-25 19:43:54 +08:00
|
|
|
struct request_queue *q = rq->q;
|
2014-09-25 23:23:43 +08:00
|
|
|
struct list_head *pending = &fq->flush_queue[fq->flush_pending_idx];
|
2018-06-09 20:37:14 +08:00
|
|
|
unsigned int cmd_flags;
|
2011-01-25 19:43:54 +08:00
|
|
|
|
|
|
|
BUG_ON(rq->flush.seq & seq);
|
|
|
|
rq->flush.seq |= seq;
|
2018-06-09 20:37:14 +08:00
|
|
|
cmd_flags = rq->cmd_flags;
|
2011-01-25 19:43:54 +08: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 23:23:43 +08:00
|
|
|
fq->flush_pending_since = jiffies;
|
2011-01-25 19:43:54 +08:00
|
|
|
list_move_tail(&rq->flush.list, pending);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REQ_FSEQ_DATA:
|
2014-09-25 23:23:43 +08:00
|
|
|
list_move_tail(&rq->flush.list, &fq->flush_data_in_flight);
|
2018-11-01 02:43:24 +08:00
|
|
|
blk_flush_queue_rq(rq, true);
|
2011-01-25 19:43:54 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case REQ_FSEQ_DONE:
|
|
|
|
/*
|
2019-11-21 18:40:26 +08:00
|
|
|
* @rq was previously adjusted by blk_insert_flush() for
|
2011-01-25 19:43:54 +08:00
|
|
|
* 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-14 05:44:12 +08:00
|
|
|
blk_mq_end_request(rq, error);
|
2011-01-25 19:43:54 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
|
2018-11-01 02:43:24 +08:00
|
|
|
blk_kick_flush(q, fq, cmd_flags);
|
2008-01-29 21:53:40 +08:00
|
|
|
}
|
|
|
|
|
2017-06-03 15:38:04 +08:00
|
|
|
static void flush_end_io(struct request *flush_rq, blk_status_t error)
|
2008-01-29 21:53:40 +08:00
|
|
|
{
|
2011-01-25 19:43:54 +08: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 16:20:05 +08:00
|
|
|
struct list_head *running;
|
2011-01-25 19:43:54 +08:00
|
|
|
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 16:20:05 +08:00
|
|
|
unsigned long flags = 0;
|
2014-09-25 23:23:46 +08:00
|
|
|
struct blk_flush_queue *fq = blk_get_flush_queue(q, flush_rq->mq_ctx);
|
2018-10-14 05:44:12 +08:00
|
|
|
struct blk_mq_hw_ctx *hctx;
|
2011-01-25 19:43:54 +08:00
|
|
|
|
2019-11-21 18:40:26 +08:00
|
|
|
blk_account_io_flush(flush_rq);
|
|
|
|
|
2018-10-14 05:44:12 +08:00
|
|
|
/* release the tag's ownership to the req cloned from */
|
|
|
|
spin_lock_irqsave(&fq->mq_flush_lock, flags);
|
block: fix null pointer dereference in blk_mq_rq_timed_out()
We got a null pointer deference BUG_ON in blk_mq_rq_timed_out()
as following:
[ 108.825472] BUG: kernel NULL pointer dereference, address: 0000000000000040
[ 108.827059] PGD 0 P4D 0
[ 108.827313] Oops: 0000 [#1] SMP PTI
[ 108.827657] CPU: 6 PID: 198 Comm: kworker/6:1H Not tainted 5.3.0-rc8+ #431
[ 108.829503] Workqueue: kblockd blk_mq_timeout_work
[ 108.829913] RIP: 0010:blk_mq_check_expired+0x258/0x330
[ 108.838191] Call Trace:
[ 108.838406] bt_iter+0x74/0x80
[ 108.838665] blk_mq_queue_tag_busy_iter+0x204/0x450
[ 108.839074] ? __switch_to_asm+0x34/0x70
[ 108.839405] ? blk_mq_stop_hw_queue+0x40/0x40
[ 108.839823] ? blk_mq_stop_hw_queue+0x40/0x40
[ 108.840273] ? syscall_return_via_sysret+0xf/0x7f
[ 108.840732] blk_mq_timeout_work+0x74/0x200
[ 108.841151] process_one_work+0x297/0x680
[ 108.841550] worker_thread+0x29c/0x6f0
[ 108.841926] ? rescuer_thread+0x580/0x580
[ 108.842344] kthread+0x16a/0x1a0
[ 108.842666] ? kthread_flush_work+0x170/0x170
[ 108.843100] ret_from_fork+0x35/0x40
The bug is caused by the race between timeout handle and completion for
flush request.
When timeout handle function blk_mq_rq_timed_out() try to read
'req->q->mq_ops', the 'req' have completed and reinitiated by next
flush request, which would call blk_rq_init() to clear 'req' as 0.
After commit 12f5b93145 ("blk-mq: Remove generation seqeunce"),
normal requests lifetime are protected by refcount. Until 'rq->ref'
drop to zero, the request can really be free. Thus, these requests
cannot been reused before timeout handle finish.
However, flush request has defined .end_io and rq->end_io() is still
called even if 'rq->ref' doesn't drop to zero. After that, the 'flush_rq'
can be reused by the next flush request handle, resulting in null
pointer deference BUG ON.
We fix this problem by covering flush request with 'rq->ref'.
If the refcount is not zero, flush_end_io() return and wait the
last holder recall it. To record the request status, we add a new
entry 'rq_status', which will be used in flush_end_io().
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Keith Busch <keith.busch@intel.com>
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: stable@vger.kernel.org # v4.18+
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Bob Liu <bob.liu@oracle.com>
Signed-off-by: Yufen Yu <yuyufen@huawei.com>
-------
v2:
- move rq_status from struct request to struct blk_flush_queue
v3:
- remove unnecessary '{}' pair.
v4:
- let spinlock to protect 'fq->rq_status'
v5:
- move rq_status after flush_running_idx member of struct blk_flush_queue
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2019-09-27 16:19:55 +08:00
|
|
|
|
|
|
|
if (!refcount_dec_and_test(&flush_rq->ref)) {
|
|
|
|
fq->rq_status = error;
|
|
|
|
spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fq->rq_status != BLK_STS_OK)
|
|
|
|
error = fq->rq_status;
|
|
|
|
|
2018-10-30 05:06:13 +08:00
|
|
|
hctx = flush_rq->mq_hctx;
|
2020-06-30 22:03:57 +08:00
|
|
|
if (!q->elevator)
|
|
|
|
flush_rq->tag = BLK_MQ_NO_TAG;
|
|
|
|
else
|
|
|
|
flush_rq->internal_tag = BLK_MQ_NO_TAG;
|
2014-02-11 00:29:00 +08:00
|
|
|
|
2014-09-25 23:23:43 +08:00
|
|
|
running = &fq->flush_queue[fq->flush_running_idx];
|
|
|
|
BUG_ON(fq->flush_pending_idx == fq->flush_running_idx);
|
2011-01-25 19:43:54 +08:00
|
|
|
|
|
|
|
/* account completion of the flush request */
|
2014-09-25 23:23:43 +08: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 16:20:05 +08:00
|
|
|
|
2011-01-25 19:43:54 +08: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);
|
2018-11-01 02:43:24 +08:00
|
|
|
blk_flush_complete_seq(rq, fq, seq, error);
|
2011-01-25 19:43:54 +08:00
|
|
|
}
|
|
|
|
|
2018-10-14 05:44:12 +08: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 16:20:05 +08:00
|
|
|
}
|
|
|
|
|
2011-01-25 19:43:54 +08:00
|
|
|
/**
|
|
|
|
* blk_kick_flush - consider issuing flush request
|
|
|
|
* @q: request_queue being kicked
|
2014-09-25 23:23:45 +08:00
|
|
|
* @fq: flush queue
|
2018-06-06 22:21:40 +08:00
|
|
|
* @flags: cmd_flags of the original request
|
2011-01-25 19:43:54 +08: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:
|
2018-11-15 00:02:10 +08:00
|
|
|
* spin_lock_irq(fq->mq_flush_lock)
|
2011-01-25 19:43:54 +08:00
|
|
|
*
|
|
|
|
*/
|
2018-11-01 02:43:24 +08:00
|
|
|
static void blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq,
|
2018-06-06 22:21:40 +08:00
|
|
|
unsigned int flags)
|
2008-01-29 21:53:40 +08:00
|
|
|
{
|
2014-09-25 23:23:43 +08:00
|
|
|
struct list_head *pending = &fq->flush_queue[fq->flush_pending_idx];
|
2011-01-25 19:43:54 +08:00
|
|
|
struct request *first_rq =
|
|
|
|
list_first_entry(pending, struct request, flush.list);
|
2014-09-25 23:23:43 +08:00
|
|
|
struct request *flush_rq = fq->flush_rq;
|
2011-01-25 19:43:54 +08:00
|
|
|
|
|
|
|
/* C1 described at the top of this file */
|
2014-09-25 23:23:43 +08:00
|
|
|
if (fq->flush_pending_idx != fq->flush_running_idx || list_empty(pending))
|
2018-11-01 02:43:24 +08:00
|
|
|
return;
|
2011-01-25 19:43:54 +08:00
|
|
|
|
2017-02-18 02:40:44 +08: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.
|
|
|
|
*/
|
2018-11-16 03:22:51 +08:00
|
|
|
if (!list_empty(&fq->flush_data_in_flight) && q->elevator &&
|
2011-01-25 19:43:54 +08:00
|
|
|
time_before(jiffies,
|
2014-09-25 23:23:43 +08:00
|
|
|
fq->flush_pending_since + FLUSH_PENDING_TIMEOUT))
|
2018-11-01 02:43:24 +08:00
|
|
|
return;
|
2011-01-25 19:43:54 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Issue flush and toggle pending_idx. This makes pending_idx
|
|
|
|
* different from running_idx, which means flush is in flight.
|
|
|
|
*/
|
2014-09-25 23:23:43 +08:00
|
|
|
fq->flush_pending_idx ^= 1;
|
2014-02-11 00:29:00 +08:00
|
|
|
|
2014-09-25 23:23:42 +08:00
|
|
|
blk_rq_init(q, flush_rq);
|
2014-09-25 23:23:47 +08:00
|
|
|
|
|
|
|
/*
|
2017-11-02 23:24:38 +08: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 23:23:47 +08:00
|
|
|
*/
|
2018-10-14 05:44:12 +08:00
|
|
|
flush_rq->mq_ctx = first_rq->mq_ctx;
|
2018-10-30 05:06:13 +08:00
|
|
|
flush_rq->mq_hctx = first_rq->mq_hctx;
|
2018-10-14 05:44:12 +08:00
|
|
|
|
2020-06-30 22:03:57 +08:00
|
|
|
if (!q->elevator)
|
2018-10-14 05:44:12 +08:00
|
|
|
flush_rq->tag = first_rq->tag;
|
2020-06-30 22:03:57 +08:00
|
|
|
else
|
2018-10-14 05:44:12 +08:00
|
|
|
flush_rq->internal_tag = first_rq->internal_tag;
|
blk-mq: new multi-queue block IO queueing mechanism
Linux currently has two models for block devices:
- The classic request_fn based approach, where drivers use struct
request units for IO. The block layer provides various helper
functionalities to let drivers share code, things like tag
management, timeout handling, queueing, etc.
- The "stacked" approach, where a driver squeezes in between the
block layer and IO submitter. Since this bypasses the IO stack,
driver generally have to manage everything themselves.
With drivers being written for new high IOPS devices, the classic
request_fn based driver doesn't work well enough. The design dates
back to when both SMP and high IOPS was rare. It has problems with
scaling to bigger machines, and runs into scaling issues even on
smaller machines when you have IOPS in the hundreds of thousands
per device.
The stacked approach is then most often selected as the model
for the driver. But this means that everybody has to re-invent
everything, and along with that we get all the problems again
that the shared approach solved.
This commit introduces blk-mq, block multi queue support. The
design is centered around per-cpu queues for queueing IO, which
then funnel down into x number of hardware submission queues.
We might have a 1:1 mapping between the two, or it might be
an N:M mapping. That all depends on what the hardware supports.
blk-mq provides various helper functions, which include:
- Scalable support for request tagging. Most devices need to
be able to uniquely identify a request both in the driver and
to the hardware. The tagging uses per-cpu caches for freed
tags, to enable cache hot reuse.
- Timeout handling without tracking request on a per-device
basis. Basically the driver should be able to get a notification,
if a request happens to fail.
- Optional support for non 1:1 mappings between issue and
submission queues. blk-mq can redirect IO completions to the
desired location.
- Support for per-request payloads. Drivers almost always need
to associate a request structure with some driver private
command structure. Drivers can tell blk-mq this at init time,
and then any request handed to the driver will have the
required size of memory associated with it.
- Support for merging of IO, and plugging. The stacked model
gets neither of these. Even for high IOPS devices, merging
sequential IO reduces per-command overhead and thus
increases bandwidth.
For now, this is provided as a potential 3rd queueing model, with
the hope being that, as it matures, it can replace both the classic
and stacked model. That would get us back to having just 1 real
model for block devices, leaving the stacked approach to dm/md
devices (as it was originally intended).
Contributions in this patch from the following people:
Shaohua Li <shli@fusionio.com>
Alexander Gordeev <agordeev@redhat.com>
Christoph Hellwig <hch@infradead.org>
Mike Christie <michaelc@cs.wisc.edu>
Matias Bjorling <m@bjorling.me>
Jeff Moyer <jmoyer@redhat.com>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
|
2016-11-01 21:40:10 +08:00
|
|
|
flush_rq->cmd_flags = REQ_OP_FLUSH | REQ_PREFLUSH;
|
2018-06-06 22:21:40 +08:00
|
|
|
flush_rq->cmd_flags |= (flags & REQ_DRV) | (flags & REQ_FAILFAST_MASK);
|
2016-10-20 21:12:13 +08:00
|
|
|
flush_rq->rq_flags |= RQF_FLUSH_SEQ;
|
2014-09-25 23:23:42 +08:00
|
|
|
flush_rq->rq_disk = first_rq->rq_disk;
|
|
|
|
flush_rq->end_io = flush_end_io;
|
2011-01-25 19:43:54 +08:00
|
|
|
|
2018-11-01 02:43:24 +08:00
|
|
|
blk_flush_queue_rq(flush_rq, false);
|
2008-01-29 21:53:40 +08:00
|
|
|
}
|
|
|
|
|
2017-06-03 15:38:04 +08: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 16:20:05 +08:00
|
|
|
{
|
|
|
|
struct request_queue *q = rq->q;
|
2018-10-30 05:06:13 +08:00
|
|
|
struct blk_mq_hw_ctx *hctx = rq->mq_hctx;
|
2014-09-25 23:23:46 +08: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 16:20:05 +08:00
|
|
|
unsigned long flags;
|
2014-09-25 23:23:46 +08: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 16:20:05 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* After populating an empty queue, kick it to avoid stall. Read
|
|
|
|
* the comment in flush_end_io().
|
|
|
|
*/
|
2014-09-25 23:23:43 +08:00
|
|
|
spin_lock_irqsave(&fq->mq_flush_lock, flags);
|
2017-01-17 21:03:22 +08:00
|
|
|
blk_flush_complete_seq(rq, fq, REQ_FSEQ_DATA, error);
|
2014-09-25 23:23:43 +08:00
|
|
|
spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
|
2017-01-17 21:03:22 +08:00
|
|
|
|
2019-01-30 17:01:56 +08:00
|
|
|
blk_mq_sched_restart(hctx);
|
blk-mq: new multi-queue block IO queueing mechanism
Linux currently has two models for block devices:
- The classic request_fn based approach, where drivers use struct
request units for IO. The block layer provides various helper
functionalities to let drivers share code, things like tag
management, timeout handling, queueing, etc.
- The "stacked" approach, where a driver squeezes in between the
block layer and IO submitter. Since this bypasses the IO stack,
driver generally have to manage everything themselves.
With drivers being written for new high IOPS devices, the classic
request_fn based driver doesn't work well enough. The design dates
back to when both SMP and high IOPS was rare. It has problems with
scaling to bigger machines, and runs into scaling issues even on
smaller machines when you have IOPS in the hundreds of thousands
per device.
The stacked approach is then most often selected as the model
for the driver. But this means that everybody has to re-invent
everything, and along with that we get all the problems again
that the shared approach solved.
This commit introduces blk-mq, block multi queue support. The
design is centered around per-cpu queues for queueing IO, which
then funnel down into x number of hardware submission queues.
We might have a 1:1 mapping between the two, or it might be
an N:M mapping. That all depends on what the hardware supports.
blk-mq provides various helper functions, which include:
- Scalable support for request tagging. Most devices need to
be able to uniquely identify a request both in the driver and
to the hardware. The tagging uses per-cpu caches for freed
tags, to enable cache hot reuse.
- Timeout handling without tracking request on a per-device
basis. Basically the driver should be able to get a notification,
if a request happens to fail.
- Optional support for non 1:1 mappings between issue and
submission queues. blk-mq can redirect IO completions to the
desired location.
- Support for per-request payloads. Drivers almost always need
to associate a request structure with some driver private
command structure. Drivers can tell blk-mq this at init time,
and then any request handed to the driver will have the
required size of memory associated with it.
- Support for merging of IO, and plugging. The stacked model
gets neither of these. Even for high IOPS devices, merging
sequential IO reduces per-command overhead and thus
increases bandwidth.
For now, this is provided as a potential 3rd queueing model, with
the hope being that, as it matures, it can replace both the classic
and stacked model. That would get us back to having just 1 real
model for block devices, leaving the stacked approach to dm/md
devices (as it was originally intended).
Contributions in this patch from the following people:
Shaohua Li <shli@fusionio.com>
Alexander Gordeev <agordeev@redhat.com>
Christoph Hellwig <hch@infradead.org>
Mike Christie <michaelc@cs.wisc.edu>
Matias Bjorling <m@bjorling.me>
Jeff Moyer <jmoyer@redhat.com>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 16:20:05 +08:00
|
|
|
}
|
|
|
|
|
2011-01-25 19:43:54 +08:00
|
|
|
/**
|
2017-08-25 02:09:25 +08:00
|
|
|
* blk_insert_flush - insert a new PREFLUSH/FUA request
|
2011-01-25 19:43:54 +08:00
|
|
|
* @rq: request to insert
|
|
|
|
*
|
2011-03-30 15:52:30 +08: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 16:20:05 +08:00
|
|
|
* or __blk_mq_run_hw_queue() to dispatch request.
|
2011-01-25 19:43:54 +08: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 21:53:40 +08:00
|
|
|
{
|
2011-01-25 19:43:54 +08:00
|
|
|
struct request_queue *q = rq->q;
|
2016-04-14 03:33:19 +08:00
|
|
|
unsigned long fflags = q->queue_flags; /* may change, cache */
|
2011-01-25 19:43:54 +08:00
|
|
|
unsigned int policy = blk_flush_policy(fflags, rq);
|
2014-09-25 23:23:46 +08:00
|
|
|
struct blk_flush_queue *fq = blk_get_flush_queue(q, rq->mq_ctx);
|
2008-01-29 21:53:40 +08:00
|
|
|
|
2011-01-25 19:43:54 +08:00
|
|
|
/*
|
|
|
|
* @policy now records what operations need to be done. Adjust
|
2016-06-06 03:32:25 +08:00
|
|
|
* REQ_PREFLUSH and FUA for the driver.
|
2011-01-25 19:43:54 +08:00
|
|
|
*/
|
2016-06-06 03:32:25 +08:00
|
|
|
rq->cmd_flags &= ~REQ_PREFLUSH;
|
2016-04-14 03:33:19 +08:00
|
|
|
if (!(fflags & (1UL << QUEUE_FLAG_FUA)))
|
2011-01-25 19:43:54 +08:00
|
|
|
rq->cmd_flags &= ~REQ_FUA;
|
|
|
|
|
2016-11-09 10:39:28 +08: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-16 03:37:25 +08: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-14 05:44:12 +08: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-16 03:37:25 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:57:22 +08: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-16 03:37:25 +08:00
|
|
|
|
2011-01-25 19:43:54 +08: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))) {
|
2020-02-25 09:04:32 +08:00
|
|
|
blk_mq_request_bypass_insert(rq, false, false);
|
2011-01-25 19:43:54 +08:00
|
|
|
return;
|
2010-09-03 17:56:16 +08:00
|
|
|
}
|
2010-09-03 17:56:17 +08:00
|
|
|
|
2011-01-25 19:43:54 +08: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 21:12:13 +08: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-16 03:37:25 +08: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 16:20:05 +08:00
|
|
|
|
2018-10-14 05:44:12 +08:00
|
|
|
rq->end_io = mq_flush_data_end_io;
|
2011-01-25 19:43:54 +08:00
|
|
|
|
2018-10-14 05:44:12 +08:00
|
|
|
spin_lock_irq(&fq->mq_flush_lock);
|
2014-09-25 23:23:45 +08:00
|
|
|
blk_flush_complete_seq(rq, fq, REQ_FSEQ_ACTIONS & ~policy, 0);
|
2018-10-14 05:44:12 +08:00
|
|
|
spin_unlock_irq(&fq->mq_flush_lock);
|
2008-01-29 21:53:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* blkdev_issue_flush - queue a flush
|
|
|
|
* @bdev: blockdev to issue flush for
|
2010-04-28 21:55:06 +08:00
|
|
|
* @gfp_mask: memory allocation flags (for bio_alloc)
|
2008-01-29 21:53:40 +08:00
|
|
|
*
|
|
|
|
* Description:
|
2020-05-13 20:36:00 +08:00
|
|
|
* Issue a flush for the block device in question.
|
2008-01-29 21:53:40 +08:00
|
|
|
*/
|
2020-05-13 20:36:00 +08:00
|
|
|
int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask)
|
2008-01-29 21:53:40 +08:00
|
|
|
{
|
|
|
|
struct bio *bio;
|
2010-04-28 21:55:06 +08:00
|
|
|
int ret = 0;
|
2008-01-29 21:53:40 +08:00
|
|
|
|
2010-04-28 21:55:06 +08:00
|
|
|
bio = bio_alloc(gfp_mask, 0);
|
2017-08-24 01:10:32 +08:00
|
|
|
bio_set_dev(bio, bdev);
|
2016-11-01 21:40:10 +08:00
|
|
|
bio->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH;
|
2008-01-29 21:53:40 +08:00
|
|
|
|
2016-06-06 03:31:41 +08:00
|
|
|
ret = submit_bio_wait(bio);
|
2008-01-29 21:53:40 +08: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 16:20:05 +08:00
|
|
|
|
2020-03-10 05:41:37 +08:00
|
|
|
struct blk_flush_queue *blk_alloc_flush_queue(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 16:20:05 +08:00
|
|
|
{
|
2014-09-25 23:23:43 +08:00
|
|
|
struct blk_flush_queue *fq;
|
|
|
|
int rq_sz = sizeof(struct request);
|
2014-09-25 23:23:39 +08:00
|
|
|
|
2018-10-12 18:07:26 +08:00
|
|
|
fq = kzalloc_node(sizeof(*fq), flags, node);
|
2014-09-25 23:23:43 +08:00
|
|
|
if (!fq)
|
|
|
|
goto fail;
|
2014-09-25 23:23:39 +08:00
|
|
|
|
2018-10-14 05:44:12 +08:00
|
|
|
spin_lock_init(&fq->mq_flush_lock);
|
2014-09-25 23:23:43 +08:00
|
|
|
|
2017-01-28 00:51:45 +08:00
|
|
|
rq_sz = round_up(rq_sz + cmd_size, cache_line_size());
|
2018-10-12 18:07:26 +08:00
|
|
|
fq->flush_rq = kzalloc_node(rq_sz, flags, node);
|
2014-09-25 23:23:43 +08: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);
|
|
|
|
|
2019-12-18 08:24:35 +08:00
|
|
|
lockdep_register_key(&fq->key);
|
|
|
|
lockdep_set_class(&fq->mq_flush_lock, &fq->key);
|
|
|
|
|
2014-09-25 23:23:43 +08:00
|
|
|
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 16:20:05 +08:00
|
|
|
}
|
2014-09-25 23:23:40 +08:00
|
|
|
|
2014-09-25 23:23:44 +08:00
|
|
|
void blk_free_flush_queue(struct blk_flush_queue *fq)
|
2014-09-25 23:23:40 +08:00
|
|
|
{
|
2014-09-25 23:23:43 +08:00
|
|
|
/* bio based request queue hasn't flush queue */
|
|
|
|
if (!fq)
|
|
|
|
return;
|
2014-09-25 23:23:41 +08:00
|
|
|
|
2019-12-18 08:24:35 +08:00
|
|
|
lockdep_unregister_key(&fq->key);
|
2014-09-25 23:23:43 +08:00
|
|
|
kfree(fq->flush_rq);
|
|
|
|
kfree(fq);
|
|
|
|
}
|