All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/3] NVMe 1.4 Identify Namespace Support
@ 2019-06-17 16:12 Bart Van Assche
  2019-06-17 16:12 ` [PATCH v3 1/3] nvme: Introduce NVMe 1.4 Identify Namespace fields in struct nvme_id_ns Bart Van Assche
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: Bart Van Assche @ 2019-06-17 16:12 UTC (permalink / raw)


Hi Christoph,

This patch series adds support for several of the new parameters introduced
in the NVMe 1.4 Identify Namespace command. Please consider these patches
for kernel version 5.3.

Thanks,

Bart.

Changes compared to v2:
- In the initiator, use AWUPF instead NAWUPF if NAWUPF == 0.

Changes compared to v1:
- Added a patch for the NVMe target code that exports these parameters.
- Limited the physical block size to the value of AWUPF/NAWUPF as appropriate.

Bart Van Assche (3):
  nvme: Introduce NVMe 1.4 Identify Namespace fields in struct
    nvme_id_ns
  nvmet: Export NVMe namespace attributes
  nvme: Set physical block size and optimal I/O size according to NVMe
    1.4

 drivers/nvme/host/core.c          | 30 +++++++++++++++++++--
 drivers/nvme/host/nvme.h          |  1 +
 drivers/nvme/target/admin-cmd.c   |  5 ++++
 drivers/nvme/target/io-cmd-bdev.c | 45 +++++++++++++++++++++++++++++++
 drivers/nvme/target/io-cmd-file.c | 37 +++++++++++++++++++++++++
 drivers/nvme/target/nvmet.h       |  2 ++
 include/linux/nvme.h              | 12 ++++++---
 7 files changed, 127 insertions(+), 5 deletions(-)

-- 
2.22.0.rc3

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 1/3] nvme: Introduce NVMe 1.4 Identify Namespace fields in struct nvme_id_ns
  2019-06-17 16:12 [PATCH v3 0/3] NVMe 1.4 Identify Namespace Support Bart Van Assche
@ 2019-06-17 16:12 ` Bart Van Assche
  2019-06-18  7:49   ` Hannes Reinecke
  2019-06-17 16:12 ` [PATCH v3 2/3] nvmet: Export NVMe namespace attributes Bart Van Assche
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 17+ messages in thread
From: Bart Van Assche @ 2019-06-17 16:12 UTC (permalink / raw)


Several new fields have been introduced in version 1.4 of the NVMe spec
at offsets that were defined as reserved in version 1.3d of the NVMe
spec. Update the definition of the nvme_id_ns data structure such that
it is in sync with version 1.4 of the NVMe spec. This change preserves
backwards compatibility.

Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
Reviewed-by: Martin K. Petersen <martin.petersen at oracle.com>
Reviewed-by: Keith Busch <kbusch at kernel.org>
Cc: Sagi Grimberg <sagi at grimberg.me>
Cc: Hannes Reinecke <hare at suse.com>
Signed-off-by: Bart Van Assche <bvanassche at acm.org>
---
 include/linux/nvme.h | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/include/linux/nvme.h b/include/linux/nvme.h
index 8028adacaff3..2b5072ec4511 100644
--- a/include/linux/nvme.h
+++ b/include/linux/nvme.h
@@ -315,7 +315,7 @@ struct nvme_id_ns {
 	__u8			nmic;
 	__u8			rescap;
 	__u8			fpi;
-	__u8			rsvd33;
+	__u8			dlfeat;
 	__le16			nawun;
 	__le16			nawupf;
 	__le16			nacwu;
@@ -324,11 +324,17 @@ struct nvme_id_ns {
 	__le16			nabspf;
 	__le16			noiob;
 	__u8			nvmcap[16];
-	__u8			rsvd64[28];
+	__le16			npwg;
+	__le16			npwa;
+	__le16			npdg;
+	__le16			npda;
+	__le16			nows;
+	__u8			rsvd74[18];
 	__le32			anagrpid;
 	__u8			rsvd96[3];
 	__u8			nsattr;
-	__u8			rsvd100[4];
+	__le16			nvmsetid;
+	__le16			endgid;
 	__u8			nguid[16];
 	__u8			eui64[8];
 	struct nvme_lbaf	lbaf[16];
-- 
2.22.0.rc3

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v3 2/3] nvmet: Export NVMe namespace attributes
  2019-06-17 16:12 [PATCH v3 0/3] NVMe 1.4 Identify Namespace Support Bart Van Assche
  2019-06-17 16:12 ` [PATCH v3 1/3] nvme: Introduce NVMe 1.4 Identify Namespace fields in struct nvme_id_ns Bart Van Assche
@ 2019-06-17 16:12 ` Bart Van Assche
  2019-06-18  7:50   ` Hannes Reinecke
                     ` (2 more replies)
  2019-06-17 16:12 ` [PATCH v3 3/3] nvme: Set physical block size and optimal I/O size according to NVMe 1.4 Bart Van Assche
  2019-06-18  7:52 ` [PATCH v3 0/3] NVMe 1.4 Identify Namespace Support Hannes Reinecke
  3 siblings, 3 replies; 17+ messages in thread
From: Bart Van Assche @ 2019-06-17 16:12 UTC (permalink / raw)


Make the NVMe NAWUN, NAWUPF, NACWU, NPWG, NPWA, NPDG and NOWS attributes
available to initator systems.

Cc: Keith Busch <kbusch at kernel.org>
Cc: Sagi Grimberg <sagi at grimberg.me>
Cc: Martin K. Petersen <martin.petersen at oracle.com>
Cc: Hannes Reinecke <hare at suse.com>
Cc: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
Signed-off-by: Bart Van Assche <bvanassche at acm.org>
---
 drivers/nvme/target/admin-cmd.c   |  5 ++++
 drivers/nvme/target/io-cmd-bdev.c | 45 +++++++++++++++++++++++++++++++
 drivers/nvme/target/io-cmd-file.c | 37 +++++++++++++++++++++++++
 drivers/nvme/target/nvmet.h       |  2 ++
 4 files changed, 89 insertions(+)

diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index 9f72d515fc4b..2558ed333d29 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -442,6 +442,11 @@ static void nvmet_execute_identify_ns(struct nvmet_req *req)
 		break;
         }
 
