Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1194124 > unrolled thread

[PATCH v6 0/5] Support for Open-Channel SSDs

Started byMatias Bjørling <mb@lightnvm.io>
First post2015-07-28 13:20 +0200
Last post2015-08-04 14:00 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v6 0/5] Support for Open-Channel SSDs Matias Bjørling <mb@lightnvm.io> - 2015-07-28 13:20 +0200
    [PATCH v6 3/5] lightnvm: Hybrid Open-Channel SSD block manager Matias Bjørling <mb@lightnvm.io> - 2015-07-28 13:20 +0200
    Re: [PATCH v6 0/5] Support for Open-Channel SSDs Christoph Hellwig <hch@infradead.org> - 2015-08-04 13:40 +0200
      Re: [PATCH v6 0/5] Support for Open-Channel SSDs Matias <mb@lightnvm.io> - 2015-08-04 14:00 +0200

#1194124 — [PATCH v6 0/5] Support for Open-Channel SSDs

FromMatias Bjørling <mb@lightnvm.io>
Date2015-07-28 13:20 +0200
Subject[PATCH v6 0/5] Support for Open-Channel SSDs
Message-ID<pRb5n-7Bt-5@gated-at.bofh.it>
These patches implement support for Open-Channel SSDs.

Applies against axboe's linux-block/for-4.3/drivers, and can be found
in the lkml_v6 branch at https://github.com/OpenChannelSSD/linux

Any feedback is greatly appreciated.

Changes since v5:

Feedback from Christoph Hellwig.
 - Created new null_nvm from null_blk to register itself as a lightnvm
   device.
 - Changed the interface of register/unregister to only take disk_name.
   The gendisk alloc in nvme is kept. Most instantiations will
   involve the device gendisk, therefore wait with refactoring to a
   later time.
 - Renamed global parameters in core.c and rrpc.c

Changes since v4:
 - Remove gendisk->nvm dependency
 - Remove device driver rq private field dependency.
 - Update submission and completion. The flow is now
     Target -> Block Manager -> Device Driver, replacing callbacks in
     device driver.
 - Abstracted out the block manager into its own module. Other block
   managers can now be implemented. For example to support fully
   host-based SSDs.
 - No longer exposes the device driver gendisk to user-space.
 - Management is moved into /sys/modules/lnvm/parameters/configure_debug

Changes since v3:

 - Remove dependency 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.

Thanks to Jens Axboe, Christoph Hellwig, Keith Busch, Paul Bolle,
Javier Gonzalez and Jesper Madsen for discussions and contributions.

Matias Bjørling (5):
  lightnvm: Support for Open-Channel SSDs
  lightnvm: Hybrid Open-Channel SSD RRPC target
  lightnvm: Hybrid Open-Channel SSD block manager
  null_nvm: Lightnvm test driver
  nvme: LightNVM support

 MAINTAINERS                   |    8 +
 drivers/Kconfig               |    2 +
 drivers/Makefile              |    5 +
 drivers/block/Makefile        |    2 +-
 drivers/block/nvme-core.c     |   22 +-
 drivers/block/nvme-lightnvm.c |  509 ++++++++++++++++++
 drivers/lightnvm/Kconfig      |   36 ++
 drivers/lightnvm/Makefile     |    8 +
 drivers/lightnvm/bm_hb.c      |  379 +++++++++++++
 drivers/lightnvm/bm_hb.h      |   31 ++
 drivers/lightnvm/core.c       |  580 ++++++++++++++++++++
 drivers/lightnvm/null_nvm.c   |  420 +++++++++++++++
 drivers/lightnvm/rrpc.c       | 1190 +++++++++++++++++++++++++++++++++++++++++
 drivers/lightnvm/rrpc.h       |  220 ++++++++
 include/linux/lightnvm.h      |  385 +++++++++++++
 include/linux/nvme.h          |    6 +
 include/uapi/linux/nvme.h     |    3 +
 17 files changed, 3802 insertions(+), 4 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/bm_hb.c
 create mode 100644 drivers/lightnvm/bm_hb.h
 create mode 100644 drivers/lightnvm/core.c
 create mode 100644 drivers/lightnvm/null_nvm.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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1194132 — [PATCH v6 3/5] lightnvm: Hybrid Open-Channel SSD block manager

