License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
blk-mq: new multi-queue block IO queueing mechanism
Linux currently has two models for block devices:
- The classic request_fn based approach, where drivers use struct
request units for IO. The block layer provides various helper
functionalities to let drivers share code, things like tag
management, timeout handling, queueing, etc.
- The "stacked" approach, where a driver squeezes in between the
block layer and IO submitter. Since this bypasses the IO stack,
driver generally have to manage everything themselves.
With drivers being written for new high IOPS devices, the classic
request_fn based driver doesn't work well enough. The design dates
back to when both SMP and high IOPS was rare. It has problems with
scaling to bigger machines, and runs into scaling issues even on
smaller machines when you have IOPS in the hundreds of thousands
per device.
The stacked approach is then most often selected as the model
for the driver. But this means that everybody has to re-invent
everything, and along with that we get all the problems again
that the shared approach solved.
This commit introduces blk-mq, block multi queue support. The
design is centered around per-cpu queues for queueing IO, which
then funnel down into x number of hardware submission queues.
We might have a 1:1 mapping between the two, or it might be
an N:M mapping. That all depends on what the hardware supports.
blk-mq provides various helper functions, which include:
- Scalable support for request tagging. Most devices need to
be able to uniquely identify a request both in the driver and
to the hardware. The tagging uses per-cpu caches for freed
tags, to enable cache hot reuse.
- Timeout handling without tracking request on a per-device
basis. Basically the driver should be able to get a notification,
if a request happens to fail.
- Optional support for non 1:1 mappings between issue and
submission queues. blk-mq can redirect IO completions to the
desired location.
- Support for per-request payloads. Drivers almost always need
to associate a request structure with some driver private
command structure. Drivers can tell blk-mq this at init time,
and then any request handed to the driver will have the
required size of memory associated with it.
- Support for merging of IO, and plugging. The stacked model
gets neither of these. Even for high IOPS devices, merging
sequential IO reduces per-command overhead and thus
increases bandwidth.
For now, this is provided as a potential 3rd queueing model, with
the hope being that, as it matures, it can replace both the classic
and stacked model. That would get us back to having just 1 real
model for block devices, leaving the stacked approach to dm/md
devices (as it was originally intended).
Contributions in this patch from the following people:
Shaohua Li <shli@fusionio.com>
Alexander Gordeev <agordeev@redhat.com>
Christoph Hellwig <hch@infradead.org>
Mike Christie <michaelc@cs.wisc.edu>
Matias Bjorling <m@bjorling.me>
Jeff Moyer <jmoyer@redhat.com>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 08:20:05 +00:00
|
|
|
#ifndef INT_BLK_MQ_H
|
|
|
|
#define INT_BLK_MQ_H
|
|
|
|
|
2023-04-13 06:40:40 +00:00
|
|
|
#include <linux/blk-mq.h>
|
2016-11-08 04:32:37 +00:00
|
|
|
#include "blk-stat.h"
|
|
|
|
|
2014-04-15 20:14:00 +00:00
|
|
|
struct blk_mq_tag_set;
|
|
|
|
|
2018-11-20 01:44:35 +00:00
|
|
|
struct blk_mq_ctxs {
|
|
|
|
struct kobject kobj;
|
|
|
|
struct blk_mq_ctx __percpu *queue_ctx;
|
|
|
|
};
|
|
|
|
|
2018-04-20 08:29:51 +00:00
|
|
|
/**
|
|
|
|
* struct blk_mq_ctx - State for a software queue facing the submitting CPUs
|
|
|
|
*/
|
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 08:20:05 +00:00
|
|
|
struct blk_mq_ctx {
|
|
|
|
struct {
|
|
|
|
spinlock_t lock;
|
2018-12-17 15:44:05 +00:00
|
|
|
struct list_head rq_lists[HCTX_MAX_TYPES];
|
|
|
|
} ____cacheline_aligned_in_smp;
|
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 08:20:05 +00:00
|
|
|
|
|
|
|
unsigned int cpu;
|
2018-10-29 19:13:29 +00:00
|
|
|
unsigned short index_hw[HCTX_MAX_TYPES];
|
2019-01-24 10:25:32 +00:00
|
|
|
struct blk_mq_hw_ctx *hctxs[HCTX_MAX_TYPES];
|
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 08:20:05 +00:00
|
|
|
|
|
|
|
struct request_queue *queue;
|
2018-11-20 01:44:35 +00:00
|
|
|
struct blk_mq_ctxs *ctxs;
|
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 08:20:05 +00:00
|
|
|
struct kobject kobj;
|
2014-05-09 15:36:49 +00:00
|
|
|
} ____cacheline_aligned_in_smp;
|
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 08:20:05 +00:00
|
|
|
|
2023-04-13 06:40:39 +00:00
|
|
|
enum {
|
|
|
|
BLK_MQ_NO_TAG = -1U,
|
|
|
|
BLK_MQ_TAG_MIN = 1,
|
|
|
|
BLK_MQ_TAG_MAX = BLK_MQ_NO_TAG - 1,
|
|
|
|
};
|
|
|
|
|
2024-07-19 11:29:02 +00:00
|
|
|
#define BLK_MQ_CPU_WORK_BATCH (8)
|
|
|
|
|
2023-04-13 06:40:54 +00:00
|
|
|
typedef unsigned int __bitwise blk_insert_t;
|
|
|
|
#define BLK_MQ_INSERT_AT_HEAD ((__force blk_insert_t)0x01)
|
|
|
|
|
2021-10-12 11:12:24 +00:00
|
|
|
void blk_mq_submit_bio(struct bio *bio);
|
2021-10-12 15:24:29 +00:00
|
|
|
int blk_mq_poll(struct request_queue *q, blk_qc_t cookie, struct io_comp_batch *iob,
|
|
|
|
unsigned int flags);
|
blk-mq: free hw queue's resource in hctx's release handler
Once blk_cleanup_queue() returns, tags shouldn't be used any more,
because blk_mq_free_tag_set() may be called. Commit 45a9c9d909b2
("blk-mq: Fix a use-after-free") fixes this issue exactly.
However, that commit introduces another issue. Before 45a9c9d909b2,
we are allowed to run queue during cleaning up queue if the queue's
kobj refcount is held. After that commit, queue can't be run during
queue cleaning up, otherwise oops can be triggered easily because
some fields of hctx are freed by blk_mq_free_queue() in blk_cleanup_queue().
We have invented ways for addressing this kind of issue before, such as:
8dc765d438f1 ("SCSI: fix queue cleanup race before queue initialization is done")
c2856ae2f315 ("blk-mq: quiesce queue before freeing queue")
But still can't cover all cases, recently James reports another such
kind of issue:
https://marc.info/?l=linux-scsi&m=155389088124782&w=2
This issue can be quite hard to address by previous way, given
scsi_run_queue() may run requeues for other LUNs.
Fixes the above issue by freeing hctx's resources in its release handler, and this
way is safe becasue tags isn't needed for freeing such hctx resource.
This approach follows typical design pattern wrt. kobject's release handler.
Cc: Dongli Zhang <dongli.zhang@oracle.com>
Cc: James Smart <james.smart@broadcom.com>
Cc: Bart Van Assche <bart.vanassche@wdc.com>
Cc: linux-scsi@vger.kernel.org,
Cc: Martin K . Petersen <martin.petersen@oracle.com>,
Cc: Christoph Hellwig <hch@lst.de>,
Cc: James E . J . Bottomley <jejb@linux.vnet.ibm.com>,
Reported-by: James Smart <james.smart@broadcom.com>
Fixes: 45a9c9d909b2 ("blk-mq: Fix a use-after-free")
Cc: stable@vger.kernel.org
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Tested-by: James Smart <james.smart@broadcom.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2019-04-30 01:52:25 +00:00
|
|
|
void blk_mq_exit_queue(struct request_queue *q);
|
2014-05-20 17:49:02 +00:00
|
|
|
int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr);
|
2014-12-22 21:04:42 +00:00
|
|
|
void blk_mq_wake_waiters(struct request_queue *q);
|
2020-06-30 10:25:00 +00:00
|
|
|
bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *,
|
|
|
|
unsigned int);
|
2016-12-14 21:34:47 +00:00
|
|
|
void blk_mq_flush_busy_ctxs(struct blk_mq_hw_ctx *hctx, struct list_head *list);
|
blk-mq-sched: improve dispatching from sw queue
SCSI devices use host-wide tagset, and the shared driver tag space is
often quite big. However, there is also a queue depth for each lun(
.cmd_per_lun), which is often small, for example, on both lpfc and
qla2xxx, .cmd_per_lun is just 3.
So lots of requests may stay in sw queue, and we always flush all
belonging to same hw queue and dispatch them all to driver.
Unfortunately it is easy to cause queue busy because of the small
.cmd_per_lun. Once these requests are flushed out, they have to stay in
hctx->dispatch, and no bio merge can happen on these requests, and
sequential IO performance is harmed.
This patch introduces blk_mq_dequeue_from_ctx for dequeuing a request
from a sw queue, so that we can dispatch them in scheduler's way. We can
then avoid dequeueing too many requests from sw queue, since we don't
flush ->dispatch completely.
This patch improves dispatching from sw queue by using the .get_budget
and .put_budget callbacks.
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-10-14 09:22:30 +00:00
|
|
|
struct request *blk_mq_dequeue_from_ctx(struct blk_mq_hw_ctx *hctx,
|
|
|
|
struct blk_mq_ctx *start);
|
2021-05-11 15:22:34 +00:00
|
|
|
void blk_mq_put_rq_ref(struct request *rq);
|
2016-12-14 21:34:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Internal helpers for allocating/freeing the request map
|
|
|
|
*/
|
2017-01-11 21:29:56 +00:00
|
|
|
void blk_mq_free_rqs(struct blk_mq_tag_set *set, struct blk_mq_tags *tags,
|
|
|
|
unsigned int hctx_idx);
|
2021-10-05 10:23:37 +00:00
|
|
|
void blk_mq_free_rq_map(struct blk_mq_tags *tags);
|
2021-10-05 10:23:35 +00:00
|
|
|
struct blk_mq_tags *blk_mq_alloc_map_and_rqs(struct blk_mq_tag_set *set,
|
|
|
|
unsigned int hctx_idx, unsigned int depth);
|
2021-10-05 10:23:36 +00:00
|
|
|
void blk_mq_free_map_and_rqs(struct blk_mq_tag_set *set,
|
|
|
|
struct blk_mq_tags *tags,
|
|
|
|
unsigned int hctx_idx);
|
2018-01-17 16:25:57 +00:00
|
|
|
|
blk-mq: new multi-queue block IO queueing mechanism
Linux currently has two models for block devices:
- The classic request_fn based approach, where drivers use struct
request units for IO. The block layer provides various helper
functionalities to let drivers share code, things like tag
management, timeout handling, queueing, etc.
- The "stacked" approach, where a driver squeezes in between the
block layer and IO submitter. Since this bypasses the IO stack,
driver generally have to manage everything themselves.
With drivers being written for new high IOPS devices, the classic
request_fn based driver doesn't work well enough. The design dates
back to when both SMP and high IOPS was rare. It has problems with
scaling to bigger machines, and runs into scaling issues even on
smaller machines when you have IOPS in the hundreds of thousands
per device.
The stacked approach is then most often selected as the model
for the driver. But this means that everybody has to re-invent
everything, and along with that we get all the problems again
that the shared approach solved.
This commit introduces blk-mq, block multi queue support. The
design is centered around per-cpu queues for queueing IO, which
then funnel down into x number of hardware submission queues.
We might have a 1:1 mapping between the two, or it might be
an N:M mapping. That all depends on what the hardware supports.
blk-mq provides various helper functions, which include:
- Scalable support for request tagging. Most devices need to
be able to uniquely identify a request both in the driver and
to the hardware. The tagging uses per-cpu caches for freed
tags, to enable cache hot reuse.
- Timeout handling without tracking request on a per-device
basis. Basically the driver should be able to get a notification,
if a request happens to fail.
- Optional support for non 1:1 mappings between issue and
submission queues. blk-mq can redirect IO completions to the
desired location.
- Support for per-request payloads. Drivers almost always need
to associate a request structure with some driver private
command structure. Drivers can tell blk-mq this at init time,
and then any request handed to the driver will have the
required size of memory associated with it.
- Support for merging of IO, and plugging. The stacked model
gets neither of these. Even for high IOPS devices, merging
sequential IO reduces per-command overhead and thus
increases bandwidth.
For now, this is provided as a potential 3rd queueing model, with
the hope being that, as it matures, it can replace both the classic
and stacked model. That would get us back to having just 1 real
model for block devices, leaving the stacked approach to dm/md
devices (as it was originally intended).
Contributions in this patch from the following people:
Shaohua Li <shli@fusionio.com>
Alexander Gordeev <agordeev@redhat.com>
Christoph Hellwig <hch@infradead.org>
Mike Christie <michaelc@cs.wisc.edu>
Matias Bjorling <m@bjorling.me>
Jeff Moyer <jmoyer@redhat.com>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-10-24 08:20:05 +00:00
|
|
|
/*
|
|
|
|
* CPU -> queue mappings
|
|
|
|
*/
|
2018-10-29 19:06:14 +00:00
|
|
|
extern int blk_mq_hw_queue_to_node(struct blk_mq_queue_map *qmap, unsigned int);
|
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 08:20:05 +00:00
|
|
|
|
2018-10-30 16:36:06 +00:00
|
|
|
/*
|
|
|
|
* blk_mq_map_queue_type() - map (hctx_type,cpu) to hardware queue
|
|
|
|
* @q: request queue
|
2018-12-02 16:46:16 +00:00
|
|
|
* @type: the hctx type index
|
2018-10-30 16:36:06 +00:00
|
|
|
* @cpu: CPU
|
|
|
|
*/
|
|
|
|
static inline struct blk_mq_hw_ctx *blk_mq_map_queue_type(struct request_queue *q,
|
2018-12-02 16:46:16 +00:00
|
|
|
enum hctx_type type,
|
2018-10-30 16:36:06 +00:00
|
|
|
unsigned int cpu)
|
2016-09-14 14:18:54 +00:00
|
|
|
{
|
2022-03-08 07:32:19 +00:00
|
|
|
return xa_load(&q->hctx_table, q->tag_set->map[type].mq_map[cpu]);
|
2016-09-14 14:18:54 +00:00
|
|
|
}
|
|
|
|
|
2022-07-14 18:06:32 +00:00
|
|
|
static inline enum hctx_type blk_mq_get_hctx_type(blk_opf_t opf)
|
2018-10-29 19:07:33 +00:00
|
|
|
{
|
2018-12-02 16:46:16 +00:00
|
|
|
enum hctx_type type = HCTX_TYPE_DEFAULT;
|
|
|
|
|
2019-01-24 10:25:33 +00:00
|
|
|
/*
|
2021-10-12 11:12:21 +00:00
|
|
|
* The caller ensure that if REQ_POLLED, poll must be enabled.
|
2019-01-24 10:25:33 +00:00
|
|
|
*/
|
2022-06-15 22:55:48 +00:00
|
|
|
if (opf & REQ_POLLED)
|
2018-12-02 16:46:16 +00:00
|
|
|
type = HCTX_TYPE_POLL;
|
2022-06-15 22:55:48 +00:00
|
|
|
else if ((opf & REQ_OP_MASK) == REQ_OP_READ)
|
2018-12-02 16:46:16 +00:00
|
|
|
type = HCTX_TYPE_READ;
|
2021-11-12 12:47:15 +00:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* blk_mq_map_queue() - map (cmd_flags,type) to hardware queue
|
|
|
|
* @q: request queue
|
2022-06-15 22:55:48 +00:00
|
|
|
* @opf: operation type (REQ_OP_*) and flags (e.g. REQ_POLLED).
|
2021-11-12 12:47:15 +00:00
|
|
|
* @ctx: software queue cpu ctx
|
|
|
|
*/
|
|
|
|
static inline struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *q,
|
2022-07-14 18:06:32 +00:00
|
|
|
blk_opf_t opf,
|
2021-11-12 12:47:15 +00:00
|
|
|
struct blk_mq_ctx *ctx)
|
|
|
|
{
|
2022-06-15 22:55:48 +00:00
|
|
|
return ctx->hctxs[blk_mq_get_hctx_type(opf)];
|
2018-10-29 19:07:33 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 14:25:36 +00:00
|
|
|
/*
|
|
|
|
* sysfs helpers
|
|
|
|
*/
|
2017-02-22 10:13:59 +00:00
|
|
|
extern void blk_mq_sysfs_init(struct request_queue *q);
|
2017-02-22 10:14:00 +00:00
|
|
|
extern void blk_mq_sysfs_deinit(struct request_queue *q);
|
2022-06-28 17:18:50 +00:00
|
|
|
int blk_mq_sysfs_register(struct gendisk *disk);
|
|
|
|
void blk_mq_sysfs_unregister(struct gendisk *disk);
|
2022-06-28 17:18:49 +00:00
|
|
|
int blk_mq_sysfs_register_hctxs(struct request_queue *q);
|
|
|
|
void blk_mq_sysfs_unregister_hctxs(struct request_queue *q);
|
2015-12-18 00:08:14 +00:00
|
|
|
extern void blk_mq_hctx_kobj_init(struct blk_mq_hw_ctx *hctx);
|
2021-10-06 12:34:11 +00:00
|
|
|
void blk_mq_free_plug_rqs(struct blk_plug *plug);
|
2021-10-20 14:41:17 +00:00
|
|
|
void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule);
|
2014-05-30 14:25:36 +00:00
|
|
|
|
blk-mq: cancel blk-mq dispatch work in both blk_cleanup_queue and disk_release()
For avoiding to slow down queue destroy, we don't call
blk_mq_quiesce_queue() in blk_cleanup_queue(), instead of delaying to
cancel dispatch work in blk_release_queue().
However, this way has caused kernel oops[1], reported by Changhui. The log
shows that scsi_device can be freed before running blk_release_queue(),
which is expected too since scsi_device is released after the scsi disk
is closed and the scsi_device is removed.
Fixes the issue by canceling blk-mq dispatch work in both blk_cleanup_queue()
and disk_release():
1) when disk_release() is run, the disk has been closed, and any sync
dispatch activities have been done, so canceling dispatch work is enough to
quiesce filesystem I/O dispatch activity.
2) in blk_cleanup_queue(), we only focus on passthrough request, and
passthrough request is always explicitly allocated & freed by
its caller, so once queue is frozen, all sync dispatch activity
for passthrough request has been done, then it is enough to just cancel
dispatch work for avoiding any dispatch activity.
[1] kernel panic log
[12622.769416] BUG: kernel NULL pointer dereference, address: 0000000000000300
[12622.777186] #PF: supervisor read access in kernel mode
[12622.782918] #PF: error_code(0x0000) - not-present page
[12622.788649] PGD 0 P4D 0
[12622.791474] Oops: 0000 [#1] PREEMPT SMP PTI
[12622.796138] CPU: 10 PID: 744 Comm: kworker/10:1H Kdump: loaded Not tainted 5.15.0+ #1
[12622.804877] Hardware name: Dell Inc. PowerEdge R730/0H21J3, BIOS 1.5.4 10/002/2015
[12622.813321] Workqueue: kblockd blk_mq_run_work_fn
[12622.818572] RIP: 0010:sbitmap_get+0x75/0x190
[12622.823336] Code: 85 80 00 00 00 41 8b 57 08 85 d2 0f 84 b1 00 00 00 45 31 e4 48 63 cd 48 8d 1c 49 48 c1 e3 06 49 03 5f 10 4c 8d 6b 40 83 f0 01 <48> 8b 33 44 89 f2 4c 89 ef 0f b6 c8 e8 fa f3 ff ff 83 f8 ff 75 58
[12622.844290] RSP: 0018:ffffb00a446dbd40 EFLAGS: 00010202
[12622.850120] RAX: 0000000000000001 RBX: 0000000000000300 RCX: 0000000000000004
[12622.858082] RDX: 0000000000000006 RSI: 0000000000000082 RDI: ffffa0b7a2dfe030
[12622.866042] RBP: 0000000000000004 R08: 0000000000000001 R09: ffffa0b742721334
[12622.874003] R10: 0000000000000008 R11: 0000000000000008 R12: 0000000000000000
[12622.881964] R13: 0000000000000340 R14: 0000000000000000 R15: ffffa0b7a2dfe030
[12622.889926] FS: 0000000000000000(0000) GS:ffffa0baafb40000(0000) knlGS:0000000000000000
[12622.898956] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[12622.905367] CR2: 0000000000000300 CR3: 0000000641210001 CR4: 00000000001706e0
[12622.913328] Call Trace:
[12622.916055] <TASK>
[12622.918394] scsi_mq_get_budget+0x1a/0x110
[12622.922969] __blk_mq_do_dispatch_sched+0x1d4/0x320
[12622.928404] ? pick_next_task_fair+0x39/0x390
[12622.933268] __blk_mq_sched_dispatch_requests+0xf4/0x140
[12622.939194] blk_mq_sched_dispatch_requests+0x30/0x60
[12622.944829] __blk_mq_run_hw_queue+0x30/0xa0
[12622.949593] process_one_work+0x1e8/0x3c0
[12622.954059] worker_thread+0x50/0x3b0
[12622.958144] ? rescuer_thread+0x370/0x370
[12622.962616] kthread+0x158/0x180
[12622.966218] ? set_kthread_struct+0x40/0x40
[12622.970884] ret_from_fork+0x22/0x30
[12622.974875] </TASK>
[12622.977309] Modules linked in: scsi_debug rpcsec_gss_krb5 auth_rpcgss nfsv4 dns_resolver nfs lockd grace fscache netfs sunrpc dm_multipath intel_rapl_msr intel_rapl_common dell_wmi_descriptor sb_edac rfkill video x86_pkg_temp_thermal intel_powerclamp dcdbas coretemp kvm_intel kvm mgag200 irqbypass i2c_algo_bit rapl drm_kms_helper ipmi_ssif intel_cstate intel_uncore syscopyarea sysfillrect sysimgblt fb_sys_fops pcspkr cec mei_me lpc_ich mei ipmi_si ipmi_devintf ipmi_msghandler acpi_power_meter drm fuse xfs libcrc32c sr_mod cdrom sd_mod t10_pi sg ixgbe ahci libahci crct10dif_pclmul crc32_pclmul crc32c_intel libata megaraid_sas ghash_clmulni_intel tg3 wdat_wdt mdio dca wmi dm_mirror dm_region_hash dm_log dm_mod [last unloaded: scsi_debug]
Reported-by: ChanghuiZhong <czhong@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: linux-scsi@vger.kernel.org
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20211116014343.610501-1-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-11-16 01:43:43 +00:00
|
|
|
void blk_mq_cancel_work_sync(struct request_queue *q);
|
|
|
|
|
2015-01-29 12:17:27 +00:00
|
|
|
void blk_mq_release(struct request_queue *q);
|
|
|
|
|
2014-05-31 16:43:36 +00:00
|
|
|
static inline struct blk_mq_ctx *__blk_mq_get_ctx(struct request_queue *q,
|
|
|
|
unsigned int cpu)
|
|
|
|
{
|
|
|
|
return per_cpu_ptr(q->queue_ctx, cpu);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This assumes per-cpu software queueing queues. They could be per-node
|
|
|
|
* as well, for instance. For now this is hardcoded as-is. Note that we don't
|
|
|
|
* care about preemption, since we know the ctx's are persistent. This does
|
|
|
|
* mean that we can't rely on ctx always matching the currently running CPU.
|
|
|
|
*/
|
|
|
|
static inline struct blk_mq_ctx *blk_mq_get_ctx(struct request_queue *q)
|
|
|
|
{
|
2019-07-01 15:47:29 +00:00
|
|
|
return __blk_mq_get_ctx(q, raw_smp_processor_id());
|
2014-05-31 16:43:36 +00:00
|
|
|
}
|
|
|
|
|
2014-05-31 16:43:37 +00:00
|
|
|
struct blk_mq_alloc_data {
|
|
|
|
/* input parameter */
|
|
|
|
struct request_queue *q;
|
2017-11-09 18:49:59 +00:00
|
|
|
blk_mq_req_flags_t flags;
|
2017-04-14 07:59:59 +00:00
|
|
|
unsigned int shallow_depth;
|
2022-07-14 18:06:32 +00:00
|
|
|
blk_opf_t cmd_flags;
|
2021-11-09 22:08:11 +00:00
|
|
|
req_flags_t rq_flags;
|
2014-05-31 16:43:37 +00:00
|
|
|
|
2021-10-06 12:34:11 +00:00
|
|
|
/* allocate multiple requests/tags in one go */
|
|
|
|
unsigned int nr_tags;
|
|
|
|
struct request **cached_rq;
|
|
|
|
|
2014-05-31 16:43:37 +00:00
|
|
|
/* input & output parameter */
|
|
|
|
struct blk_mq_ctx *ctx;
|
|
|
|
struct blk_mq_hw_ctx *hctx;
|
|
|
|
};
|
|
|
|
|
2023-04-13 06:40:39 +00:00
|
|
|
struct blk_mq_tags *blk_mq_init_tags(unsigned int nr_tags,
|
|
|
|
unsigned int reserved_tags, int node, int alloc_policy);
|
|
|
|
void blk_mq_free_tags(struct blk_mq_tags *tags);
|
|
|
|
int blk_mq_init_bitmaps(struct sbitmap_queue *bitmap_tags,
|
|
|
|
struct sbitmap_queue *breserved_tags, unsigned int queue_depth,
|
|
|
|
unsigned int reserved, int node, int alloc_policy);
|
|
|
|
|
|
|
|
unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data);
|
|
|
|
unsigned long blk_mq_get_tags(struct blk_mq_alloc_data *data, int nr_tags,
|
|
|
|
unsigned int *offset);
|
|
|
|
void blk_mq_put_tag(struct blk_mq_tags *tags, struct blk_mq_ctx *ctx,
|
|
|
|
unsigned int tag);
|
|
|
|
void blk_mq_put_tags(struct blk_mq_tags *tags, int *tag_array, int nr_tags);
|
|
|
|
int blk_mq_tag_update_depth(struct blk_mq_hw_ctx *hctx,
|
|
|
|
struct blk_mq_tags **tags, unsigned int depth, bool can_grow);
|
|
|
|
void blk_mq_tag_resize_shared_tags(struct blk_mq_tag_set *set,
|
|
|
|
unsigned int size);
|
|
|
|
void blk_mq_tag_update_sched_shared_tags(struct request_queue *q);
|
|
|
|
|
|
|
|
void blk_mq_tag_wakeup_all(struct blk_mq_tags *tags, bool);
|
|
|
|
void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_tag_iter_fn *fn,
|
|
|
|
void *priv);
|
|
|
|
void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
|
|
|
|
void *priv);
|
|
|
|
|
|
|
|
static inline struct sbq_wait_state *bt_wait_ptr(struct sbitmap_queue *bt,
|
|
|
|
struct blk_mq_hw_ctx *hctx)
|
|
|
|
{
|
|
|
|
if (!hctx)
|
|
|
|
return &bt->ws[0];
|
|
|
|
return sbq_wait_ptr(bt, &hctx->wait_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __blk_mq_tag_busy(struct blk_mq_hw_ctx *);
|
|
|
|
void __blk_mq_tag_idle(struct blk_mq_hw_ctx *);
|
|
|
|
|
|
|
|
static inline void blk_mq_tag_busy(struct blk_mq_hw_ctx *hctx)
|
|
|
|
{
|
|
|
|
if (hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED)
|
|
|
|
__blk_mq_tag_busy(hctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void blk_mq_tag_idle(struct blk_mq_hw_ctx *hctx)
|
|
|
|
{
|
|
|
|
if (hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED)
|
|
|
|
__blk_mq_tag_idle(hctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool blk_mq_tag_is_reserved(struct blk_mq_tags *tags,
|
|
|
|
unsigned int tag)
|
|
|
|
{
|
|
|
|
return tag < tags->nr_reserved_tags;
|
|
|
|
}
|
|
|
|
|
2021-10-05 10:23:39 +00:00
|
|
|
static inline bool blk_mq_is_shared_tags(unsigned int flags)
|
blk-mq: Facilitate a shared sbitmap per tagset
Some SCSI HBAs (such as HPSA, megaraid, mpt3sas, hisi_sas_v3 ..) support
multiple reply queues with single hostwide tags.
In addition, these drivers want to use interrupt assignment in
pci_alloc_irq_vectors(PCI_IRQ_AFFINITY). However, as discussed in [0],
CPU hotplug may cause in-flight IO completion to not be serviced when an
interrupt is shutdown. That problem is solved in commit bf0beec0607d
("blk-mq: drain I/O when all CPUs in a hctx are offline").
However, to take advantage of that blk-mq feature, the HBA HW queuess are
required to be mapped to that of the blk-mq hctx's; to do that, the HBA HW
queues need to be exposed to the upper layer.
In making that transition, the per-SCSI command request tags are no
longer unique per Scsi host - they are just unique per hctx. As such, the
HBA LLDD would have to generate this tag internally, which has a certain
performance overhead.
However another problem is that blk-mq assumes the host may accept
(Scsi_host.can_queue * #hw queue) commands. In commit 6eb045e092ef ("scsi:
core: avoid host-wide host_busy counter for scsi_mq"), the Scsi host busy
counter was removed, which would stop the LLDD being sent more than
.can_queue commands; however, it should still be ensured that the block
layer does not issue more than .can_queue commands to the Scsi host.
To solve this problem, introduce a shared sbitmap per blk_mq_tag_set,
which may be requested at init time.
New flag BLK_MQ_F_TAG_HCTX_SHARED should be set when requesting the
tagset to indicate whether the shared sbitmap should be used.
Even when BLK_MQ_F_TAG_HCTX_SHARED is set, a full set of tags and requests
are still allocated per hctx; the reason for this is that if tags and
requests were only allocated for a single hctx - like hctx0 - it may break
block drivers which expect a request be associated with a specific hctx,
i.e. not always hctx0. This will introduce extra memory usage.
This change is based on work originally from Ming Lei in [1] and from
Bart's suggestion in [2].
[0] https://lore.kernel.org/linux-block/alpine.DEB.2.21.1904051331270.1802@nanos.tec.linutronix.de/
[1] https://lore.kernel.org/linux-block/20190531022801.10003-1-ming.lei@redhat.com/
[2] https://lore.kernel.org/linux-block/ff77beff-5fd9-9f05-12b6-826922bace1f@huawei.com/T/#m3db0a602f095cbcbff27e9c884d6b4ae826144be
Signed-off-by: John Garry <john.garry@huawei.com>
Tested-by: Don Brace<don.brace@microsemi.com> #SCSI resv cmds patches used
Tested-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2020-08-19 15:20:24 +00:00
|
|
|
{
|
|
|
|
return flags & BLK_MQ_F_TAG_HCTX_SHARED;
|
|
|
|
}
|
|
|
|
|
2017-01-13 15:09:05 +00:00
|
|
|
static inline struct blk_mq_tags *blk_mq_tags_from_data(struct blk_mq_alloc_data *data)
|
|
|
|
{
|
2023-05-18 05:31:01 +00:00
|
|
|
if (data->rq_flags & RQF_SCHED_TAGS)
|
|
|
|
return data->hctx->sched_tags;
|
|
|
|
return data->hctx->tags;
|
2017-01-13 15:09:05 +00:00
|
|
|
}
|
|
|
|
|
2016-10-29 00:19:15 +00:00
|
|
|
static inline bool blk_mq_hctx_stopped(struct blk_mq_hw_ctx *hctx)
|
|
|
|
{
|
|
|
|
return test_bit(BLK_MQ_S_STOPPED, &hctx->state);
|
|
|
|
}
|
|
|
|
|
2014-12-03 11:38:04 +00:00
|
|
|
static inline bool blk_mq_hw_queue_mapped(struct blk_mq_hw_ctx *hctx)
|
|
|
|
{
|
|
|
|
return hctx->nr_ctx && hctx->tags;
|
|
|
|
}
|
|
|
|
|
2020-11-24 08:36:54 +00:00
|
|
|
unsigned int blk_mq_in_flight(struct request_queue *q,
|
|
|
|
struct block_device *part);
|
|
|
|
void blk_mq_in_flight_rw(struct request_queue *q, struct block_device *part,
|
|
|
|
unsigned int inflight[2]);
|
2017-08-08 23:51:45 +00:00
|
|
|
|
2021-01-22 02:33:12 +00:00
|
|
|
static inline void blk_mq_put_dispatch_budget(struct request_queue *q,
|
|
|
|
int budget_token)
|
2017-10-14 09:22:29 +00:00
|
|
|
{
|
|
|
|
if (q->mq_ops->put_budget)
|
2021-01-22 02:33:12 +00:00
|
|
|
q->mq_ops->put_budget(q, budget_token);
|
2017-10-14 09:22:29 +00:00
|
|
|
}
|
|
|
|
|
2021-01-22 02:33:12 +00:00
|
|
|
static inline int blk_mq_get_dispatch_budget(struct request_queue *q)
|
2017-10-14 09:22:29 +00:00
|
|
|
{
|
|
|
|
if (q->mq_ops->get_budget)
|
2020-06-30 10:24:56 +00:00
|
|
|
return q->mq_ops->get_budget(q);
|
2021-01-22 02:33:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void blk_mq_set_rq_budget_token(struct request *rq, int token)
|
|
|
|
{
|
|
|
|
if (token < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (rq->q->mq_ops->set_rq_budget_token)
|
|
|
|
rq->q->mq_ops->set_rq_budget_token(rq, token);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int blk_mq_get_rq_budget_token(struct request *rq)
|
|
|
|
{
|
|
|
|
if (rq->q->mq_ops->get_rq_budget_token)
|
|
|
|
return rq->q->mq_ops->get_rq_budget_token(rq);
|
|
|
|
return -1;
|
2017-10-14 09:22:29 +00:00
|
|
|
}
|
|
|
|
|
2023-09-13 15:16:12 +00:00
|
|
|
static inline void __blk_mq_add_active_requests(struct blk_mq_hw_ctx *hctx,
|
|
|
|
int val)
|
2020-08-19 15:20:26 +00:00
|
|
|
{
|
2021-10-05 10:23:39 +00:00
|
|
|
if (blk_mq_is_shared_tags(hctx->flags))
|
2023-09-13 15:16:12 +00:00
|
|
|
atomic_add(val, &hctx->queue->nr_active_requests_shared_tags);
|
2020-08-19 15:20:26 +00:00
|
|
|
else
|
2023-09-13 15:16:12 +00:00
|
|
|
atomic_add(val, &hctx->nr_active);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void __blk_mq_inc_active_requests(struct blk_mq_hw_ctx *hctx)
|
|
|
|
{
|
|
|
|
__blk_mq_add_active_requests(hctx, 1);
|
2020-08-19 15:20:26 +00:00
|
|
|
}
|
|
|
|
|
2021-11-02 15:36:19 +00:00
|
|
|
static inline void __blk_mq_sub_active_requests(struct blk_mq_hw_ctx *hctx,
|
|
|
|
int val)
|
2020-08-19 15:20:26 +00:00
|
|
|
{
|
2021-10-05 10:23:39 +00:00
|
|
|
if (blk_mq_is_shared_tags(hctx->flags))
|
2021-11-02 15:36:19 +00:00
|
|
|
atomic_sub(val, &hctx->queue->nr_active_requests_shared_tags);
|
2020-08-19 15:20:26 +00:00
|
|
|
else
|
2021-11-02 15:36:19 +00:00
|
|
|
atomic_sub(val, &hctx->nr_active);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void __blk_mq_dec_active_requests(struct blk_mq_hw_ctx *hctx)
|
|
|
|
{
|
|
|
|
__blk_mq_sub_active_requests(hctx, 1);
|
2020-08-19 15:20:26 +00:00
|
|
|
}
|
|
|
|
|
2023-09-13 15:16:12 +00:00
|
|
|
static inline void blk_mq_add_active_requests(struct blk_mq_hw_ctx *hctx,
|
|
|
|
int val)
|
|
|
|
{
|
|
|
|
if (hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED)
|
|
|
|
__blk_mq_add_active_requests(hctx, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void blk_mq_inc_active_requests(struct blk_mq_hw_ctx *hctx)
|
|
|
|
{
|
|
|
|
if (hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED)
|
|
|
|
__blk_mq_inc_active_requests(hctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void blk_mq_sub_active_requests(struct blk_mq_hw_ctx *hctx,
|
|
|
|
int val)
|
|
|
|
{
|
|
|
|
if (hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED)
|
|
|
|
__blk_mq_sub_active_requests(hctx, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void blk_mq_dec_active_requests(struct blk_mq_hw_ctx *hctx)
|
|
|
|
{
|
|
|
|
if (hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED)
|
|
|
|
__blk_mq_dec_active_requests(hctx);
|
|
|
|
}
|
|
|
|
|
2020-08-19 15:20:26 +00:00
|
|
|
static inline int __blk_mq_active_requests(struct blk_mq_hw_ctx *hctx)
|
|
|
|
{
|
2021-10-05 10:23:39 +00:00
|
|
|
if (blk_mq_is_shared_tags(hctx->flags))
|
|
|
|
return atomic_read(&hctx->queue->nr_active_requests_shared_tags);
|
2020-08-19 15:20:26 +00:00
|
|
|
return atomic_read(&hctx->nr_active);
|
|
|
|
}
|
2020-07-02 04:58:32 +00:00
|
|
|
static inline void __blk_mq_put_driver_tag(struct blk_mq_hw_ctx *hctx,
|
|
|
|
struct request *rq)
|
|
|
|
{
|
2023-09-13 15:16:12 +00:00
|
|
|
blk_mq_dec_active_requests(hctx);
|
2020-07-02 04:58:32 +00:00
|
|
|
blk_mq_put_tag(hctx->tags, rq->mq_ctx, rq->tag);
|
|
|
|
rq->tag = BLK_MQ_NO_TAG;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void blk_mq_put_driver_tag(struct request *rq)
|
|
|
|
{
|
|
|
|
if (rq->tag == BLK_MQ_NO_TAG || rq->internal_tag == BLK_MQ_NO_TAG)
|
|
|
|
return;
|
|
|
|
|
|
|
|
__blk_mq_put_driver_tag(rq->mq_hctx, rq);
|
|
|
|
}
|
|
|
|
|
2023-09-13 15:16:12 +00:00
|
|
|
bool __blk_mq_alloc_driver_tag(struct request *rq);
|
2021-10-13 14:28:14 +00:00
|
|
|
|
|
|
|
static inline bool blk_mq_get_driver_tag(struct request *rq)
|
|
|
|
{
|
2023-09-13 15:16:12 +00:00
|
|
|
if (rq->tag == BLK_MQ_NO_TAG && !__blk_mq_alloc_driver_tag(rq))
|
|
|
|
return false;
|
2021-10-13 14:28:14 +00:00
|
|
|
|
2023-09-13 15:16:12 +00:00
|
|
|
return true;
|
2021-10-13 14:28:14 +00:00
|
|
|
}
|
2021-06-03 10:47:21 +00:00
|
|
|
|
2018-10-29 19:06:14 +00:00
|
|
|
static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap)
|
2018-07-02 14:46:43 +00:00
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
for_each_possible_cpu(cpu)
|
2018-10-29 19:06:14 +00:00
|
|
|
qmap->mq_map[cpu] = 0;
|
2018-07-02 14:46:43 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 09:36:34 +00:00
|
|
|
/* Free all requests on the list */
|
|
|
|
static inline void blk_mq_free_requests(struct list_head *list)
|
|
|
|
{
|
|
|
|
while (!list_empty(list)) {
|
|
|
|
struct request *rq = list_entry_rq(list->next);
|
|
|
|
|
|
|
|
list_del_init(&rq->queuelist);
|
|
|
|
blk_mq_free_request(rq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-19 15:20:25 +00:00
|
|
|
/*
|
|
|
|
* For shared tag users, we track the number of currently active users
|
|
|
|
* and attempt to provide a fair share of the tag depth for each of them.
|
|
|
|
*/
|
|
|
|
static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx,
|
|
|
|
struct sbitmap_queue *bt)
|
|
|
|
{
|
|
|
|
unsigned int depth, users;
|
|
|
|
|
|
|
|
if (!hctx || !(hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't try dividing an ant
|
|
|
|
*/
|
|
|
|
if (bt->sb.depth == 1)
|
|
|
|
return true;
|
|
|
|
|
2021-10-05 10:23:39 +00:00
|
|
|
if (blk_mq_is_shared_tags(hctx->flags)) {
|
2020-08-19 15:20:27 +00:00
|
|
|
struct request_queue *q = hctx->queue;
|
|
|
|
|
2020-12-27 11:34:58 +00:00
|
|
|
if (!test_bit(QUEUE_FLAG_HCTX_ACTIVE, &q->queue_flags))
|
2020-08-19 15:20:27 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if (!test_bit(BLK_MQ_S_TAG_ACTIVE, &hctx->state))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-06-10 02:30:43 +00:00
|
|
|
users = READ_ONCE(hctx->tags->active_queues);
|
2020-08-19 15:20:25 +00:00
|
|
|
if (!users)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allow at least some tags
|
|
|
|
*/
|
|
|
|
depth = max((bt->sb.depth + users - 1) / users, 4U);
|
2020-08-19 15:20:26 +00:00
|
|
|
return __blk_mq_active_requests(hctx) < depth;
|
2020-08-19 15:20:25 +00:00
|
|
|
}
|
|
|
|
|
2021-12-03 13:15:31 +00:00
|
|
|
/* run the code block in @dispatch_ops with rcu/srcu read lock held */
|
2021-12-06 11:12:13 +00:00
|
|
|
#define __blk_mq_run_dispatch_ops(q, check_sleep, dispatch_ops) \
|
2021-12-03 13:15:31 +00:00
|
|
|
do { \
|
2022-11-01 15:00:47 +00:00
|
|
|
if ((q)->tag_set->flags & BLK_MQ_F_BLOCKING) { \
|
2023-03-10 01:09:13 +00:00
|
|
|
struct blk_mq_tag_set *__tag_set = (q)->tag_set; \
|
2021-12-03 13:15:31 +00:00
|
|
|
int srcu_idx; \
|
|
|
|
\
|
2021-12-06 11:12:13 +00:00
|
|
|
might_sleep_if(check_sleep); \
|
2023-03-10 01:09:13 +00:00
|
|
|
srcu_idx = srcu_read_lock(__tag_set->srcu); \
|
2021-12-03 13:15:31 +00:00
|
|
|
(dispatch_ops); \
|
2023-03-10 01:09:13 +00:00
|
|
|
srcu_read_unlock(__tag_set->srcu, srcu_idx); \
|
2022-11-01 15:00:47 +00:00
|
|
|
} else { \
|
|
|
|
rcu_read_lock(); \
|
|
|
|
(dispatch_ops); \
|
|
|
|
rcu_read_unlock(); \
|
2021-12-03 13:15:31 +00:00
|
|
|
} \
|
|
|
|
} while (0)
|
2020-08-19 15:20:25 +00:00
|
|
|
|
2021-12-06 11:12:13 +00:00
|
|
|
#define blk_mq_run_dispatch_ops(q, dispatch_ops) \
|
|
|
|
__blk_mq_run_dispatch_ops(q, true, dispatch_ops) \
|
|
|
|
|
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 08:20:05 +00:00
|
|
|
#endif
|