Skip to contentSkip to conversation

Support for Open-Channel SSDs

PATCH Superseded Matias Bjørling 4 participants 22 messages Jun 5, 2015 – Jul 16, 2015

Subsystems (4)

v4 of 14 Superseded Latest is v14 →

lore
Share & tools
lore
#0 lore raw

v4 cover Support for Open-Channel SSDs

Hi,

This is an updated version based on the feedback from Christoph.

Patch 1-2 are fixes and preparation for the nvme driver. The first fixes a flag bug. The second allows rq->special in nvme_submit_sync_cmd to be set and used.
Patch 3 fixes capacity reporting in null_blk.
Patch 4-8 introduces LightNVM and a simple target.

Jens, the patches are on top of your for-next tree.

Development and further information on LightNVM can be found at:

https://github.com/OpenChannelSSD/linux

Changes since v3:

- Remove dependence on REQ_NVM_GC
- Refactor nvme integration to use nvme_submit_sync_cmd for internal commands.
- Fix race condition bug on multiple threads on RRPC target.
- Rename sysfs entry under the block device from nvm to lightnvm. The configuration is found in /sys/block/*/lightnvm/

Changes since v2:

Feedback from Paul Bolle:
- Fix license to GPLv2, documentation, compilation. Feedback from Keith Busch:
- nvme: Move lightnvm out and into nvme-lightnvm.c.
- nvme: Set controller css on lightnvm command set.
- nvme: Remove OACS.
Feedback from Christoph Hellwig:
- lightnvm: Move out of block layer into /drivers/lightnvm/core.c
- lightnvm: refactor request->phys_sector into device drivers.
- lightnvm: refactor prep/unprep into device drivers.
- lightnvm: move nvm_dev from request_queue to gendisk.

New
- Bad block table support (From Javier).
- Update maintainers file.

Changes since v1:

- Splitted LightNVM into two parts. A get/put interface for flash blocks and the respective targets that implement flash translation layer logic.
- Updated the patches according to the LightNVM specification changes.
- Added interface to add/remove targets for a block device.

Matias Bj?rling (8):
nvme: add special param for nvme_submit_sync_cmd
nvme: don't overwrite req->cmd_flags on sync cmd
null_blk: wrong capacity when bs is not 512 bytes
bio: Introduce LightNVM payload
lightnvm: Support for Open-Channel SSDs
lightnvm: RRPC target
null_blk: LightNVM support
nvme: LightNVM support

 Documentation/block/null_blk.txt |    8 +
 MAINTAINERS                      |    9 +
 drivers/Kconfig                  |    2 +
 drivers/Makefile                 |    2 +
 drivers/block/Makefile           |    2 +-
 drivers/block/null_blk.c         |  136 ++++-
 drivers/block/nvme-core.c        |  134 ++++-
 drivers/block/nvme-lightnvm.c    |  320 +++++++++++
 drivers/block/nvme-scsi.c        |    4 +-
 drivers/lightnvm/Kconfig         |   26 +
 drivers/lightnvm/Makefile        |    6 +
 drivers/lightnvm/core.c          |  833 +++++++++++++++++++++++++++++
 drivers/lightnvm/rrpc.c          | 1088 ++++++++++++++++++++++++++++++++++++++
 drivers/lightnvm/rrpc.h          |  221 ++++++++
 include/linux/bio.h              |    9 +
 include/linux/blk_types.h        |    4 +-
 include/linux/blkdev.h           |    2 +
 include/linux/genhd.h            |    3 +
 include/linux/lightnvm.h         |  379 +++++++++++++
 include/linux/nvme.h             |   11 +-
 include/uapi/linux/nvme.h        |  131 +++++
 21 files changed, 3300 insertions(+), 30 deletions(-)
 create mode 100644 drivers/block/nvme-lightnvm.c
 create mode 100644 drivers/lightnvm/Kconfig
 create mode 100644 drivers/lightnvm/Makefile
 create mode 100644 drivers/lightnvm/core.c
 create mode 100644 drivers/lightnvm/rrpc.c
 create mode 100644 drivers/lightnvm/rrpc.h
 create mode 100644 include/linux/lightnvm.h
Signature · 1 line
2.1.4
#1 lore raw

PATCH v4 1/8 nvme: add special param for nvme_submit_sync_cmd

In preparation for LightNVM, it requires a hook for internal commands to resolve its state on command completion. Use req->special for this and move the command result to req->sense.

---
 drivers/block/nvme-core.c | 19 ++++++++++---------
 drivers/block/nvme-scsi.c |  4 ++--
 include/linux/nvme.h      |  2 +-
 3 files changed, 13 insertions(+), 12 deletions(-)
drivers/block/nvme-core.c +10 -9
index 6ed1356..d2955fe 100644
@@ -614,7 +614,7 @@ static void req_completion(struct nvme_queue *nvmeq, void *ctx,
 		req->errors = 0;
 	if (req->cmd_type == REQ_TYPE_DRV_PRIV) {
 		u32 result = le32_to_cpup(&cqe->result);
-		req->special = (void *)(uintptr_t)result;
+		req->sense = (void *)(uintptr_t)result;
 	}
 
 	if (cmd_rq->aborted)
@@ -998,7 +998,7 @@ static irqreturn_t nvme_irq_check(int irq, void *data)
  */
 int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
 		void *buffer, void __user *ubuffer, unsigned bufflen,