+	if (ns->file)
+		nvmet_file_set_limits(ns->file, id);
+	else if (ns->bdev)
+		nvmet_bdev_set_limits(ns->bdev, id);
+
 	/*
 	 * We just provide a single LBA format that matches what the
 	 * underlying device reports.
diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c
index 3efc52f9c309..5fe51e5d2f1b 100644
--- a/drivers/nvme/target/io-cmd-bdev.c
+++ b/drivers/nvme/target/io-cmd-bdev.c
@@ -8,6 +8,51 @@
 #include <linux/module.h>
 #include "nvmet.h"
 
+/* Convert a 32-bit number to a 16-bit 0's based number */
+static __le16 to0based(u32 a)
+{
+	return cpu_to_le16(max(1U, min(1U << 16, a)) - 1);
+}
+
+void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id)
+{
+	const struct queue_limits *ql = &bdev_get_queue(bdev)->limits;
+	/* Number of physical blocks per logical block. */
+	const u32 ppl = ql->physical_block_size / ql->logical_block_size;
+	/* Physical blocks per logical block, 0's based. */
+	const __le16 ppl0b = to0based(ppl);
+
+	/*
+	 * 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;
+	id->nawun = ppl0b;
+	id->nawupf = ppl0b;
+	id->nacwu = ppl0b;
+
+	/*
+	 * For NVMe 1.4 and later, 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 */
+	id->npwg = ppl0b;
+	/* NPWA = Namespace Preferred Write Alignment. 0's based */
+	id->npwa = id->npwg;
+	/* NPDG = Namespace Preferred Deallocate Granularity. 0's based */
+	id->npdg = to0based(ql->discard_granularity / ql->logical_block_size);
+	/* NPDG = Namespace Preferred Deallocate Alignment */
+	id->npda = id->npdg;
+	/* NOWS = Namespace Optimal Write Size */
+	id->nows = to0based(ql->io_opt / ql->logical_block_size);
+}
+
 int nvmet_bdev_ns_enable(struct nvmet_ns *ns)
 {
 	int ret;
diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c
index 05453f5d1448..268dfc678567 100644
--- a/drivers/nvme/target/io-cmd-file.c
+++ b/drivers/nvme/target/io-cmd-file.c
@@ -13,6 +13,43 @@
 #define NVMET_MAX_MPOOL_BVEC		16
 #define NVMET_MIN_MPOOL_OBJ		16
 
+void nvmet_file_set_limits(struct file *file, struct nvme_id_ns *id)
+{
+	/*
+	 * Physical blocks per logical block, 0's based. Is it possible to
+	 * extract this information from the filesystem properties?
+	 */
+	const __le16 ppl0b = cpu_to_le16(0);
+
+	/*
+	 * 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.
+	 */
+	id->nsfeat |= 1 << 1;
+	id->nawun = ppl0b;
+	id->nawupf = ppl0b;
+	id->nacwu = ppl0b;
+
+	/*
+	 * For NVMe 1.4 and later, 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 */
+	id->npwg = ppl0b;
+	/* NPWA = Namespace Preferred Write Alignment. 0's based */
+	id->npwa = id->npwg;
+	/* NPDG = Namespace Preferred Deallocate Granularity. 0's based */
+	id->npdg = ppl0b;
+	/* NPDG = Namespace Preferred Deallocate Alignment */
+	id->npda = id->npdg;
+	/* NOWS = Namespace Optimal Write Size */
+	id->nows = ppl0b;
+}
+
 void nvmet_file_ns_disable(struct nvmet_ns *ns)
 {
 	if (ns->file) {
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index c25d88fc9dec..ed0362544932 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -363,6 +363,8 @@ u16 nvmet_set_feat_async_event(struct nvmet_req *req, u32 mask);
 void nvmet_execute_async_event(struct nvmet_req *req);
 
 u16 nvmet_parse_connect_cmd(struct nvmet_req *req);
+void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id);
+void nvmet_file_set_limits(struct file *file, struct nvme_id_ns *id);
 u16 nvmet_bdev_parse_io_cmd(struct nvmet_req *req);
 u16 nvmet_file_parse_io_cmd(struct nvmet_req *req);
 u16 nvmet_parse_admin_cmd(struct nvmet_req *req);
-- 
2.22.0.rc3

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v3 3/3] nvme: Set physical block size and optimal I/O size according to NVMe 1.4
  2019-06-17 16:12 [PATCH v3 0/3] NVMe 1.4 Identify Namespace Support Bart Van Assche
  2019-06-17 16:12 ` [PATCH v3 1/3] nvme: Introduce NVMe 1.4 Identify Namespace fields in struct nvme_id_ns Bart Van Assche
  2019-06-17 16:12 ` [PATCH v3 2/3] nvmet: Export NVMe namespace attributes Bart Van Assche
@ 2019-06-17 16:12 ` Bart Van Assche
  2019-06-18  7:51   ` Hannes Reinecke
  2019-06-19  4:17   ` Martin K. Petersen
  2019-06-18  7:52 ` [PATCH v3 0/3] NVMe 1.4 Identify Namespace Support Hannes Reinecke
  3 siblings, 2 replies; 17+ messages in thread
From: Bart Van Assche @ 2019-06-17 16:12 UTC (permalink / raw)


>From the NVMe 1.4 spec:

NSFEAT bit 4 if set to 1: 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;
[ ... ]
Namespace Preferred Write Granularity (NPWG): This field indicates the
smallest recommended write granularity in logical blocks for this namespace.
This is a 0's based value. The size indicated should be less than or equal
to Maximum Data Transfer Size (MDTS) that is specified in units of minimum
memory page size. The value of this field may change if the namespace is
reformatted. The size should be a multiple of Namespace Preferred Write
Alignment (NPWA). Refer to section 8.25 for how this field is utilized to
improve performance and endurance.
[ ... ]
Each Write, Write Uncorrectable, or Write Zeroes commands should address a
multiple of Namespace Preferred Write Granularity (NPWG) (refer to Figure
245) and Stream Write Size (SWS) (refer to Figure 515) logical blocks (as
expressed in the NLB field), and the SLBA field of the command should be
aligned to Namespace Preferred Write Alignment (NPWA) (refer to Figure 245)
for best performance.

Cc: Keith Busch <kbusch at kernel.org>
Cc: Sagi Grimberg <sagi at grimberg.me>
Cc: Hannes Reinecke <hare at suse.com>
Signed-off-by: Bart Van Assche <bvanassche at acm.org>
---
 drivers/nvme/host/core.c | 30 ++++++++++++++++++++++++++++--
 drivers/nvme/host/nvme.h |  1 +
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 1b7c2afd84cb..5b92d875a1a6 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1608,6 +1608,7 @@ static void nvme_update_disk_info(struct gendisk *disk,
 {
 	sector_t capacity = le64_to_cpu(id->nsze) << (ns->lba_shift - 9);
 	unsigned short bs = 1 << ns->lba_shift;
+	u32 atomic_bs, phys_bs, io_opt;
 
 	if (ns->lba_shift > PAGE_SHIFT) {
 		/* unsupported block size, set capacity to 0 later */
@@ -1616,9 +1617,33 @@ static void nvme_update_disk_info(struct gendisk *disk,
 	blk_mq_freeze_queue(disk->queue);
 	blk_integrity_unregister(disk);
 
+	/*
+	 * Bit 1 indicates whether NAWUPF is defined for this namespace
+	 * and whether it should be used instead of AWUPF. If NAWUPF == 0
+	 * then AWUPF must be used instead.
+	 */
+	if (id->nsfeat & (1 << 1) && id->nawupf)
+		atomic_bs = (1 + id->nawupf) * bs;
+	else
+		atomic_bs = (1 + ns->ctrl->subsys->awupf) * bs;
+	phys_bs = bs;
+	io_opt = bs;
+	if (id->nsfeat & (1 << 4)) {
+		/* NPWG = Namespace Preferred Write Granularity */
+		phys_bs *= 1 + le16_to_cpu(id->npwg);
+		/* NOWS = Namespace Optimal Write Size */
+		io_opt *= 1 + le16_to_cpu(id->nows);
+	}
+
 	blk_queue_logical_block_size(disk->queue, bs);
-	blk_queue_physical_block_size(disk->queue, bs);
-	blk_queue_io_min(disk->queue, bs);
+	/*
+	 * Linux filesystems assume writing a single physical block is
+	 * an atomic operation. Hence limit the physical block size to the
+	 * value of the Atomic Write Unit Power Fail parameter.
+	 */
+	blk_queue_physical_block_size(disk->queue, min(phys_bs, atomic_bs));
+	blk_queue_io_min(disk->queue, phys_bs);
+	blk_queue_io_opt(disk->queue, io_opt);
 
 	if (ns->ms && !ns->ext &&
 	    (ns->ctrl->ops->flags & NVME_F_METADATA_SUPPORTED))
@@ -2415,6 +2440,7 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
 	memcpy(subsys->firmware_rev, id->fr, sizeof(subsys->firmware_rev));
 	subsys->vendor_id = le16_to_cpu(id->vid);
 	subsys->cmic = id->cmic;
+	subsys->awupf = le16_to_cpu(id->awupf);
 #ifdef CONFIG_NVME_MULTIPATH
 	subsys->iopolicy = NVME_IOPOLICY_NUMA;
 #endif
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 55553d293a98..d93279fd5960 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -272,6 +272,7 @@ struct nvme_subsystem {
 	char			firmware_rev[8];
 	u8			cmic;
 	u16			vendor_id;
+	u16			awupf;	/* 0's based awupf value. */
 	struct ida		ns_ida;
 #ifdef CONFIG_NVME_MULTIPATH
 	enum nvme_iopolicy	iopolicy;
-- 
2.22.0.rc3

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v3 1/3] nvme: Introduce NVMe 1.4 Identify Namespace fields in struct nvme_id_ns
  2019-06-17 16:12 ` [PATCH v3 1/3] nvme: Introduce NVMe 1.4 Identify Namespace fields in struct nvme_id_ns Bart Van Assche
@ 2019-06-18  7:49   ` Hannes Reinecke
  0 siblings, 0 replies; 17+ messages in thread
From: Hannes Reinecke @ 2019-06-18  7:49 UTC (permalink / raw)


On 6/17/19 6:12 PM, Bart Van Assche wrote:
> Several new fields have been introduced in version 1.4 of the NVMe spec
> at offsets that were defined as reserved in version 1.3d of the NVMe
> spec. Update the definition of the nvme_id_ns data structure such that
> it is in sync with version 1.4 of the NVMe spec. This change preserves
> backwards compatibility.
> 
> Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
> Reviewed-by: Martin K. Petersen <martin.petersen at oracle.com>
> Reviewed-by: Keith Busch <kbusch at kernel.org>
> Cc: Sagi Grimberg <sagi at grimberg.me>
> Cc: Hannes Reinecke <hare at suse.com>
> Signed-off-by: Bart Van Assche <bvanassche at acm.org>
> ---
>  include/linux/nvme.h | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare at suse.com>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare at suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG N?rnberg)

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 2/3] nvmet: Export NVMe namespace attributes
  2019-06-17 16:12 ` [PATCH v3 2/3] nvmet: Export NVMe namespace attributes Bart Van Assche
@ 2019-06-18  7:50   ` Hannes Reinecke
  2019-06-19  4:13   ` Martin K. Petersen
  2019-06-20  3:19   ` Chaitanya Kulkarni
  2 siblings, 0 replies; 17+ messages in thread
From: Hannes Reinecke @ 2019-06-18  7:50 UTC (permalink / raw)


On 6/17/19 6:12 PM, Bart Van Assche wrote:
> Make the NVMe NAWUN, NAWUPF, NACWU, NPWG, NPWA, NPDG and NOWS attributes
> available to initator systems.
> 
> Cc: Keith Busch <kbusch at kernel.org>
> Cc: Sagi Grimberg <sagi at grimberg.me>
> Cc: Martin K. Petersen <martin.petersen at oracle.com>
> Cc: Hannes Reinecke <hare at suse.com>
> Cc: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
> Signed-off-by: Bart Van Assche <bvanassche at acm.org>
> ---
>  drivers/nvme/target/admin-cmd.c   |  5 ++++
>  drivers/nvme/target/io-cmd-bdev.c | 45 +++++++++++++++++++++++++++++++
>  drivers/nvme/target/io-cmd-file.c | 37 +++++++++++++++++++++++++
>  drivers/nvme/target/nvmet.h       |  2 ++
>  4 files changed, 89 insertions(+)
> 
Reviewed-by: Hannes Reinecke <hare at suse.com>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare at suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG N?rnberg)

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 3/3] nvme: Set physical block size and optimal I/O size according to NVMe 1.4
  2019-06-17 16:12 ` [PATCH v3 3/3] nvme: Set physical block size and optimal I/O size according to NVMe 1.4 Bart Van Assche
@ 2019-06-18  7:51   ` Hannes Reinecke
  2019-06-19  4:17   ` Martin K. Petersen
  1 sibling, 0 replies; 17+ messages in thread
From: Hannes Reinecke @ 2019-06-18  7:51 UTC (permalink / raw)


On 6/17/19 6:12 PM, Bart Van Assche wrote:
> From the NVMe 1.4 spec:
> 
> NSFEAT bit 4 if set to 1: 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;
> [ ... ]
> Namespace Preferred Write Granularity (NPWG): This field indicates the
> smallest recommended write granularity in logical blocks for this namespace.
> This is a 0's based value. The size indicated should be less than or equal
> to Maximum Data Transfer Size (MDTS) that is specified in units of minimum
> memory page size. The value of this field may change if the namespace is
> reformatted. The size should be a multiple of Namespace Preferred Write
> Alignment (NPWA). Refer to section 8.25 for how this field is utilized to
> improve performance and endurance.
> [ ... ]
> Each Write, Write Uncorrectable, or Write Zeroes commands should address a
> multiple of Namespace Preferred Write Granularity (NPWG) (refer to Figure
> 245) and Stream Write Size (SWS) (refer to Figure 515) logical blocks (as
> expressed in the NLB field), and the SLBA field of the command should be
> aligned to Namespace Preferred Write Alignment (NPWA) (refer to Figure 245)
> for best performance.
> 
> Cc: Keith Busch <kbusch at kernel.org>
> Cc: Sagi Grimberg <sagi at grimberg.me>
> Cc: Hannes Reinecke <hare at suse.com>
> Signed-off-by: Bart Van Assche <bvanassche at acm.org>
> ---
>  drivers/nvme/host/core.c | 30 ++++++++++++++++++++++++++++--
>  drivers/nvme/host/nvme.h |  1 +
>  2 files changed, 29 insertions(+), 2 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare at suse.com>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare at suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG N?rnberg)

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 0/3] NVMe 1.4 Identify Namespace Support
  2019-06-17 16:12 [PATCH v3 0/3] NVMe 1.4 Identify Namespace Support Bart Van Assche
                   ` (2 preceding siblings ...)
  2019-06-17 16:12 ` [PATCH v3 3/3] nvme: Set physical block size and optimal I/O size according to NVMe 1.4 Bart Van Assche
@ 2019-06-18  7:52 ` Hannes Reinecke
  2019-06-18 20:34   ` Bart Van Assche
  3 siblings, 1 reply; 17+ messages in thread
From: Hannes Reinecke @ 2019-06-18  7:52 UTC (permalink / raw)


On 6/17/19 6:12 PM, Bart Van Assche wrote:
> Hi Christoph,
> 
> This patch series adds support for several of the new parameters introduced
> in the NVMe 1.4 Identify Namespace command. Please consider these patches
> for kernel version 5.3.
> 
> Thanks,
> 
> Bart.
> 
> Changes compared to v2:
> - In the initiator, use AWUPF instead NAWUPF if NAWUPF == 0.
> 
> Changes compared to v1:
> - Added a patch for the NVMe target code that exports these parameters.
> - Limited the physical block size to the value of AWUPF/NAWUPF as appropriate.
> 
> Bart Van Assche (3):
>   nvme: Introduce NVMe 1.4 Identify Namespace fields in struct
>     nvme_id_ns
>   nvmet: Export NVMe namespace attributes
>   nvme: Set physical block size and optimal I/O size according to NVMe
>     1.4
> 
>  drivers/nvme/host/core.c          | 30 +++++++++++++++++++--
>  drivers/nvme/host/nvme.h          |  1 +
>  drivers/nvme/target/admin-cmd.c   |  5 ++++
>  drivers/nvme/target/io-cmd-bdev.c | 45 +++++++++++++++++++++++++++++++
>  drivers/nvme/target/io-cmd-file.c | 37 +++++++++++++++++++++++++
>  drivers/nvme/target/nvmet.h       |  2 ++
>  include/linux/nvme.h              | 12 ++++++---
>  7 files changed, 127 insertions(+), 5 deletions(-)
> 
Can you send a patch for nvme-cli, too?

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare at suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG N?rnberg)

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 0/3] NVMe 1.4 Identify Namespace Support
  2019-06-18  7:52 ` [PATCH v3 0/3] NVMe 1.4 Identify Namespace Support Hannes Reinecke
@ 2019-06-18 20:34   ` Bart Van Assche
  0 siblings, 0 replies; 17+ messages in thread
From: Bart Van Assche @ 2019-06-18 20:34 UTC (permalink / raw)


On 6/18/19 12:52 AM, Hannes Reinecke wrote:
> Can you send a patch for nvme-cli, too?

Sure. But I do not know what the preferred approach is for contributing 
to nvme-cli? Should I post a patch on this mailing list or rather send a 
github pull request?

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 2/3] nvmet: Export NVMe namespace attributes
  2019-06-17 16:12 ` [PATCH v3 2/3] nvmet: Export NVMe namespace attributes Bart Van Assche
  2019-06-18  7:50   ` Hannes Reinecke
@ 2019-06-19  4:13   ` Martin K. Petersen
  2019-06-19 15:44     ` Bart Van Assche
  2019-06-20  3:19   ` Chaitanya Kulkarni
  2 siblings, 1 reply; 17+ messages in thread
From: Martin K. Petersen @ 2019-06-19  4:13 UTC (permalink / raw)



Bart,

> +	/*
> +	 * Physical blocks per logical block, 0's based. Is it possible to
> +	 * extract this information from the filesystem properties?
> +	 */
> +	const __le16 ppl0b = cpu_to_le16(0);

Maybe report the filesystem block size here?

Otherwise OK.

Reviewed-by: Martin K. Petersen <martin.petersen at oracle.com>

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 3/3] nvme: Set physical block size and optimal I/O size according to NVMe 1.4
  2019-06-17 16:12 ` [PATCH v3 3/3] nvme: Set physical block size and optimal I/O size according to NVMe 1.4 Bart Van Assche
  2019-06-18  7:51   ` Hannes Reinecke
