2019-02-18 18:36:11 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-06-22 00:04:20 +08:00
|
|
|
/*
|
|
|
|
* NVMe I/O command implementation.
|
|
|
|
* Copyright (c) 2015-2016 HGST, a Western Digital Company.
|
|
|
|
*/
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
#include <linux/blkdev.h>
|
2021-09-20 20:33:27 +08:00
|
|
|
#include <linux/blk-integrity.h>
|
2022-02-16 12:31:36 +08:00
|
|
|
#include <linux/memremap.h>
|
2016-06-22 00:04:20 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include "nvmet.h"
|
|
|
|
|
2019-06-29 00:53:30 +08:00
|
|
|
void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id)
|
|
|
|
{
|
2019-09-18 02:52:00 +08:00
|
|
|
/* Logical blocks per physical block, 0's based. */
|
2022-09-27 16:26:26 +08:00
|
|
|
const __le16 lpp0b = to0based(bdev_physical_block_size(bdev) /
|
|
|
|
bdev_logical_block_size(bdev));
|
2019-06-29 00:53:30 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For NVMe 1.2 and later, bit 1 indicates that the fields NAWUN,
|
|
|
|
* NAWUPF, and NACWU are defined for this namespace and should be
|
|
|
|
* used by the host for this namespace instead of the AWUN, AWUPF,
|
|
|
|
* and ACWU fields in the Identify Controller data structure. If
|
|
|
|
* any of these fields are zero that means that the corresponding
|
|
|
|
* field from the identify controller data structure should be used.
|
|
|
|
*/
|
|
|
|
id->nsfeat |= 1 << 1;
|
2019-09-18 02:52:00 +08:00
|
|
|
id->nawun = lpp0b;
|
|
|
|
id->nawupf = lpp0b;
|
|
|
|
id->nacwu = lpp0b;
|
2019-06-29 00:53:30 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Bit 4 indicates that the fields NPWG, NPWA, NPDG, NPDA, and
|
|
|
|
* NOWS are defined for this namespace and should be used by
|
|
|
|
* the host for I/O optimization.
|
|
|
|
*/
|
|
|
|
id->nsfeat |= 1 << 4;
|
|
|
|
/* NPWG = Namespace Preferred Write Granularity. 0's based */
|
2019-09-18 02:52:00 +08:00
|
|
|
id->npwg = lpp0b;
|
2019-06-29 00:53:30 +08:00
|
|
|
/* NPWA = Namespace Preferred Write Alignment. 0's based */
|
|
|
|
id->npwa = id->npwg;
|
|
|
|
/* NPDG = Namespace Preferred Deallocate Granularity. 0's based */
|
2022-09-27 16:26:26 +08:00
|
|
|
id->npdg = to0based(bdev_discard_granularity(bdev) /
|
|
|
|
bdev_logical_block_size(bdev));
|
2019-06-29 00:53:30 +08:00
|
|
|
/* NPDG = Namespace Preferred Deallocate Alignment */
|
|
|
|
id->npda = id->npdg;
|
|
|
|
/* NOWS = Namespace Optimal Write Size */
|
2022-09-27 16:26:26 +08:00
|
|
|
id->nows = to0based(bdev_io_opt(bdev) / bdev_logical_block_size(bdev));
|
2019-06-29 00:53:30 +08:00
|
|
|
}
|
|
|
|
|
2021-06-10 09:32:52 +08:00
|
|
|
void nvmet_bdev_ns_disable(struct nvmet_ns *ns)
|
|
|
|
{
|
|
|
|
if (ns->bdev) {
|
|
|
|
blkdev_put(ns->bdev, FMODE_WRITE | FMODE_READ);
|
|
|
|
ns->bdev = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 22:05:57 +08:00
|
|
|
static void nvmet_bdev_ns_enable_integrity(struct nvmet_ns *ns)
|
|
|
|
{
|
|
|
|
struct blk_integrity *bi = bdev_get_integrity(ns->bdev);
|
|
|
|
|
|
|
|
if (bi) {
|
|
|
|
ns->metadata_size = bi->tuple_size;
|
|
|
|
if (bi->profile == &t10_pi_type1_crc)
|
|
|
|
ns->pi_type = NVME_NS_DPS_PI_TYPE1;
|
|
|
|
else if (bi->profile == &t10_pi_type3_crc)
|
|
|
|
ns->pi_type = NVME_NS_DPS_PI_TYPE3;
|
|
|
|
else
|
|
|
|
/* Unsupported metadata type */
|
|
|
|
ns->metadata_size = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 12:34:39 +08:00
|
|
|
int nvmet_bdev_ns_enable(struct nvmet_ns *ns)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2022-02-02 17:04:45 +08:00
|
|
|
/*
|
|
|
|
* When buffered_io namespace attribute is enabled that means user want
|
|
|
|
* this block device to be used as a file, so block device can take
|
|
|
|
* an advantage of cache.
|
|
|
|
*/
|
|
|
|
if (ns->buffered_io)
|
|
|
|
return -ENOTBLK;
|
|
|
|
|
2018-05-23 12:34:39 +08:00
|
|
|
ns->bdev = blkdev_get_by_path(ns->device_path,
|
|
|
|
FMODE_READ | FMODE_WRITE, NULL);
|
|
|
|
if (IS_ERR(ns->bdev)) {
|
|
|
|
ret = PTR_ERR(ns->bdev);
|
|
|
|
if (ret != -ENOTBLK) {
|
|
|
|
pr_err("failed to open block device %s: (%ld)\n",
|
|
|
|
ns->device_path, PTR_ERR(ns->bdev));
|
|
|
|
}
|
|
|
|
ns->bdev = NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
2021-10-18 18:11:07 +08:00
|
|
|
ns->size = bdev_nr_bytes(ns->bdev);
|
2018-05-23 12:34:39 +08:00
|
|
|
ns->blksize_shift = blksize_bits(bdev_logical_block_size(ns->bdev));
|
2020-05-19 22:05:57 +08:00
|
|
|
|
|
|
|
ns->pi_type = 0;
|
|
|
|
ns->metadata_size = 0;
|
|
|
|
if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY_T10))
|
|
|
|
nvmet_bdev_ns_enable_integrity(ns);
|
|
|
|
|
2021-06-10 09:32:52 +08:00
|
|
|
if (bdev_is_zoned(ns->bdev)) {
|
|
|
|
if (!nvmet_bdev_zns_enable(ns)) {
|
|
|
|
nvmet_bdev_ns_disable(ns);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
ns->csi = NVME_CSI_ZNS;
|
2018-05-23 12:34:39 +08:00
|
|
|
}
|
2021-06-10 09:32:52 +08:00
|
|
|
|
|
|
|
return 0;
|
2018-05-23 12:34:39 +08:00
|
|
|
}
|
|
|
|
|
2020-04-20 07:48:50 +08:00
|
|
|
void nvmet_bdev_ns_revalidate(struct nvmet_ns *ns)
|
|
|
|
{
|
2021-10-18 18:11:07 +08:00
|
|
|
ns->size = bdev_nr_bytes(ns->bdev);
|
2020-04-20 07:48:50 +08:00
|
|
|
}
|
|
|
|
|
2021-06-10 09:32:52 +08:00
|
|
|
u16 blk_to_nvme_status(struct nvmet_req *req, blk_status_t blk_sts)
|
2018-12-13 07:11:42 +08:00
|
|
|
{
|
|
|
|
u16 status = NVME_SC_SUCCESS;
|
|
|
|
|
|
|
|
if (likely(blk_sts == BLK_STS_OK))
|
|
|
|
return status;
|
|
|
|
/*
|
|
|
|
* Right now there exists M : 1 mapping between block layer error
|
|
|
|
* to the NVMe status code (see nvme_error_status()). For consistency,
|
|
|
|
* when we reverse map we use most appropriate NVMe Status code from
|
|
|
|
* the group of the NVMe staus codes used in the nvme_error_status().
|
|
|
|
*/
|
|
|
|
switch (blk_sts) {
|
|
|
|
case BLK_STS_NOSPC:
|
|
|
|
status = NVME_SC_CAP_EXCEEDED | NVME_SC_DNR;
|
|
|
|
req->error_loc = offsetof(struct nvme_rw_command, length);
|
|
|
|
break;
|
|
|
|
case BLK_STS_TARGET:
|
|
|
|
status = NVME_SC_LBA_RANGE | NVME_SC_DNR;
|
|
|
|
req->error_loc = offsetof(struct nvme_rw_command, slba);
|
|
|
|
break;
|
|
|
|
case BLK_STS_NOTSUPP:
|
|
|
|
req->error_loc = offsetof(struct nvme_common_command, opcode);
|
|
|
|
switch (req->cmd->common.opcode) {
|
|
|
|
case nvme_cmd_dsm:
|
|
|
|
case nvme_cmd_write_zeroes:
|
|
|
|
status = NVME_SC_ONCS_NOT_SUPPORTED | NVME_SC_DNR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
status = NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BLK_STS_MEDIUM:
|
|
|
|
status = NVME_SC_ACCESS_DENIED;
|
|
|
|
req->error_loc = offsetof(struct nvme_rw_command, nsid);
|
|
|
|
break;
|
|
|
|
case BLK_STS_IOERR:
|
|
|
|
default:
|
|
|
|
status = NVME_SC_INTERNAL | NVME_SC_DNR;
|
|
|
|
req->error_loc = offsetof(struct nvme_common_command, opcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (req->cmd->common.opcode) {
|
|
|
|
case nvme_cmd_read:
|
|
|
|
case nvme_cmd_write:
|
|
|
|
req->error_slba = le64_to_cpu(req->cmd->rw.slba);
|
|
|
|
break;
|
|
|
|
case nvme_cmd_write_zeroes:
|
|
|
|
req->error_slba =
|
|
|
|
le64_to_cpu(req->cmd->write_zeroes.slba);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
req->error_slba = 0;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2016-06-22 00:04:20 +08:00
|
|
|
static void nvmet_bio_done(struct bio *bio)
|
|
|
|
{
|
|
|
|
struct nvmet_req *req = bio->bi_private;
|
|
|
|
|
2018-12-13 07:11:42 +08:00
|
|
|
nvmet_req_complete(req, blk_to_nvme_status(req, bio->bi_status));
|
2021-06-10 09:32:50 +08:00
|
|
|
nvmet_req_bio_put(req, bio);
|
2016-06-22 00:04:20 +08:00
|
|
|
}
|
|
|
|
|
2020-05-19 22:06:02 +08:00
|
|
|
#ifdef CONFIG_BLK_DEV_INTEGRITY
|
|
|
|
static int nvmet_bdev_alloc_bip(struct nvmet_req *req, struct bio *bio,
|
|
|
|
struct sg_mapping_iter *miter)
|
|
|
|
{
|
|
|
|
struct blk_integrity *bi;
|
|
|
|
struct bio_integrity_payload *bip;
|
|
|
|
int rc;
|
|
|
|
size_t resid, len;
|
|
|
|
|
2021-06-03 08:37:58 +08:00
|
|
|
bi = bdev_get_integrity(req->ns->bdev);
|
2020-05-19 22:06:02 +08:00
|
|
|
if (unlikely(!bi)) {
|
|
|
|
pr_err("Unable to locate bio_integrity\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
bip = bio_integrity_alloc(bio, GFP_NOIO,
|
2021-01-29 12:38:57 +08:00
|
|
|
bio_max_segs(req->metadata_sg_cnt));
|
2020-05-19 22:06:02 +08:00
|
|
|
if (IS_ERR(bip)) {
|
|
|
|
pr_err("Unable to allocate bio_integrity_payload\n");
|
|
|
|
return PTR_ERR(bip);
|
|
|
|
}
|
|
|
|
|
|
|
|
bip->bip_iter.bi_size = bio_integrity_bytes(bi, bio_sectors(bio));
|
|
|
|
/* virtual start sector must be in integrity interval units */
|
|
|
|
bip_set_seed(bip, bio->bi_iter.bi_sector >>
|
|
|
|
(bi->interval_exp - SECTOR_SHIFT));
|
|
|
|
|
|
|
|
resid = bip->bip_iter.bi_size;
|
|
|
|
while (resid > 0 && sg_miter_next(miter)) {
|
|
|
|
len = min_t(size_t, miter->length, resid);
|
|
|
|
rc = bio_integrity_add_page(bio, miter->page, len,
|
|
|
|
offset_in_page(miter->addr));
|
|
|
|
if (unlikely(rc != len)) {
|
|
|
|
pr_err("bio_integrity_add_page() failed; %d\n", rc);
|
|
|
|
sg_miter_stop(miter);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
resid -= len;
|
|
|
|
if (len < miter->length)
|
|
|
|
miter->consumed -= miter->length - len;
|
|
|
|
}
|
|
|
|
sg_miter_stop(miter);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static int nvmet_bdev_alloc_bip(struct nvmet_req *req, struct bio *bio,
|
|
|
|
struct sg_mapping_iter *miter)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_BLK_DEV_INTEGRITY */
|
|
|
|
|
2018-05-23 12:34:39 +08:00
|
|
|
static void nvmet_bdev_execute_rw(struct nvmet_req *req)
|
2016-06-22 00:04:20 +08:00
|
|
|
{
|
2021-01-29 12:38:57 +08:00
|
|
|
unsigned int sg_cnt = req->sg_cnt;
|
2018-09-29 06:40:43 +08:00
|
|
|
struct bio *bio;
|
2016-06-22 00:04:20 +08:00
|
|
|
struct scatterlist *sg;
|
nvmet: add plugging for read/write when ns is bdev
With reference to the following issue reported on the mailing list :-
http://lists.infradead.org/pipermail/linux-nvme/2019-October/027604.html
this patch adds plugging for the bdev-ns under nvmet_bdev_execute_rw().
We can see the following performance improvement in random write
workload I/Os with the setup described in the link when device_path
configured as /dev/md0.
Without this patch :-
write: IOPS=40.8k, BW=159MiB/s (167MB/s)(4777MiB/30002msec)
write: IOPS=41.2k, BW=161MiB/s (169MB/s)(4831MiB/30011msec)
slat (usec): min=8, max=10823, avg=15.64, stdev=16.85
slat (usec): min=8, max=401, avg=15.40, stdev= 9.56
clat (usec): min=54, max=2492, avg=759.07, stdev=172.62
clat (usec): min=56, max=1997, avg=768.06, stdev=178.72
With this patch :-
write: IOPS=123k, BW=480MiB/s (504MB/s)(14.1GiB/30011msec)
write: IOPS=123k, BW=481MiB/s (504MB/s)(14.1GiB/30002msec)
slat (usec): min=8, max=9941, avg=13.31, stdev= 8.04
slat (usec): min=8, max=289, avg=13.31, stdev= 3.37
clat (usec): min=43, max=17635, avg=245.46, stdev=171.23
clat (usec): min=44, max=17751, avg=245.25, stdev=183.14
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2019-10-29 02:23:26 +08:00
|
|
|
struct blk_plug plug;
|
2016-06-22 00:04:20 +08:00
|
|
|
sector_t sector;
|
2022-07-15 02:07:04 +08:00
|
|
|
blk_opf_t opf;
|
|
|
|
int i, rc;
|
2020-05-19 22:06:02 +08:00
|
|
|
struct sg_mapping_iter prot_miter;
|
|
|
|
unsigned int iter_flags;
|
|
|
|
unsigned int total_len = nvmet_rw_data_len(req) + req->metadata_len;
|
2016-06-22 00:04:20 +08:00
|
|
|
|
2020-05-19 22:06:02 +08:00
|
|
|
if (!nvmet_check_transfer_len(req, total_len))
|
2019-10-24 00:35:44 +08:00
|
|
|
return;
|
|
|
|
|
2016-06-22 00:04:20 +08:00
|
|
|
if (!req->sg_cnt) {
|
|
|
|
nvmet_req_complete(req, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req->cmd->rw.opcode == nvme_cmd_write) {
|
2022-07-15 02:07:04 +08:00
|
|
|
opf = REQ_OP_WRITE | REQ_SYNC | REQ_IDLE;
|
2016-06-22 00:04:20 +08:00
|
|
|
if (req->cmd->rw.control & cpu_to_le16(NVME_RW_FUA))
|
2022-07-15 02:07:04 +08:00
|
|
|
opf |= REQ_FUA;
|
2020-05-19 22:06:02 +08:00
|
|
|
iter_flags = SG_MITER_TO_SG;
|
2016-06-22 00:04:20 +08:00
|
|
|
} else {
|
2022-07-15 02:07:04 +08:00
|
|
|
opf = REQ_OP_READ;
|
2020-05-19 22:06:02 +08:00
|
|
|
iter_flags = SG_MITER_FROM_SG;
|
2016-06-22 00:04:20 +08:00
|
|
|
}
|
|
|
|
|
2018-10-05 05:27:47 +08:00
|
|
|
if (is_pci_p2pdma_page(sg_page(req->sg)))
|
2022-07-15 02:07:04 +08:00
|
|
|
opf |= REQ_NOMERGE;
|
2018-10-05 05:27:47 +08:00
|
|
|
|
2021-01-12 12:26:16 +08:00
|
|
|
sector = nvmet_lba_to_sect(req->ns, req->cmd->rw.slba);
|
2016-06-22 00:04:20 +08:00
|
|
|
|
2021-05-07 09:51:35 +08:00
|
|
|
if (nvmet_use_inline_bvec(req)) {
|
2018-09-29 06:40:43 +08:00
|
|
|
bio = &req->b.inline_bio;
|
2022-01-24 17:11:06 +08:00
|
|
|
bio_init(bio, req->ns->bdev, req->inline_bvec,
|
2022-07-15 02:07:04 +08:00
|
|
|
ARRAY_SIZE(req->inline_bvec), opf);
|
2018-09-29 06:40:43 +08:00
|
|
|
} else {
|
2022-07-15 02:07:04 +08:00
|
|
|
bio = bio_alloc(req->ns->bdev, bio_max_segs(sg_cnt), opf,
|
2022-01-24 17:11:05 +08:00
|
|
|
GFP_KERNEL);
|
2018-09-29 06:40:43 +08:00
|
|
|
}
|
2016-06-22 00:04:20 +08:00
|
|
|
bio->bi_iter.bi_sector = sector;
|
|
|
|
bio->bi_private = req;
|
|
|
|
bio->bi_end_io = nvmet_bio_done;
|
|
|
|
|
nvmet: add plugging for read/write when ns is bdev
With reference to the following issue reported on the mailing list :-
http://lists.infradead.org/pipermail/linux-nvme/2019-October/027604.html
this patch adds plugging for the bdev-ns under nvmet_bdev_execute_rw().
We can see the following performance improvement in random write
workload I/Os with the setup described in the link when device_path
configured as /dev/md0.
Without this patch :-
write: IOPS=40.8k, BW=159MiB/s (167MB/s)(4777MiB/30002msec)
write: IOPS=41.2k, BW=161MiB/s (169MB/s)(4831MiB/30011msec)
slat (usec): min=8, max=10823, avg=15.64, stdev=16.85
slat (usec): min=8, max=401, avg=15.40, stdev= 9.56
clat (usec): min=54, max=2492, avg=759.07, stdev=172.62
clat (usec): min=56, max=1997, avg=768.06, stdev=178.72
With this patch :-
write: IOPS=123k, BW=480MiB/s (504MB/s)(14.1GiB/30011msec)
write: IOPS=123k, BW=481MiB/s (504MB/s)(14.1GiB/30002msec)
slat (usec): min=8, max=9941, avg=13.31, stdev= 8.04
slat (usec): min=8, max=289, avg=13.31, stdev= 3.37
clat (usec): min=43, max=17635, avg=245.46, stdev=171.23
clat (usec): min=44, max=17751, avg=245.25, stdev=183.14
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2019-10-29 02:23:26 +08:00
|
|
|
blk_start_plug(&plug);
|
2020-05-19 22:06:02 +08:00
|
|
|
if (req->metadata_len)
|
|
|
|
sg_miter_start(&prot_miter, req->metadata_sg,
|
|
|
|
req->metadata_sg_cnt, iter_flags);
|
|
|
|
|
2016-06-22 00:04:20 +08:00
|
|
|
for_each_sg(req->sg, sg, req->sg_cnt, i) {
|
|
|
|
while (bio_add_page(bio, sg_page(sg), sg->length, sg->offset)
|
|
|
|
!= sg->length) {
|
|
|
|
struct bio *prev = bio;
|
|
|
|
|
2020-05-19 22:06:02 +08:00
|
|
|
if (req->metadata_len) {
|
|
|
|
rc = nvmet_bdev_alloc_bip(req, bio,
|
|
|
|
&prot_miter);
|
|
|
|
if (unlikely(rc)) {
|
|
|
|
bio_io_error(bio);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-24 17:11:05 +08:00
|
|
|
bio = bio_alloc(req->ns->bdev, bio_max_segs(sg_cnt),
|
2022-07-15 02:07:04 +08:00
|
|
|
opf, GFP_KERNEL);
|
2016-06-22 00:04:20 +08:00
|
|
|
bio->bi_iter.bi_sector = sector;
|
|
|
|
|
|
|
|
bio_chain(bio, prev);
|
2017-07-10 22:24:02 +08:00
|
|
|
submit_bio(prev);
|
2016-06-22 00:04:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sector += sg->length >> 9;
|
|
|
|
sg_cnt--;
|
|
|
|
}
|
|
|
|
|
2020-05-19 22:06:02 +08:00
|
|
|
if (req->metadata_len) {
|
|
|
|
rc = nvmet_bdev_alloc_bip(req, bio, &prot_miter);
|
|
|
|
if (unlikely(rc)) {
|
|
|
|
bio_io_error(bio);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-13 15:01:54 +08:00
|
|
|
submit_bio(bio);
|
nvmet: add plugging for read/write when ns is bdev
With reference to the following issue reported on the mailing list :-
http://lists.infradead.org/pipermail/linux-nvme/2019-October/027604.html
this patch adds plugging for the bdev-ns under nvmet_bdev_execute_rw().
We can see the following performance improvement in random write
workload I/Os with the setup described in the link when device_path
configured as /dev/md0.
Without this patch :-
write: IOPS=40.8k, BW=159MiB/s (167MB/s)(4777MiB/30002msec)
write: IOPS=41.2k, BW=161MiB/s (169MB/s)(4831MiB/30011msec)
slat (usec): min=8, max=10823, avg=15.64, stdev=16.85
slat (usec): min=8, max=401, avg=15.40, stdev= 9.56
clat (usec): min=54, max=2492, avg=759.07, stdev=172.62
clat (usec): min=56, max=1997, avg=768.06, stdev=178.72
With this patch :-
write: IOPS=123k, BW=480MiB/s (504MB/s)(14.1GiB/30011msec)
write: IOPS=123k, BW=481MiB/s (504MB/s)(14.1GiB/30002msec)
slat (usec): min=8, max=9941, avg=13.31, stdev= 8.04
slat (usec): min=8, max=289, avg=13.31, stdev= 3.37
clat (usec): min=43, max=17635, avg=245.46, stdev=171.23
clat (usec): min=44, max=17751, avg=245.25, stdev=183.14
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2019-10-29 02:23:26 +08:00
|
|
|
blk_finish_plug(&plug);
|
2016-06-22 00:04:20 +08:00
|
|
|
}
|
|
|
|
|
2018-05-23 12:34:39 +08:00
|
|
|
static void nvmet_bdev_execute_flush(struct nvmet_req *req)
|
2016-06-22 00:04:20 +08:00
|
|
|
{
|
2018-05-23 12:34:39 +08:00
|
|
|
struct bio *bio = &req->b.inline_bio;
|
2016-06-22 00:04:20 +08:00
|
|
|
|
2022-07-29 11:53:05 +08:00
|
|
|
if (!bdev_write_cache(req->ns->bdev)) {
|
|
|
|
nvmet_req_complete(req, NVME_SC_SUCCESS);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-19 22:05:59 +08:00
|
|
|
if (!nvmet_check_transfer_len(req, 0))
|
2019-10-24 00:35:44 +08:00
|
|
|
return;
|
|
|
|
|
2022-01-24 17:11:06 +08:00
|
|
|
bio_init(bio, req->ns->bdev, req->inline_bvec,
|
|
|
|
ARRAY_SIZE(req->inline_bvec), REQ_OP_WRITE | REQ_PREFLUSH);
|
2016-06-22 00:04:20 +08:00
|
|
|
bio->bi_private = req;
|
|
|
|
bio->bi_end_io = nvmet_bio_done;
|
|
|
|
|
|
|
|
submit_bio(bio);
|
|
|
|
}
|
|
|
|
|
2018-08-08 14:01:07 +08:00
|
|
|
u16 nvmet_bdev_flush(struct nvmet_req *req)
|
|
|
|
{
|
2022-07-29 11:53:05 +08:00
|
|
|
if (!bdev_write_cache(req->ns->bdev))
|
|
|
|
return 0;
|
|
|
|
|
2021-01-26 22:52:35 +08:00
|
|
|
if (blkdev_issue_flush(req->ns->bdev))
|
2018-08-08 14:01:07 +08:00
|
|
|
return NVME_SC_INTERNAL | NVME_SC_DNR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-13 07:11:42 +08:00
|
|
|
static u16 nvmet_bdev_discard_range(struct nvmet_req *req,
|
2016-06-22 00:04:20 +08:00
|
|
|
struct nvme_dsm_range *range, struct bio **bio)
|
|
|
|
{
|
2018-12-13 07:11:42 +08:00
|
|
|
struct nvmet_ns *ns = req->ns;
|
2018-01-30 18:07:01 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = __blkdev_issue_discard(ns->bdev,
|
2021-01-12 12:26:16 +08:00
|
|
|
nvmet_lba_to_sect(ns, range->slba),
|
2016-06-22 00:04:20 +08:00
|
|
|
le32_to_cpu(range->nlb) << (ns->blksize_shift - 9),
|
2022-04-15 12:52:57 +08:00
|
|
|
GFP_KERNEL, bio);
|
2019-03-14 01:55:09 +08:00
|
|
|
if (ret && ret != -EOPNOTSUPP) {
|
2018-12-13 07:11:42 +08:00
|
|
|
req->error_slba = le64_to_cpu(range->slba);
|
2019-03-13 01:05:10 +08:00
|
|
|
return errno_to_nvme_status(req, ret);
|
2019-03-14 01:55:09 +08:00
|
|
|
}
|
|
|
|
return NVME_SC_SUCCESS;
|
2016-06-22 00:04:20 +08:00
|
|
|
}
|
|
|
|
|
2018-05-23 12:34:39 +08:00
|
|
|
static void nvmet_bdev_execute_discard(struct nvmet_req *req)
|
2016-06-22 00:04:20 +08:00
|
|
|
{
|
|
|
|
struct nvme_dsm_range range;
|
|
|
|
struct bio *bio = NULL;
|
|
|
|
int i;
|
|
|
|
u16 status;
|
|
|
|
|
|
|
|
for (i = 0; i <= le32_to_cpu(req->cmd->dsm.nr); i++) {
|
|
|
|
status = nvmet_copy_from_sgl(req, i * sizeof(range), &range,
|
|
|
|
sizeof(range));
|
|
|
|
if (status)
|
|
|
|
break;
|
|
|
|
|
2018-12-13 07:11:42 +08:00
|
|
|
status = nvmet_bdev_discard_range(req, &range, &bio);
|
2016-06-22 00:04:20 +08:00
|
|
|
if (status)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bio) {
|
|
|
|
bio->bi_private = req;
|
|
|
|
bio->bi_end_io = nvmet_bio_done;
|
2019-10-14 00:57:32 +08:00
|
|
|
if (status)
|
|
|
|
bio_io_error(bio);
|
|
|
|
else
|
2016-06-22 00:04:20 +08:00
|
|
|
submit_bio(bio);
|
|
|
|
} else {
|
|
|
|
nvmet_req_complete(req, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 12:34:39 +08:00
|
|
|
static void nvmet_bdev_execute_dsm(struct nvmet_req *req)
|
2016-06-22 00:04:20 +08:00
|
|
|
{
|
2020-01-27 15:23:28 +08:00
|
|
|
if (!nvmet_check_data_len_lte(req, nvmet_dsm_len(req)))
|
2019-10-24 00:35:44 +08:00
|
|
|
return;
|
|
|
|
|
2016-06-22 00:04:20 +08:00
|
|
|
switch (le32_to_cpu(req->cmd->dsm.attributes)) {
|
|
|
|
case NVME_DSMGMT_AD:
|
2018-05-23 12:34:39 +08:00
|
|
|
nvmet_bdev_execute_discard(req);
|
2016-06-22 00:04:20 +08:00
|
|
|
return;
|
|
|
|
case NVME_DSMGMT_IDR:
|
|
|
|
case NVME_DSMGMT_IDW:
|
|
|
|
default:
|
|
|
|
/* Not supported yet */
|
|
|
|
nvmet_req_complete(req, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 12:34:39 +08:00
|
|
|
static void nvmet_bdev_execute_write_zeroes(struct nvmet_req *req)
|
2016-12-01 04:29:02 +08:00
|
|
|
{
|
|
|
|
struct nvme_write_zeroes_cmd *write_zeroes = &req->cmd->write_zeroes;
|
|
|
|
struct bio *bio = NULL;
|
|
|
|
sector_t sector;
|
|
|
|
sector_t nr_sector;
|
2018-12-13 07:11:42 +08:00
|
|
|
int ret;
|
2016-12-01 04:29:02 +08:00
|
|
|
|
2020-05-19 22:05:59 +08:00
|
|
|
if (!nvmet_check_transfer_len(req, 0))
|
2019-10-24 00:35:44 +08:00
|
|
|
return;
|
|
|
|
|
2021-01-12 12:26:16 +08:00
|
|
|
sector = nvmet_lba_to_sect(req->ns, write_zeroes->slba);
|
2018-04-12 23:16:11 +08:00
|
|
|
nr_sector = (((sector_t)le16_to_cpu(write_zeroes->length) + 1) <<
|
|
|
|
(req->ns->blksize_shift - 9));
|
2016-12-01 04:29:02 +08:00
|
|
|
|
2018-12-13 07:11:42 +08:00
|
|
|
ret = __blkdev_issue_zeroout(req->ns->bdev, sector, nr_sector,
|
|
|
|
GFP_KERNEL, &bio, 0);
|
2016-12-01 04:29:02 +08:00
|
|
|
if (bio) {
|
|
|
|
bio->bi_private = req;
|
|
|
|
bio->bi_end_io = nvmet_bio_done;
|
|
|
|
submit_bio(bio);
|
|
|
|
} else {
|
2019-03-13 01:05:10 +08:00
|
|
|
nvmet_req_complete(req, errno_to_nvme_status(req, ret));
|
2016-12-01 04:29:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 12:34:39 +08:00
|
|
|
u16 nvmet_bdev_parse_io_cmd(struct nvmet_req *req)
|
2016-06-22 00:04:20 +08:00
|
|
|
{
|
2021-06-14 09:58:46 +08:00
|
|
|
switch (req->cmd->common.opcode) {
|
2016-06-22 00:04:20 +08:00
|
|
|
case nvme_cmd_read:
|
|
|
|
case nvme_cmd_write:
|
2018-05-23 12:34:39 +08:00
|
|
|
req->execute = nvmet_bdev_execute_rw;
|
2020-05-19 22:06:02 +08:00
|
|
|
if (req->sq->ctrl->pi_support && nvmet_ns_has_pi(req->ns))
|
|
|
|
req->metadata_len = nvmet_rw_metadata_len(req);
|
2016-06-22 00:04:20 +08:00
|
|
|
return 0;
|
|
|
|
case nvme_cmd_flush:
|
2018-05-23 12:34:39 +08:00
|
|
|
req->execute = nvmet_bdev_execute_flush;
|
2016-06-22 00:04:20 +08:00
|
|
|
return 0;
|
|
|
|
case nvme_cmd_dsm:
|
2018-05-23 12:34:39 +08:00
|
|
|
req->execute = nvmet_bdev_execute_dsm;
|
2016-06-22 00:04:20 +08:00
|
|
|
return 0;
|
2016-12-01 04:29:02 +08:00
|
|
|
case nvme_cmd_write_zeroes:
|
2018-05-23 12:34:39 +08:00
|
|
|
req->execute = nvmet_bdev_execute_write_zeroes;
|
2016-12-01 04:29:02 +08:00
|
|
|
return 0;
|
2016-06-22 00:04:20 +08:00
|
|
|
default:
|
2021-02-10 13:47:56 +08:00
|
|
|
return nvmet_report_invalid_opcode(req);
|
2016-06-22 00:04:20 +08:00
|
|
|
}
|
|
|
|
}
|