-		u32 *result, unsigned timeout)
+		u32 *result, unsigned timeout, void *special)
 {
 	bool write = cmd->common.opcode & 1;
 	struct bio *bio = NULL;
@@ -1019,7 +1019,7 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
 
 	req->cmd = (unsigned char *)cmd;
 	req->cmd_len = sizeof(struct nvme_command);
-	req->special = (void *)0;
+	req->special = special;
 
 	if (buffer && bufflen) {
 		ret = blk_rq_map_kern(q, req, buffer, bufflen, __GFP_WAIT);
@@ -1036,7 +1036,7 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
 	if (bio)
 		blk_rq_unmap_user(bio);
 	if (result)
-		*result = (u32)(uintptr_t)req->special;
+		*result = (u32)(uintptr_t)req->sense;
 	ret = req->errors;
  out:
 	blk_mq_free_request(req);
@@ -1046,7 +1046,8 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
 int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
 		void *buffer, unsigned bufflen)
 {
-	return __nvme_submit_sync_cmd(q, cmd, buffer, NULL, bufflen, NULL, 0);
+	return __nvme_submit_sync_cmd(q, cmd, buffer, NULL, bufflen, NULL, 0,
+									NULL);
 }
 
 static int nvme_submit_async_admin_req(struct nvme_dev *dev)
@@ -1209,7 +1210,7 @@ int nvme_get_features(struct nvme_dev *dev, unsigned fid, unsigned nsid,
 	c.features.fid = cpu_to_le32(fid);
 
 	return __nvme_submit_sync_cmd(dev->admin_q, &c, NULL, NULL, 0,
-			result, 0);
+			result, 0, NULL);
 }
 
 int nvme_set_features(struct nvme_dev *dev, unsigned fid, unsigned dword11,
@@ -1224,7 +1225,7 @@ int nvme_set_features(struct nvme_dev *dev, unsigned fid, unsigned dword11,
 	c.features.dword11 = cpu_to_le32(dword11);
 
 	return __nvme_submit_sync_cmd(dev->admin_q, &c, NULL, NULL, 0,
-			result, 0);
+			result, 0, NULL);
 }
 
 int nvme_get_log_page(struct nvme_dev *dev, struct nvme_smart_log **log)
@@ -1787,7 +1788,7 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
 	c.rw.metadata = cpu_to_le64(meta_dma);
 
 	status = __nvme_submit_sync_cmd(ns->queue, &c, NULL,
-			(void __user *)io.addr, length, NULL, 0);
+			(void __user *)io.addr, length, NULL, 0, NULL);
  unmap:
 	if (meta) {
 		if (status == NVME_SC_SUCCESS && !write) {
@@ -1831,7 +1832,7 @@ static int nvme_user_cmd(struct nvme_dev *dev, struct nvme_ns *ns,
 
 	status = __nvme_submit_sync_cmd(ns ? ns->queue : dev->admin_q, &c,
 			NULL, (void __user *)cmd.addr, cmd.data_len,
-			&cmd.result, timeout);
+			&cmd.result, timeout, NULL);
 	if (status >= 0) {
 		if (put_user(cmd.result, &ucmd->result))
 			return -EFAULT;
drivers/block/nvme-scsi.c +2 -2
index 8e6223e..ad35bb7 100644
@@ -1297,7 +1297,7 @@ static int nvme_trans_send_download_fw_cmd(struct nvme_ns *ns, struct sg_io_hdr
 	c.dlfw.offset = cpu_to_le32(offset/BYTES_TO_DWORDS);
 
 	nvme_sc = __nvme_submit_sync_cmd(dev->admin_q, &c, NULL,
-			hdr->dxferp, tot_len, NULL, 0);
+			hdr->dxferp, tot_len, NULL, 0, NULL);
 	return nvme_trans_status_code(hdr, nvme_sc);
 }
 
@@ -1704,7 +1704,7 @@ static int nvme_trans_do_nvme_io(struct nvme_ns *ns, struct sg_io_hdr *hdr,
 			break;
 		}
 		nvme_sc = __nvme_submit_sync_cmd(ns->queue, &c, NULL,
-				next_mapping_addr, unit_len, NULL, 0);
+				next_mapping_addr, unit_len, NULL, 0, NULL);
 		if (nvme_sc)
 			break;
 
include/linux/nvme.h +1 -1
index 986bf8a..fce2090 100644
@@ -150,7 +150,7 @@ int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
 		void *buf, unsigned bufflen);
 int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
 		void *buffer, void __user *ubuffer, unsigned bufflen,
-		u32 *result, unsigned timeout);
+		u32 *result, unsigned timeout, void *special);
 int nvme_identify_ctrl(struct nvme_dev *dev, struct nvme_id_ctrl **id);
 int nvme_identify_ns(struct nvme_dev *dev, unsigned nsid,
 		struct nvme_id_ns **id);
Signature · 1 line
2.1.4
#2 lore raw

PATCH v4 2/8 nvme: don't overwrite req->cmd_flags on sync cmd

In reply to Matias Bjørling

In __nvme_submit_sync_cmd, the request direction is overwritten when the REQ_FAILFAST_DRIVER flag is set.