@ 2019-06-19  4:17   ` Martin K. Petersen
  1 sibling, 0 replies; 17+ messages in thread
From: Martin K. Petersen @ 2019-06-19  4:17 UTC (permalink / raw)



Bart,

> NSFEAT bit 4 if set to 1: 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;

LGTM.

Reviewed-by: Martin K. Petersen <martin.petersen at oracle.com>

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 2/3] nvmet: Export NVMe namespace attributes
  2019-06-19  4:13   ` Martin K. Petersen
@ 2019-06-19 15:44     ` Bart Van Assche
  2019-06-21  1:56       ` Martin K. Petersen
  0 siblings, 1 reply; 17+ messages in thread
From: Bart Van Assche @ 2019-06-19 15:44 UTC (permalink / raw)


On 6/18/19 9:13 PM, Martin K. Petersen wrote:
> 
> Bart,
> 
>> +	/*
>> +	 * Physical blocks per logical block, 0's based. Is it possible to
>> +	 * extract this information from the filesystem properties?
>> +	 */
>> +	const __le16 ppl0b = cpu_to_le16(0);
> 
> Maybe report the filesystem block size here?
> 
> Otherwise OK.
> 
> Reviewed-by: Martin K. Petersen <martin.petersen at oracle.com>

Hi Martin,