FromMatias Bjørling <mb@lightnvm.io>
Date2015-07-28 13:20 +0200
Subject[PATCH v6 3/5] lightnvm: Hybrid Open-Channel SSD block manager
Message-ID<pRb5o-7Bt-37@gated-at.bofh.it>
In reply to#1194124
The host implementation for Open-Channel SSDs is divided into block
management and targets. This patch implements the block manager for
hybrid open-channel SSDs. On top a target, such as rrpc is initialized.

Signed-off-by: Matias Bjørling <mb@lightnvm.io>
---
 drivers/lightnvm/Kconfig  |   7 +
 drivers/lightnvm/Makefile |   1 +
 drivers/lightnvm/bm_hb.c  | 379 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/lightnvm/bm_hb.h  |  31 ++++
 4 files changed, 418 insertions(+)
 create mode 100644 drivers/lightnvm/bm_hb.c
 create mode 100644 drivers/lightnvm/bm_hb.h

diff --git a/drivers/lightnvm/Kconfig b/drivers/lightnvm/Kconfig
index ab1fe57..37b00ae 100644
--- a/drivers/lightnvm/Kconfig
+++ b/drivers/lightnvm/Kconfig
@@ -23,4 +23,11 @@ config NVM_RRPC
 	host. The target is implemented using a linear mapping table and
 	cost-based garbage collection. It is optimized for 4K IO sizes.
 
+config NVM_BM_HB
+	tristate "Block manager for Hybrid Open-Channel SSD"
+	---help---
+	Block manager for SSDs that offload block management off to the device,
+	while keeping data placement and garbage collection decisions on the
+	host.
+
 endif # NVM
diff --git a/drivers/lightnvm/Makefile b/drivers/lightnvm/Makefile
index b2a39e2..9ff4669 100644
--- a/drivers/lightnvm/Makefile
+++ b/drivers/lightnvm/Makefile
@@ -4,3 +4,4 @@
 
 obj-$(CONFIG_NVM)		:= core.o
 obj-$(CONFIG_NVM_RRPC)		+= rrpc.o