---
 drivers/block/nvme-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/nvme-core.c +1 -1
index d2955fe..6e433b1 100644
@@ -1010,7 +1010,7 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
 		return PTR_ERR(req);
 
 	req->cmd_type = REQ_TYPE_DRV_PRIV;
-	req->cmd_flags = REQ_FAILFAST_DRIVER;
+	req->cmd_flags |= REQ_FAILFAST_DRIVER;
 	req->__data_len = 0;
 	req->__sector = (sector_t) -1;
 	req->bio = req->biotail = NULL;
Signature · 1 line
2.1.4
Reviewed-by on v4 2/8
#3 lore raw

Re: [PATCH v4 2/8] nvme: don't overwrite req->cmd_flags on sync cmd

Quoted 2 lines · Matias Bj??rling

In __nvme_submit_sync_cmd, the request direction is overwritten when the REQ_FAILFAST_DRIVER flag is set.

Looks good,

Reviewed-by Christoph Hellwig <hch at lst.de>

This is a fix for a last minute regression and needs to got into the drivers/for-4.2 tree ASAP.

#4 lore raw

PATCH v4 3/8 null_blk: wrong capacity when bs is not 512 bytes

In reply to Matias Bjørling

set_capacity() sets device capacity by the number of 512 bytes sectors. null_blk calculates the number of sectors by size / bs and calls set_capacity. This leads to the wrong number of sectors when bs is not 512 bytes.

---
 drivers/block/null_blk.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/block/null_blk.c +1 -2
index 65cd61a..79972ab 100644
@@ -576,8 +576,7 @@ static int null_add_dev(void)
 	blk_queue_physical_block_size(nullb->q, bs);
 
 	size = gb * 1024 * 1024 * 1024ULL;
-	sector_div(size, bs);
-	set_capacity(disk, size);
+	set_capacity(disk, size >> 9);
 
 	disk->flags |= GENHD_FL_EXT_DEVT | GENHD_FL_SUPPRESS_PARTITION_INFO;
 	disk->major		= null_major;
Signature · 1 line
2.1.4
#5 lore raw

PATCH v4 4/8 bio: Introduce LightNVM payload

In reply to Matias Bjørling

LightNVM integrates on both sides of the block layer. The lower layer implements mapping of logical to physical addressing, while the layer above can string together multiple LightNVM devices and expose them as a single block device.

Having multiple devices underneath requires a way to resolve where the IO came from when submitted through the block layer. Extending bio with a LightNVM payload solves this problem.

---
 include/linux/bio.h       | 9 +++++++++
 include/linux/blk_types.h | 4 +++-
 2 files changed, 12 insertions(+), 1 deletion(-)