Thanks for the review.

Are you perhaps referring to the parameter that can be specified as 
command-line option -b to mkfs? I'm not sure that we should report that 
size as the physical block size since that parameter can be set to a 
value that is much larger than the physical block size of the storage 
medium (in the target system). I'd like to make sure that writes with a 
size of what is reported as physical block size are atomic because that 
is what filesystems (at the initiator side) expect.

Bart.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 2/3] nvmet: Export NVMe namespace attributes
  2019-06-17 16:12 ` [PATCH v3 2/3] nvmet: Export NVMe namespace attributes Bart Van Assche
  2019-06-18  7:50   ` Hannes Reinecke
  2019-06-19  4:13   ` Martin K. Petersen
@ 2019-06-20  3:19   ` Chaitanya Kulkarni
  2 siblings, 0 replies; 17+ messages in thread
From: Chaitanya Kulkarni @ 2019-06-20  3:19 UTC (permalink / raw)


Looks good to me.

Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>

On 6/17/19 9:13 AM, Bart Van Assche wrote:
> Make the NVMe NAWUN, NAWUPF, NACWU, NPWG, NPWA, NPDG and NOWS attributes
> available to initator systems.
> 
> Cc: Keith Busch <kbusch at kernel.org>
> Cc: Sagi Grimberg <sagi at grimberg.me>
> Cc: Martin K. Petersen <martin.petersen at oracle.com>
> Cc: Hannes Reinecke <hare at suse.com>
> Cc: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
> Signed-off-by: Bart Van Assche <bvanassche at acm.org>
> ---
>   drivers/nvme/target/admin-cmd.c   |  5 ++++
>   drivers/nvme/target/io-cmd-bdev.c | 45 +++++++++++++++++++++++++++++++
>   drivers/nvme/target/io-cmd-file.c | 37 +++++++++++++++++++++++++
>   drivers/nvme/target/nvmet.h       |  2 ++
>   4 files changed, 89 insertions(+)
> 
> diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
> index 9f72d515fc4b..2558ed333d29 100644
> --- a/drivers/nvme/target/admin-cmd.c
> +++ b/drivers/nvme/target/admin-cmd.c
> @@ -442,6 +442,11 @@ static void nvmet_execute_identify_ns(struct nvmet_req *req)
>   		break;
>           }
>   
> +	if (ns->file)
> +		nvmet_file_set_limits(ns->file, id);
> +	else if (ns->bdev)
> +		nvmet_bdev_set_limits(ns->bdev, id);
> +
>   	/*
>   	 * We just provide a single LBA format that matches what the
>   	 * underlying device reports.
> diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c
> index 3efc52f9c309..5fe51e5d2f1b 100644
> --- a/drivers/nvme/target/io-cmd-bdev.c
> +++ b/drivers/nvme/target/io-cmd-bdev.c
> @@ -8,6 +8,51 @@
>   #include <linux/module.h>
>   #include "nvmet.h"
>   
> +/* Convert a 32-bit number to a 16-bit 0's based number */
> +static __le16 to0based(u32 a)
> +{
> +	return cpu_to_le16(max(1U, min(1U << 16, a)) - 1);
> +}
> +
> +void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id)
> +{
> +	const struct queue_limits *ql = &bdev_get_queue(bdev)->limits;
> +	/* Number of physical blocks per logical block. */
> +	const u32 ppl = ql->physical_block_size / ql->logical_block_size;
> +	/* Physical blocks per logical block, 0's based. */
> +	const __le16 ppl0b = to0based(ppl);
> +
> +	/*
> +	 * 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;
> +	id->nawun = ppl0b;
> +	id->nawupf = ppl0b;
> +	id->nacwu = ppl0b;
> +
> +	/*
> +	 * For NVMe 1.4 and later, 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 */
> +	id->npwg = ppl0b;
> +	/* NPWA = Namespace Preferred Write Alignment. 0's based */
> +	id->npwa = id->npwg;
> +	/* NPDG = Namespace Preferred Deallocate Granularity. 0's based */
> +	id->npdg = to0based(ql->discard_granularity / ql->logical_block_size);
> +	/* NPDG = Namespace Preferred Deallocate Alignment */
> +	id->npda = id->npdg;
> +	/* NOWS = Namespace Optimal Write Size */
> +	id->nows = to0based(ql->io_opt / ql->logical_block_size);
> +}
> +
>   int nvmet_bdev_ns_enable(struct nvmet_ns *ns)
>   {
>   	int ret;
> diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c
> index 05453f5d1448..268dfc678567 100644
> --- a/drivers/nvme/target/io-cmd-file.c
> +++ b/drivers/nvme/target/io-cmd-file.c
> @@ -13,6 +13,43 @@
>   #define NVMET_MAX_MPOOL_BVEC		16
>   #define NVMET_MIN_MPOOL_OBJ		16
>   
> +void nvmet_file_set_limits(struct file *file, struct nvme_id_ns *id)
> +{
> +	/*
> +	 * Physical blocks per logical block, 0's based. Is it possible to
> +	 * extract this information from the filesystem properties?
> +	 */
> +	const __le16 ppl0b = cpu_to_le16(0);
> +
> +	/*
> +	 * 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.
> +	 */
> +	id->nsfeat |= 1 << 1;
> +	id->nawun = ppl0b;
> +	id->nawupf = ppl0b;
> +	id->nacwu = ppl0b;
> +
> +	/*
> +	 * For NVMe 1.4 and later, 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 */
> +	id->npwg = ppl0b;
> +	/* NPWA = Namespace Preferred Write Alignment. 0's based */
> +	id->npwa = id->npwg;
> +	/* NPDG = Namespace Preferred Deallocate Granularity. 0's based */
> +	id->npdg = ppl0b;
> +	/* NPDG = Namespace Preferred Deallocate Alignment */
> +	id->npda = id->npdg;
> +	/* NOWS = Namespace Optimal Write Size */
> +	id->nows = ppl0b;
> +}
> +
>   void nvmet_file_ns_disable(struct nvmet_ns *ns)
>   {
>   	if (ns->file) {
> diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
> index c25d88fc9dec..ed0362544932 100644
> --- a/drivers/nvme/target/nvmet.h
> +++ b/drivers/nvme/target/nvmet.h
> @@ -363,6 +363,8 @@ u16 nvmet_set_feat_async_event(struct nvmet_req *req, u32 mask);
>   void nvmet_execute_async_event(struct nvmet_req *req);
>   
>   u16 nvmet_parse_connect_cmd(struct nvmet_req *req);
> +void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id);
> +void nvmet_file_set_limits(struct file *file, struct nvme_id_ns *id);
>   u16 nvmet_bdev_parse_io_cmd(struct nvmet_req *req);
>   u16 nvmet_file_parse_io_cmd(struct nvmet_req *req);
>   u16 nvmet_parse_admin_cmd(struct nvmet_req *req);
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 2/3] nvmet: Export NVMe namespace attributes
  2019-06-19 15:44     ` Bart Van Assche
@ 2019-06-21  1:56       ` Martin K. Petersen
  2019-06-21 15:19         ` Bart Van Assche
  0 siblings, 1 reply; 17+ messages in thread
From: Martin K. Petersen @ 2019-06-21  1:56 UTC (permalink / raw)



Bart,

> Are you perhaps referring to the parameter that can be specified as
> command-line option -b to mkfs? I'm not sure that we should report
> that size as the physical block size since that parameter can be set
> to a value that is much larger than the physical block size of the
> storage medium (in the target system).

An admin can create all sorts of weird configurations by twiddling
options. But trying to match the physical block size is one of the
heuristics for mkfs.

Also, I haven't actually looked at the code, but what happens with the
buffered I/O backend?

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 2/3] nvmet: Export NVMe namespace attributes
  2019-06-21  1:56       ` Martin K. Petersen
@ 2019-06-21 15:19         ` Bart Van Assche
  2019-06-24 23:30           ` Martin K. Petersen
  0 siblings, 1 reply; 17+ messages in thread
From: Bart Van Assche @ 2019-06-21 15:19 UTC (permalink / raw)


On 6/20/19 6:56 PM, Martin K. Petersen wrote:
> Also, I haven't actually looked at the code, but what happens with the
> buffered I/O backend?

Hi Martin,

The NVMe target code supports two types of backends: "bdev" and "file". 
The file backend code does not set the IOCB_DIRECT flag. So I assume 
that "buffered I/O backend" refers to the file backend? As you must have 
noticed the patch at the start of this thread touches both the bdev and 
the file backends. So I'm not sure what your question is about?

Bart.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 2/3] nvmet: Export NVMe namespace attributes
  2019-06-21 15:19         ` Bart Van Assche
@ 2019-06-24 23:30           ` Martin K. Petersen
  2019-06-24 23:51             ` Bart Van Assche
  0 siblings, 1 reply; 17+ messages in thread
From: Martin K. Petersen @ 2019-06-24 23:30 UTC (permalink / raw)



Hi Bart,

> As you must have noticed the patch at the start of this thread touches
> both the bdev and the file backends. So I'm not sure what your
> question is about?

I was contemplating what the observed I/O atomicity would be for the
initiator side when the target file backend is using buffered I/O.

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 2/3] nvmet: Export NVMe namespace attributes
  2019-06-24 23:30           ` Martin K. Petersen