+obj-$(CONFIG_NVM_BM_HB) 	+= bm_hb.o
diff --git a/drivers/lightnvm/bm_hb.c b/drivers/lightnvm/bm_hb.c
new file mode 100644
index 0000000..4272b7e
--- /dev/null
+++ b/drivers/lightnvm/bm_hb.c
@@ -0,0 +1,379 @@
+/*
+ * Copyright: Matias Bjorling <mb@lightnvm.io>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * Implementation of a block manager for hybrid open-channel SSD.
+ */
+
+#include "bm_hb.h"
+
+static void hb_blocks_free(struct nvm_dev *dev)
+{
+	struct bm_hb *bm = dev->bmp;
+	struct nvm_lun *lun;
+	int i;
+
+	bm_for_each_lun(dev, bm, lun, i) {
+		if (!lun->blocks)
+			break;
+		vfree(lun->blocks);
+	}
+}
+
+static void hb_luns_free(struct nvm_dev *dev)
+{
+	struct bm_hb *bm = dev->bmp;
+
+	kfree(bm->luns);
+}
+
+static int hb_luns_init(struct nvm_dev *dev, struct bm_hb *bm)
+{
+	struct nvm_lun *lun;
+	struct nvm_id_chnl *chnl;
+	int i;
+
+	bm->luns = kcalloc(dev->nr_luns, sizeof(struct nvm_lun), GFP_KERNEL);
+	if (!bm->luns)
+		return -ENOMEM;
+
+	bm_for_each_lun(dev, bm, lun, i) {
+		chnl = &dev->identity.chnls[i];
+		pr_info("bm_hb: p %u qsize %u gr %u ge %u begin %llu end %llu\n",
+			i, chnl->queue_size, chnl->gran_read, chnl->gran_erase,
+			chnl->laddr_begin, chnl->laddr_end);
+
+		spin_lock_init(&lun->lock);
+
+		INIT_LIST_HEAD(&lun->free_list);
+		INIT_LIST_HEAD(&lun->used_list);
+		INIT_LIST_HEAD(&lun->bb_list);
+
+		lun->id = i;
+		lun->dev = dev;
+		lun->chnl = chnl;
+		lun->reserved_blocks = 2; /* for GC only */
+		lun->nr_blocks =
+				(chnl->laddr_end - chnl->laddr_begin + 1) /
+				(chnl->gran_erase / chnl->gran_read);
+		lun->nr_free_blocks = lun->nr_blocks;
+		lun->nr_pages_per_blk = chnl->gran_erase / chnl->gran_write *
+					(chnl->gran_write / dev->sector_size);
+
+		if (lun->nr_pages_per_blk > dev->max_pages_per_blk)
+			dev->max_pages_per_blk = lun->nr_pages_per_blk;
+
+		dev->total_pages += lun->nr_blocks * lun->nr_pages_per_blk;
+		dev->total_blocks += lun->nr_blocks;
+
+		if (lun->nr_pages_per_blk >
+				MAX_INVALID_PAGES_STORAGE * BITS_PER_LONG) {
+			pr_err("bm_hb: number of pages per block too high.");
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+static int hb_block_bb(u32 lun_id, void *bb_bitmap, unsigned int nr_blocks,
+								void *private)
+{
+	struct bm_hb *bm = private;
+	struct nvm_lun *lun = &bm->luns[lun_id];
+	struct nvm_block *block;
+	int i;
+
+	if (unlikely(bitmap_empty(bb_bitmap, nr_blocks)))
+		return 0;
+
+	i = -1;
+	while ((i = find_next_bit(bb_bitmap, nr_blocks, i + 1)) <
+			nr_blocks) {
+		block = &lun->blocks[i];
+		if (!block) {
+			pr_err("bm_hb: BB data is out of bounds!\n");
+			return -EINVAL;
+		}
+		list_move_tail(&block->list, &lun->bb_list);
+	}
+
+	return 0;
+}
+
+static int hb_block_map(u64 slba, u64 nlb, u64 *entries, void *private)
+{
+	struct nvm_dev *dev = private;
+	struct bm_hb *bm = dev->bmp;
+	sector_t max_pages = dev->total_pages * (dev->sector_size >> 9);
+	u64 elba = slba + nlb;
+	struct nvm_lun *lun;
+	struct nvm_block *blk;
+	sector_t total_pgs_per_lun = /* each lun have the same configuration */
+		   bm->luns[0].nr_blocks * bm->luns[0].nr_pages_per_blk;
+	u64 i;
+	int lun_id;
+
+	if (unlikely(elba > dev->total_pages)) {
+		pr_err("bm_hb: L2P data from device is out of bounds!\n");
+		return -EINVAL;
+	}
+
+	for (i = 0; i < nlb; i++) {
+		u64 pba = le64_to_cpu(entries[i]);
+
+		if (unlikely(pba >= max_pages && pba != U64_MAX)) {
+			pr_err("bm_hb: L2P data entry is out of bounds!\n");
+			return -EINVAL;
+		}
+
+		/* Address zero is a special one. The first page on a disk is
+		 * protected. As it often holds internal device boot
+		 * information. */
+		if (!pba)
+			continue;
+
+		/* resolve block from physical address */
+		lun_id = pba / total_pgs_per_lun;
+		lun = &bm->luns[lun_id];
+
+		/* Calculate block offset into lun */
+		pba = pba - (total_pgs_per_lun * lun_id);
+		blk = &lun->blocks[pba / lun->nr_pages_per_blk];
+
+		if (!blk->type) {
+			/* at this point, we don't know anything about the
+			 * block. It's up to the FTL on top to re-etablish the
+			 * block state */
+			list_move_tail(&blk->list, &lun->used_list);
+			blk->type = 1;
+			lun->nr_free_blocks--;
+		}
+	}
+
+	return 0;
+}
+
+static int hb_blocks_init(struct nvm_dev *dev, struct bm_hb *bm)
+{
+	struct nvm_lun *lun;
+	struct nvm_block *block;
+	sector_t lun_iter, block_iter, cur_block_id = 0;
+	int ret;
+
+	bm_for_each_lun(dev, bm, lun, lun_iter) {
+		lun->blocks = vzalloc(sizeof(struct nvm_block) *
+						lun->nr_blocks);
+		if (!lun->blocks)
+			return -ENOMEM;
+
+		lun_for_each_block(lun, block, block_iter) {
+			spin_lock_init(&block->lock);
+			INIT_LIST_HEAD(&block->list);
+
+			block->lun = lun;
+			block->id = cur_block_id++;
+
+			/* First block is reserved for device */
+			if (unlikely(lun_iter == 0 && block_iter == 0))
+				continue;
+
+			list_add_tail(&block->list, &lun->free_list);
+		}
+
+		if (dev->ops->get_bb_tbl) {
+			ret = dev->ops->get_bb_tbl(dev->q, lun->id,
+			lun->nr_blocks, hb_block_bb, bm);
+			if (ret)
+				pr_err("bm_hb: could not read BB table\n");
+		}
+	}
+
+	if (dev->ops->get_l2p_tbl) {
+		ret = dev->ops->get_l2p_tbl(dev->q, 0, dev->total_pages,
+							hb_block_map, dev);
+		if (ret) {
+			pr_err("bm_hb: could not read L2P table.\n");
+			pr_warn("bm_hb: default block initialization");
+		}
+	}
+
+	return 0;
+}
+
+static int hb_register(struct nvm_dev *dev)
+{
+	struct bm_hb *bm;
+	int ret;
+
+	if (!dev->features.rsp & NVM_RSP_L2P)
+		return 0;
+
+	bm = kzalloc(sizeof(struct bm_hb), GFP_KERNEL);
+	if (!bm)
+		return -ENOMEM;
+
+	dev->bmp = bm;
+
+	ret = hb_luns_init(dev, bm);
+	if (ret) {
+		pr_err("bm_hb: could not initialize luns\n");
+		goto err;
+	}
+
+	ret = hb_blocks_init(dev, bm);
+	if (ret) {
+		pr_err("bm_hb: could not initialize blocks\n");
+		goto err;
+	}
+
+	return 1;
+err:
+	kfree(bm);
+	return ret;
+}
+
+static void hb_unregister(struct nvm_dev *dev)
+{
+	hb_blocks_free(dev);
+	hb_luns_free(dev);
+	kfree(dev->bmp);
+	dev->bmp = NULL;
+}
+
+static void nvm_reset_block(struct nvm_lun *lun, struct nvm_block *block)
+{
+	spin_lock(&block->lock);
+	bitmap_zero(block->invalid_pages, lun->nr_pages_per_blk);
+	block->next_page = 0;
+	block->nr_invalid_pages = 0;
+	atomic_set(&block->data_cmnt_size, 0);
+	spin_unlock(&block->lock);
+}
+
+static struct nvm_block *hb_get_blk(struct nvm_dev *dev, struct nvm_lun *lun,
+							unsigned long flags)
+{
+	struct nvm_block *block = NULL;
+	int is_gc = flags & NVM_IOTYPE_GC;
+
+	BUG_ON(!lun);
+
+	spin_lock(&lun->lock);
+
+	if (list_empty(&lun->free_list)) {
+		pr_err_ratelimited("bm_hb: lun %u have no free pages available",
+								lun->id);
+		spin_unlock(&lun->lock);
+		goto out;
+	}
+
+	while (!is_gc && lun->nr_free_blocks < lun->reserved_blocks) {
+		spin_unlock(&lun->lock);
+		goto out;
+	}
+
+	block = list_first_entry(&lun->free_list, struct nvm_block, list);
+	list_move_tail(&block->list, &lun->used_list);
+
+	lun->nr_free_blocks--;
+
+	spin_unlock(&lun->lock);
+
+	nvm_reset_block(lun, block);
+
+out:
+	return block;
+}
+
+static void hb_put_blk(struct nvm_dev *dev, struct nvm_block *blk)
+{
+	struct nvm_lun *lun = blk->lun;
+
+	spin_lock(&lun->lock);
+
+	list_move_tail(&blk->list, &lun->free_list);
+	lun->nr_free_blocks++;
+
+	spin_unlock(&lun->lock);
+}
+
+static int hb_submit_io(struct nvm_dev *dev, struct nvm_rq *rqd)
+{
+	if (!dev->ops->submit_io)
+		return 0;
+
+	return dev->ops->submit_io(dev->q, rqd);
+}
+
+static void hb_end_io(struct nvm_rq *rqd, int error)
+{
+	struct nvm_tgt_instance *ins = rqd->ins;
+
+	ins->tt->end_io(rqd, error);
+}
+
+static int hb_erase_blk(struct nvm_dev *dev, struct nvm_block *blk)
+{
+	if (!dev->ops->erase_block)
+		return 0;
+
+	return dev->ops->erase_block(dev->q, blk->id);
+}
+
+static struct nvm_lun *hb_get_luns(struct nvm_dev *dev, int begin, int end)
+{
+	struct bm_hb *bm = dev->bmp;
+
+	return bm->luns + begin;
+}
+
+static void hb_free_blocks_print(struct nvm_dev *dev)
+{
+	struct bm_hb *bm = dev->bmp;
+	struct nvm_lun *lun;
+	unsigned int i;
+
+	bm_for_each_lun(dev, bm, lun, i)
+		pr_info("%s: lun%8u\t%u\n", dev->name, i, lun->nr_free_blocks);
+}
+
+static struct nvm_bm_type bm_hb = {
+	.name		= "hb",
+
+	.register_bm	= hb_register,
+	.unregister_bm	= hb_unregister,
+
+	.get_blk	= hb_get_blk,
+	.put_blk	= hb_put_blk,
+
+	.submit_io	= hb_submit_io,
+	.end_io		= hb_end_io,
+	.erase_blk	= hb_erase_blk,
+
+	.get_luns	= hb_get_luns,
+	.free_blocks_print = hb_free_blocks_print,
+};
+
+static int __init hb_module_init(void)
+{
+	return nvm_register_bm(&bm_hb);
+}
+
+static void hb_module_exit(void)
+{
+	nvm_unregister_bm(&bm_hb);
+}
+
+module_init(hb_module_init);
+module_exit(hb_module_exit);
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("Block manager for Hybrid Open-Channel SSDs");
diff --git a/drivers/lightnvm/bm_hb.h b/drivers/lightnvm/bm_hb.h
new file mode 100644
index 0000000..13171af
--- /dev/null
+++ b/drivers/lightnvm/bm_hb.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright: Matias Bjorling <mb@lightnvm.io>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ */
+
+#ifndef BM_HB_H_
+#define BM_HB_H_
+
+#include <linux/module.h>
+#include <linux/vmalloc.h>
+
+#include <linux/lightnvm.h>
+
+struct bm_hb {
+	struct nvm_lun *luns;
+};
+
+#define bm_for_each_lun(dev, bm, lun, i) \
+		for ((i) = 0, lun = &(bm)->luns[0]; \
+			(i) < (dev)->nr_luns; (i)++, lun = &(bm)->luns[(i)])
+
+#endif /* BM_HB_H_ */
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1199698

FromChristoph Hellwig <hch@infradead.org>
Date2015-08-04 13:40 +0200
Message-ID<pTIJA-OZ-13@gated-at.bofh.it>
In reply to#1194124
Hi Matias,

the architecture looks fine to me.  Probab;y not worth merging until
your have the multipage I/O sorted out and real hardware, or do you want
to aim for fast inclusion?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1199715

FromMatias <mb@lightnvm.io>
Date2015-08-04 14:00 +0200
Message-ID<pTJ2Y-1c2-47@gated-at.bofh.it>
In reply to#1199698
On 08/04/2015 01:30 PM, Christoph Hellwig wrote:
> Hi Matias,
>
> the architecture looks fine to me.  Probab;y not worth merging until
> your have the multipage I/O sorted out and real hardware, or do you want
> to aim for fast inclusion?
>

Hi Christoph,

The multipage will come in v7. Javier has it flushed out, and we are 
just going through the last nitpicks on it.

I'll like to get it included. There is some out-of-tree work that is 
based on it, which requires that the kernel and the modules are compiled 
together. Having the core part in the kernel will be very helpful.

(resending to the lists. Forgot to put gmail in plain text mode)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web