include/linux/bio.h +9 -0
index f0291cf..1fe490e 100644
@@ -368,6 +368,15 @@ static inline void bip_set_seed(struct bio_integrity_payload *bip,
 
 #endif /* CONFIG_BLK_DEV_INTEGRITY */
 
+#if defined(CONFIG_NVM)
+
+/* bio open-channel ssd payload */
+struct bio_nvm_payload {
+	void *private;
+};
+
+#endif /* CONFIG_NVM */
+
 extern void bio_trim(struct bio *bio, int offset, int size);
 extern struct bio *bio_split(struct bio *bio, int sectors,
 			     gfp_t gfp, struct bio_set *bs);
include/linux/blk_types.h +3 -1
index 45a6be8..41d9ba1 100644
@@ -83,7 +83,9 @@ struct bio {
 		struct bio_integrity_payload *bi_integrity; /* data integrity */
 #endif
 	};
-
+#if defined(CONFIG_NVM)
+	struct bio_nvm_payload *bi_nvm; /* open-channel ssd backend */
+#endif
 	unsigned short		bi_vcnt;	/* how many bio_vec's */
 
 	/*
Signature · 1 line
2.1.4
#6 lore raw

Re: [PATCH v4 4/8] bio: Introduce LightNVM payload

include/linux/blk_types.h struct bio { · line 89

Quoted 6 lines
include/linux/blk_types.h +3 -1
-
+#if defined(CONFIG_NVM)
+	struct bio_nvm_payload *bi_nvm; /* open-channel ssd backend */
+#endif
  	unsigned short		bi_vcnt;	/* how many bio_vec's */

Jens suggests this to implemented using a bio clone. Will do in the next refresh.

#7 lore raw

Re: [PATCH v4 4/8] bio: Introduce LightNVM payload

Quoted 9 lines · Matias Bjorling

include/linux/blk_types.h struct bio { · line 89

Quoted 6 lines
include/linux/blk_types.h +3 -1
-
+#if defined(CONFIG_NVM)
+	struct bio_nvm_payload *bi_nvm; /* open-channel ssd backend */
+#endif
 	unsigned short		bi_vcnt;	/* how many bio_vec's */

Jens suggests this to implemented using a bio clone. Will do in the next refresh.

And I'd spell OpenChannel SSD the way you do in changelogs... for consistency.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#8 lore raw

PATCH v4 5/8 lightnvm: Support for Open-Channel SSDs

In reply to Matias Bjørling

Open-channel SSDs are devices that share responsibilities with the host in order to implement and maintain features that typical SSDs keep strictly in firmware. These include (i) the Flash Translation Layer (FTL), (ii) bad block management, and (iii) hardware units such as the flash controller, the interface controller, and large amounts of flash chips. In this way, Open-channels SSDs exposes direct access to their physical flash storage, while keeping a subset of the internal features of SSDs.

LightNVM is a specification that gives support to Open-channel SSDs LightNVM allows the host to manage data placement, garbage collection, and parallelism. Device specific responsibilities such as bad block management, FTL extensions to support atomic IOs, or metadata persistence are still handled by the device.

The implementation of LightNVM consists of two parts: core and (multiple) targets. The core implements functionality shared across targets. This is initialization, teardown and statistics. The targets implement the interface that exposes physical flash to user-space applications. Examples of such targets include key-value store, object-store, as well as traditional block devices, which can be application-specific.

Contributions in this patch from:

Javier Gonzalez <[email protected]>
Jesper Madsen <[email protected]>

---
 MAINTAINERS               |   9 +
 drivers/Kconfig           |   2 +
 drivers/Makefile          |   2 +
 drivers/lightnvm/Kconfig  |  16 +
 drivers/lightnvm/Makefile |   5 +
 drivers/lightnvm/core.c   | 833 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/genhd.h     |   3 +
 include/linux/lightnvm.h  | 379 +++++++++++++++++++++
 8 files changed, 1249 insertions(+)
 create mode 100644 drivers/lightnvm/Kconfig
 create mode 100644 drivers/lightnvm/Makefile
 create mode 100644 drivers/lightnvm/core.c
 create mode 100644 include/linux/lightnvm.h
MAINTAINERS +9 -0
index 781e099..c4119c4 100644
@@ -5903,6 +5903,15 @@ M:	Sasha Levin <[email protected]>
 S:	Maintained
 F:	tools/lib/lockdep/
 
+LIGHTNVM PLATFORM SUPPORT
+M:	Matias Bjorling <[email protected]>
+M:	Javier Gonzalez <[email protected]>
+W:	http://github/OpenChannelSSD
+S:	Maintained
+F:	drivers/lightnvm/
+F:	include/linux/lightnvm.h
+F:	include/uapi/linux/lightnvm.h
+
 LINUX FOR IBM pSERIES (RS/6000)
 M:	Paul Mackerras <[email protected]>
 W:	http://www.ibm.com/linux/ltc/projects/ppc
drivers/Kconfig +2 -0
index c0cc96b..da47047 100644
@@ -42,6 +42,8 @@ source "drivers/net/Kconfig"
 
 source "drivers/isdn/Kconfig"
 
+source "drivers/lightnvm/Kconfig"
+
 # input before char - char/joystick depends on it. As does USB.
 
 source "drivers/input/Kconfig"
drivers/Makefile +2 -0
index 46d2554..2629be2 100644
@@ -165,3 +165,5 @@ obj-$(CONFIG_RAS)		+= ras/
 obj-$(CONFIG_THUNDERBOLT)	+= thunderbolt/
 obj-$(CONFIG_CORESIGHT)		+= hwtracing/coresight/
 obj-$(CONFIG_ANDROID)		+= android/
+
+obj-$(CONFIG_NVM)		+= lightnvm/
drivers/lightnvm/Kconfig new file +16 -0
new file mode 100644
index 0000000..1f8412c
@@ -0,0 +1,16 @@
+#
+# Open-Channel SSD NVM configuration
+#
+
+menuconfig NVM
+	bool "Open-Channel SSD target support"
+	depends on BLOCK
+	help
+	  Say Y here to get to enable Open-channel SSDs.
+
+	  Open-Channel SSDs implement a set of extension to SSDs, that
+	  exposes direct access to the underlying non-volatile memory.
+
+	  If you say N, all options in this submenu will be skipped and disabled
+	  only do this if you know what you are doing.
+
drivers/lightnvm/Makefile new file +5 -0
new file mode 100644
index 0000000..38185e9
@@ -0,0 +1,5 @@
+#
+# Makefile for Open-Channel SSDs.
+#
+
+obj-$(CONFIG_NVM)		:= core.o
drivers/lightnvm/core.c new file +833 -0

833 lines not on this page · raw message

include/linux/genhd.h +3 -0
index ec274e0..7d7442e 100644
@@ -199,6 +199,9 @@ struct gendisk {
 #ifdef  CONFIG_BLK_DEV_INTEGRITY
 	struct blk_integrity *integrity;
 #endif
+#ifdef CONFIG_NVM
+	struct nvm_dev *nvm;
+#endif
 	int node_id;
 };
 
include/linux/lightnvm.h new file +379 -0

379 lines not on this page · raw message

Signature · 1 line
2.1.4
#9 lore raw

PATCH v4 6/8 lightnvm: RRPC target

In reply to Matias Bjørling

This target implements a simple strategy FTL for Open-Channel SSDs. It does round-robin selection across channels and lunis. It uses a simple greedy cost-based garbage collector and exposes the physical flash as a block device.

Signed-off-by Javier Gonz?lez <jg at lightnvm.io>
Signed-off-by Matias Bj?rling <m at bjorling.me>
---
 drivers/lightnvm/Kconfig  |   10 +
 drivers/lightnvm/Makefile |    1 +
 drivers/lightnvm/rrpc.c   | 1088 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/lightnvm/rrpc.h   |  221 +++++++++
 include/linux/blkdev.h    |    2 +
 5 files changed, 1322 insertions(+)
 create mode 100644 drivers/lightnvm/rrpc.c
 create mode 100644 drivers/lightnvm/rrpc.h
drivers/lightnvm/Kconfig +10 -0
index 1f8412c..1773891 100644
@@ -14,3 +14,13 @@ menuconfig NVM
 	  If you say N, all options in this submenu will be skipped and disabled
 	  only do this if you know what you are doing.
 
+if NVM
+
+config NVM_RRPC
+	tristate "Round-robin Hybrid Open-Channel SSD"
+	---help---
+	Allows an open-channel SSD to be exposed as a block device to the
+	host. The target is implemented using a linear mapping table and
+	cost-based garbage collection. It is optimized for 4K IO sizes.
+
+endif # NVM
drivers/lightnvm/Makefile +1 -0
index 38185e9..b2a39e2 100644
@@ -3,3 +3,4 @@
 #
 
 obj-$(CONFIG_NVM)		:= core.o
+obj-$(CONFIG_NVM_RRPC)		+= rrpc.o
drivers/lightnvm/rrpc.c new file +1088 -0

1,088 lines not on this page · raw message

drivers/lightnvm/rrpc.h new file +221 -0

221 lines not on this page · raw message

include/linux/blkdev.h +2 -0
index 0283c7e..5635940 100644
@@ -1471,6 +1471,8 @@ extern bool blk_integrity_merge_bio(struct request_queue *, struct request *,
 static inline
 struct blk_integrity *bdev_get_integrity(struct block_device *bdev)
 {
+	if (unlikely(!bdev))
+		return NULL;
 	return bdev->bd_disk->integrity;
 }
 
Signature · 1 line
2.1.4
#10 lore raw

PATCH v4 7/8 null_blk: LightNVM support

In reply to Matias Bjørling

Initial support for LightNVM. The support can be used to benchmark performance of targets and core implementation.

---
 Documentation/block/null_blk.txt |   8 +++
 drivers/block/null_blk.c         | 133 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 138 insertions(+), 3 deletions(-)
Documentation/block/null_blk.txt +8 -0
index 2f6c6ff..a34f50a 100644
@@ -70,3 +70,11 @@ use_per_node_hctx=[0/1]: Default: 0
      parameter.
   1: The multi-queue block layer is instantiated with a hardware dispatch
      queue for each CPU node in the system.
+
+IV: LightNVM specific parameters
+
+nvm_enable=[x]: Default: 0
+  Enable LightNVM for null block devices. Requires blk-mq to be used.
+
+nvm_num_channels=[x]: Default: 1
+  Number of LightNVM channels that is exposed to the LightNVM driver.
drivers/block/null_blk.c +130 -3

210 lines not on this page · raw message

Signature · 1 line
2.1.4
#11 lore raw

PATCH v4 8/8 nvme: LightNVM support

In reply to Matias Bjørling

The first generation of Open-Channel SSDs will be based on NVMe. The integration requires that a NVMe device exposes itself as a LightNVM device. The way this is done currently is by hooking into the Controller Capabilities (CAP register) and a bit in NSFEAT for each namespace.

After detection, vendor specific codes are used to identify the device and enumerate supported features.

---
 drivers/block/Makefile        |   2 +-
 drivers/block/nvme-core.c     | 113 +++++++++++++--
 drivers/block/nvme-lightnvm.c | 320 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/nvme.h          |   9 ++
 include/uapi/linux/nvme.h     | 131 +++++++++++++++++
 5 files changed, 564 insertions(+), 11 deletions(-)
 create mode 100644 drivers/block/nvme-lightnvm.c
drivers/block/Makefile +1 -1
index 9cc6c18..37f7b3b 100644
@@ -45,6 +45,6 @@ obj-$(CONFIG_BLK_DEV_RSXX) += rsxx/
 obj-$(CONFIG_BLK_DEV_NULL_BLK)	+= null_blk.o
 obj-$(CONFIG_ZRAM) += zram/
 
-nvme-y		:= nvme-core.o nvme-scsi.o
+nvme-y		:= nvme-core.o nvme-scsi.o nvme-lightnvm.o
 skd-y		:= skd_main.o
 swim_mod-y	:= swim.o swim_asm.o
drivers/block/nvme-core.c +103 -10

229 lines not on this page · raw message

drivers/block/nvme-lightnvm.c new file +320 -0

320 lines not on this page · raw message

include/linux/nvme.h +9 -0
index fce2090..8fbc7bf 100644
@@ -19,6 +19,7 @@
 #include <linux/pci.h>
 #include <linux/kref.h>
 #include <linux/blk-mq.h>
+#include <linux/lightnvm.h>
 
 struct nvme_bar {
 	__u64			cap;	/* Controller Capabilities */
@@ -39,10 +40,12 @@ struct nvme_bar {
 #define NVME_CAP_STRIDE(cap)	(((cap) >> 32) & 0xf)
 #define NVME_CAP_MPSMIN(cap)	(((cap) >> 48) & 0xf)
 #define NVME_CAP_MPSMAX(cap)	(((cap) >> 52) & 0xf)
+#define NVME_CAP_LIGHTNVM(cap)	(((cap) >> 38) & 0x1)
 
 enum {
 	NVME_CC_ENABLE		= 1 << 0,
 	NVME_CC_CSS_NVM		= 0 << 4,
+	NVME_CC_CSS_LIGHTNVM	= 1 << 4,
 	NVME_CC_MPS_SHIFT	= 7,
 	NVME_CC_ARB_RR		= 0 << 11,
 	NVME_CC_ARB_WRRU	= 1 << 11,
@@ -120,6 +123,7 @@ struct nvme_ns {
 	u16 ms;
 	bool ext;
 	u8 pi_type;
+	int type;
 	u64 mode_select_num_blocks;
 	u32 mode_select_block_len;
 };
@@ -137,6 +141,7 @@ struct nvme_iod {
 	int nents;		/* Used in scatterlist */
 	int length;		/* Of data, in bytes */
 	dma_addr_t first_dma;
+	struct nvm_rq_data nvm_rqdata; /* Physical sectors description of the I/O */
 	struct scatterlist meta_sg[1]; /* metadata requires single contiguous buffer */
 	struct scatterlist sg[0];
 };
@@ -166,4 +171,8 @@ int nvme_sg_io(struct nvme_ns *ns, struct sg_io_hdr __user *u_hdr);
 int nvme_sg_io32(struct nvme_ns *ns, unsigned long arg);
 int nvme_sg_get_version_num(int __user *ip);
 
+int nvme_nvm_register(struct request_queue *q, struct gendisk *disk);
+int nvme_nvm_prep_internal_rq(struct request *rq, struct nvme_ns *ns,
+				struct nvme_command *c, struct nvme_iod *iod);
+
 #endif /* _LINUX_NVME_H */
include/uapi/linux/nvme.h +131 -0

179 lines not on this page · raw message

Signature · 1 line
2.1.4
Tested-by on the v4 series
#12 lore raw
In reply to Matias Bjørling

Hi

I have tested this patchset using fio and a simple script that is available at the URL below. Note testing was performed in a QEMU environment and not on real lightnvm block IO devices.

https://github.com/OpenChannelSSD/lightnvm-hw

(see the sanity.sh script in the sanity sub-folder).

Tested-by Stephen Bates <stephen.bates at pmcs.com>

Cheers

Stephen

-----Original Message-----
From: Matias Bj?rling [mailto:[email protected]]
Sent: Friday, June 5, 2015 6:54 AM
To: hch at infradead.org; axboe at fb.com; linux-fsdevel at vger.kernel.org; linux-kernel at vger.kernel.org; linux-nvme at lists.infradead.org
Cc: javier at lightnvm.io; Stephen Bates; keith.busch at intel.com; Matias Bj?rling
Subject: [PATCH v4 0/8] Support for Open-Channel SSDs

Hi,

This is an updated version based on the feedback from Christoph.

Patch 1-2 are fixes and preparation for the nvme driver. The first fixes a flag bug. The second allows rq->special in nvme_submit_sync_cmd to be set and used. Patch 3 fixes capacity reporting in null_blk.
Patch 4-8 introduces LightNVM and a simple target.

Jens, the patches are on top of your for-next tree.

Development and further information on LightNVM can be found at:

https://github.com/OpenChannelSSD/linux

Changes since v3:

- Remove dependence on REQ_NVM_GC
- Refactor nvme integration to use nvme_submit_sync_cmd for internal commands.
- Fix race condition bug on multiple threads on RRPC target.
- Rename sysfs entry under the block device from nvm to lightnvm. The configuration is found in /sys/block/*/lightnvm/

Changes since v2:

Feedback from Paul Bolle:
- Fix license to GPLv2, documentation, compilation. Feedback from Keith Busch:
- nvme: Move lightnvm out and into nvme-lightnvm.c.
- nvme: Set controller css on lightnvm command set.
- nvme: Remove OACS.
Feedback from Christoph Hellwig:
- lightnvm: Move out of block layer into /drivers/lightnvm/core.c
- lightnvm: refactor request->phys_sector into device drivers.
- lightnvm: refactor prep/unprep into device drivers.
- lightnvm: move nvm_dev from request_queue to gendisk.

New
- Bad block table support (From Javier).
- Update maintainers file.

Changes since v1:

- Splitted LightNVM into two parts. A get/put interface for flash blocks and the respective targets that implement flash translation layer logic.
- Updated the patches according to the LightNVM specification changes.
- Added interface to add/remove targets for a block device.

Matias Bj?rling (8):
nvme: add special param for nvme_submit_sync_cmd
nvme: don't overwrite req->cmd_flags on sync cmd
null_blk: wrong capacity when bs is not 512 bytes
bio: Introduce LightNVM payload
lightnvm: Support for Open-Channel SSDs
lightnvm: RRPC target
null_blk: LightNVM support
nvme: LightNVM support

 Documentation/block/null_blk.txt |    8 +
 MAINTAINERS                      |    9 +
 drivers/Kconfig                  |    2 +
 drivers/Makefile                 |    2 +
 drivers/block/Makefile           |    2 +-
 drivers/block/null_blk.c         |  136 ++++-
 drivers/block/nvme-core.c        |  134 ++++-
 drivers/block/nvme-lightnvm.c    |  320 +++++++++++
 drivers/block/nvme-scsi.c        |    4 +-
 drivers/lightnvm/Kconfig         |   26 +
 drivers/lightnvm/Makefile        |    6 +
 drivers/lightnvm/core.c          |  833 +++++++++++++++++++++++++++++
 drivers/lightnvm/rrpc.c          | 1088 ++++++++++++++++++++++++++++++++++++++
 drivers/lightnvm/rrpc.h          |  221 ++++++++
 include/linux/bio.h              |    9 +
 include/linux/blk_types.h        |    4 +-
 include/linux/blkdev.h           |    2 +
 include/linux/genhd.h            |    3 +
 include/linux/lightnvm.h         |  379 +++++++++++++
 include/linux/nvme.h             |   11 +-
 include/uapi/linux/nvme.h        |  131 +++++
 21 files changed, 3300 insertions(+), 30 deletions(-)  create mode 100644 drivers/block/nvme-lightnvm.c  create mode 100644 drivers/lightnvm/Kconfig  create mode 100644 drivers/lightnvm/Makefile  create mode 100644 drivers/lightnvm/core.c  create mode 100644 drivers/lightnvm/rrpc.c  create mode 100644 drivers/lightnvm/rrpc.h  create mode 100644 include/linux/lightnvm.h

--
2.1.4

#13 lore raw
In reply to Matias Bjørling

Hi Matias,

I've been looking over this and I really think it needs a fundamental rearchitecture still. The design of using a separate stacking block device and all kinds of private hooks does not look very maintainable.

Here is my counter suggestion:

- the stacking block device goes away
- the nvm_target_type make_rq and prep_rq callbacks are combined into one and called from the nvme/null_blk ->queue_rq method early on to prepare the FTL state. The drivers that are LightNVM enabled reserve a pointer to it in their per request data, which the unprep_rq callback is called on durign I/O completion.

#14 lore raw
Quoted 7 lines · Christoph Hellwig

Hi Matias,

I've been looking over this and I really think it needs a fundamental rearchitecture still. The design of using a separate stacking block device and all kinds of private hooks does not look very maintainable.

Quoted 9 lines

Here is my counter suggestion:

- the stacking block device goes away
- the nvm_target_type make_rq and prep_rq callbacks are combined into one and called from the nvme/null_blk ->queue_rq method early on to prepare the FTL state. The drivers that are LightNVM enabled reserve a pointer to it in their per request data, which the unprep_rq callback is called on durign I/O completion.

I agree with this, if it only was a common FTL that would be implemented. This is maybe where we start, but what I really want to enable is these two use-cases:

1. A get/put flash block API, that user-space applications can use. That will enable application-driven FTLs. E.g. RocksDB can be integrated tightly with the SSD. Allowing data placement and garbage collection to be strictly controlled. Data placement will reduce the need for over-provisioning, as data that age at the same time are placed in the same flash block, and garbage collection can be scheduled to not interfere with user requests. Together, it will remove I/O outliers significantly.

2. Large drive arrays with global FTL. The stacking block device model enables this. It allows an FTL to span multiple devices, and thus perform data placement and garbage collection over tens to hundred of devices. That'll greatly improve wear-leveling, as there is a much higher probability of a fully inactive block with more flash. Additionally, as the parallelism grows within the storage array, we can slice and dice the devices using the get/put flash block API and enable applications to get predictable performance, while using large arrays that have a single address space.

If it too much for now to get upstream, I can live with (2) removed and then I make the changes you proposed.

What do you think?

Thanks
-Matias

#15 lore raw
Quoted 19 lines · Matias Bjorling

1. A get/put flash block API, that user-space applications can use. That will enable application-driven FTLs. E.g. RocksDB can be integrated tightly with the SSD. Allowing data placement and garbage collection to be strictly controlled. Data placement will reduce the need for over-provisioning, as data that age at the same time are placed in the same flash block, and garbage collection can be scheduled to not interfere with user requests. Together, it will remove I/O outliers significantly.

2. Large drive arrays with global FTL. The stacking block device model enables this. It allows an FTL to span multiple devices, and thus perform data placement and garbage collection over tens to hundred of devices. That'll greatly improve wear-leveling, as there is a much higher probability of a fully inactive block with more flash. Additionally, as the parallelism grows within the storage array, we can slice and dice the devices using the get/put flash block API and enable applications to get predictable performance, while using large arrays that have a single address space.

Quoted 2 lines

If it too much for now to get upstream, I can live with (2) removed and then I make the changes you proposed.

In this case your driver API really isn't the Linux block API anymore. I think the right API is a simple asynchronous submit with callback into the driver, with the block device only provided by the lightnvm layer.

Note that for NVMe it might still make sense to implement this using blk-mq and a struct request, but those should be internal similar to how NVMe implements admin commands.

#16 lore raw
Quoted 20 lines · Christoph Hellwig
Quoted 19 lines · Matias Bjorling

1. A get/put flash block API, that user-space applications can use. That will enable application-driven FTLs. E.g. RocksDB can be integrated tightly with the SSD. Allowing data placement and garbage collection to be strictly controlled. Data placement will reduce the need for over-provisioning, as data that age at the same time are placed in the same flash block, and garbage collection can be scheduled to not interfere with user requests. Together, it will remove I/O outliers significantly.

2. Large drive arrays with global FTL. The stacking block device model enables this. It allows an FTL to span multiple devices, and thus perform data placement and garbage collection over tens to hundred of devices. That'll greatly improve wear-leveling, as there is a much higher probability of a fully inactive block with more flash. Additionally, as the parallelism grows within the storage array, we can slice and dice the devices using the get/put flash block API and enable applications to get predictable performance, while using large arrays that have a single address space.

Quoted 7 lines
Quoted 2 lines

If it too much for now to get upstream, I can live with (2) removed and then I make the changes you proposed.

In this case your driver API really isn't the Linux block API anymore. I think the right API is a simple asynchronous submit with callback into the driver, with the block device only provided by the lightnvm layer.

Agree. A group is working on a RocksDB prototype at the moment. When that is done, such an interface would be polished and submitted for review. The first patches here are to lay the groundwork for block I/O FTLs and generic flash block interface.

Quoted 4 lines

Note that for NVMe it might still make sense to implement this using blk-mq and a struct request, but those should be internal similar to how NVMe implements admin commands.

How about handling I/O merges? In the case where a block API is exposed with a global FTL, filesystems relies on I/O merges for improving performance. If using internal commands, merging has to implemented in the lightnvm stack itself, I rather want to use blk-mq and not duplicate the effort. I've kept the stacking model, so that I/Os go through the queue I/O path and then picked up in the device driver.

#17 lore raw
Quoted 10 lines · Matias Bjorling
Quoted 3 lines

Note that for NVMe it might still make sense to implement this using blk-mq and a struct request, but those should be internal similar to how NVMe implements admin commands.

How about handling I/O merges? In the case where a block API is exposed with a global FTL, filesystems relies on I/O merges for improving performance. If using internal commands, merging has to implemented in the lightnvm stack itself, I rather want to use blk-mq and not duplicate the effort. I've kept the stacking model, so that I/Os go through the queue I/O path and then picked up in the device driver.

I don't think the current abuses of the block API are acceptable though. The crazy deep merging shouldn't be too relevant for SSD-type devices so I think you'd do better than trying to reuse the TYPE_FS level blk-mq merging code. If you want to reuse the request allocation/submission code that's still doable.

As a start add a new submit_io method to the nvm_dev_ops, and add an implementation similar to pscsi_execute_cmd in drivers/target/target_core_pscsi.c for nvme, and a trivial no op for a null-nvm driver replacing the null-blk additions. This will give you very similar behavior to your current code, while allowing to drop all the hacks in the block code. Note that simple plugging will work just fine which should be all you'll need.

#18 lore raw
Quoted 6 lines

I don't think the current abuses of the block API are acceptable though. The crazy deep merging shouldn't be too relevant for SSD-type devices so I think you'd do better than trying to reuse the TYPE_FS level blk-mq merging code. If you want to reuse the request allocation/submission code that's still doable.

Quoted 8 lines

As a start add a new submit_io method to the nvm_dev_ops, and add an implementation similar to pscsi_execute_cmd in drivers/target/target_core_pscsi.c for nvme, and a trivial no op for a null-nvm driver replacing the null-blk additions. This will give you very similar behavior to your current code, while allowing to drop all the hacks in the block code. Note that simple plugging will work just fine which should be all you'll need.

Thanks, I appreciate you taking the time to go through it. I'll respin the patches and remove the block hacks.

#19 lore raw
In reply to Christoph Hellwig
Quoted 8 lines

As a start add a new submit_io method to the nvm_dev_ops, and add an implementation similar to pscsi_execute_cmd in drivers/target/target_core_pscsi.c for nvme, and a trivial no op for a null-nvm driver replacing the null-blk additions. This will give you very similar behavior to your current code, while allowing to drop all the hacks in the block code. Note that simple plugging will work just fine which should be all you'll need.

A quick question. The flow is getting into place and it is looking good.

However, the code path is still left with a per device flash block management core data structure in gendisk->nvm. ->nvm holds the device configuration (number of flash chips, channels, flash page sizes, etc.), free/used blocks in the media and other small structures. Basically keeping track of the state of the blocks on the media.

It is nice to have it associated with gendisk, as it then easily can be accessed from lightnvm code, without knowing which device driver that is underneath.

If moving it outside gendisk, one approach would be to create a separate block device for each open-channel ssd initialized. E.g. /dev/nvme0n1 has its block management information exposed through /dev/lnvm/nvme0n1_bm. For each *_bm, the private field holds a map between request_queue and bm. Effectively using a gendisk to act as a link between the real device and any FTL target. This seems just as hacky as the gendisk approach.

Any other approaches or is gendisk good for now?

Thanks, Matias

#20 lore raw

Hi Matias,

the underlying lighnvm driver (nvme or NULL) shouldn't register a gendisk - the only gendisk you'll need is that for the block device that sits on top of lightnvm.

#21 lore raw
Quoted 6 lines · Christoph Hellwig

Hi Matias,

the underlying lighnvm driver (nvme or NULL) shouldn't register a gendisk - the only gendisk you'll need is that for the block device that sits on top of lightnvm.

That could work as well. I'll refactor the nvme/null drivers to allow that instead. Thanks