@ 2019-06-24 23:51             ` Bart Van Assche
  0 siblings, 0 replies; 17+ messages in thread
From: Bart Van Assche @ 2019-06-24 23:51 UTC (permalink / raw)


On 6/24/19 4:30 PM, Martin K. Petersen wrote:
> 
> Hi Bart,
> 
>> As you must have noticed the patch at the start of this thread touches
>> both the bdev and the file backends. So I'm not sure what your
>> question is about?
> 
> I was contemplating what the observed I/O atomicity would be for the
> initiator side when the target file backend is using buffered I/O.

Hi Martin,

My understanding is that after a completion has been reported for an 
atomic NVMe write that the written data must survive a power cycle. As 
you probably know all single logical block NVMe writes are atomic since 
the AWUPF field is 0's based. So I don't think that it is possible to 
implement a backend that uses buffered I/O in such a way that the 
backend is NVMe compliant without using an uninterruptible power supply.

Bart.

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2019-06-24 23:51 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-17 16:12 [PATCH v3 0/3] NVMe 1.4 Identify Namespace Support Bart Van Assche
2019-06-17 16:12 ` [PATCH v3 1/3] nvme: Introduce NVMe 1.4 Identify Namespace fields in struct nvme_id_ns Bart Van Assche
2019-06-18  7:49   ` Hannes Reinecke
2019-06-17 16:12 ` [PATCH v3 2/3] nvmet: Export NVMe namespace attributes Bart Van Assche
2019-06-18  7:50   ` Hannes Reinecke
2019-06-19  4:13   ` Martin K. Petersen
2019-06-19 15:44     ` Bart Van Assche
2019-06-21  1:56       ` Martin K. Petersen
2019-06-21 15:19         ` Bart Van Assche
2019-06-24 23:30           ` Martin K. Petersen
2019-06-24 23:51             ` Bart Van Assche
2019-06-20  3:19   ` Chaitanya Kulkarni
2019-06-17 16:12 ` [PATCH v3 3/3] nvme: Set physical block size and optimal I/O size according to NVMe 1.4 Bart Van Assche
2019-06-18  7:51   ` Hannes Reinecke
2019-06-19  4:17   ` Martin K. Petersen
2019-06-18  7:52 ` [PATCH v3 0/3] NVMe 1.4 Identify Namespace Support Hannes Reinecke
2019-06-18 20:34   ` Bart Van Assche

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.