lightnvm: Introduce System Blocks
cover lightnvm: Introduce System Blocks
Hi,
Currently a device is brought up via the media manager, which detects if a device supports it. We like to allow a drive to be intialized to a specific media manager and therefore introduce new functionality in the core to scan a specific set of flash blocks, that maintains what we call system blocks.
With this patchset, the disk should first be initialized to a given media manager, which then takes control over the device. The core and media managers are free to update the system block for the device. In the case of the initialization PPA for the media manager is changed or for other reasons.
A system block is duplicated in three places to prevent the system block data to be unreachable. We currently allocate blocks on three different luns, the first lun from the first channel, the first lun from the middle channel, and from the first lun in the last channel. If a device only have a single or two channels, only one or two system blocks are maintained.
The three luns each have two blocks reserved during initialization, which amounts to approximately 1.5M updates in total, which is much more updates that we expect with current workloads.
The first four patches prepares the core to directlt interact with the device, and the last patch introduces the recovery scheme.
Later patches will add the management functionality and integrate with the gennvm media manager.
Thanks,
Matias
Matias Bjørling (5):
lightnvm: move ppa erase logic to core
lightnvm: refactor rqd ppa list into set/free
lightnvm: add sync support for submit_io
lightnvm: introduce nvm_submit_ppa
lightnvm: core on-disk initialization
drivers/lightnvm/Makefile | 2 +- drivers/lightnvm/core.c | 128 +++++++++++ drivers/lightnvm/gennvm.c | 68 +----- drivers/lightnvm/sysblk.c | 524 +++++++++++++++++++++++++++++++++++++++++++ drivers/nvme/host/lightnvm.c | 7 + include/linux/lightnvm.h | 39 ++++ 6 files changed, 703 insertions(+), 65 deletions(-) create mode 100644 drivers/lightnvm/sysblk.c
Signature · 1 line
2.1.4
RFC PATCH 1/5 lightnvm: move ppa erase logic to core
A device may function in single, dual or quad plane mode. The gennvm media manager manages this with explicit helpers. They convert a single ppa to 1, 2 or 4 separate ppas in a ppa list. To aid implementation of recovery and system blocks, this functionality can be moved directly into the core.
--- drivers/lightnvm/core.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/lightnvm/gennvm.c | 68 +++-------------------------------------------- include/linux/lightnvm.h | 3 +++ 3 files changed, 74 insertions(+), 64 deletions(-)
drivers/lightnvm/core.c +67 -0
@@ -192,6 +192,73 @@ int nvm_erase_blk(struct nvm_dev *dev, struct nvm_block *blk) }EXPORT_SYMBOL (nvm_erase_blk); +void nvm_addr_to_generic_mode (struct nvm_dev *dev,struct nvm_rq *rqd) +{ +int i; + +if (rqd->nr_pages >1 ) { +for (i =0 ; i < rqd->nr_pages; i++) + rqd->ppa_list[i] =dev_to_generic_addr (dev, + rqd->ppa_list[i]); + }else { + rqd->ppa_addr =dev_to_generic_addr (dev, rqd->ppa_addr); + } +} +EXPORT_SYMBOL (nvm_addr_to_generic_mode); + +void nvm_generic_to_addr_mode (struct nvm_dev *dev,struct nvm_rq *rqd) +{ +int i; + +if (rqd->nr_pages >1 ) { +for (i =0 ; i < rqd->nr_pages; i++) + rqd->ppa_list[i] =generic_to_dev_addr (dev, + rqd->ppa_list[i]); + }else { + rqd->ppa_addr =generic_to_dev_addr (dev, rqd->ppa_addr); + } +} +EXPORT_SYMBOL (nvm_generic_to_addr_mode); + +int nvm_erase_ppa (struct nvm_dev *dev,struct ppa_addr ppa) +{ +int plane_cnt =0 , pl_idx, ret; +struct nvm_rq rqd; + +if (!dev->ops->erase_block) +return 0 ; + +if (dev->plane_mode ==NVM_PLANE_SINGLE ) { + rqd.nr_pages =1 ; + rqd.ppa_addr = ppa; + }else { + plane_cnt = (1 << dev->plane_mode); + rqd.nr_pages = plane_cnt; + + rqd.ppa_list =nvm_dev_dma_alloc (dev,GFP_KERNEL , + &rqd.dma_ppa_list); +if (!rqd.ppa_list) { +pr_err ("nvm: failed to allocate dma memory\n" ); +return -ENOMEM ; + } + +for (pl_idx =0 ; pl_idx < plane_cnt; pl_idx++) { + ppa.g.pl = pl_idx; + rqd.ppa_list[pl_idx] = ppa; + } + } + +nvm_generic_to_addr_mode (dev, &rqd); + + ret = dev->ops->erase_block (dev, &rqd); + +if (plane_cnt) +nvm_dev_dma_free (dev, rqd.ppa_list, rqd.dma_ppa_list); + +return ret; +} +EXPORT_SYMBOL (nvm_erase_ppa); +static int nvm_core_init (struct nvm_dev *dev) {struct nvm_id *id = &dev->identity;
drivers/lightnvm/gennvm.c +4 -64
93 lines not on this page · raw message
include/linux/lightnvm.h +3 -0
@@ -427,6 +427,9 @@ extern int nvm_register(struct request_queue *, char *,extern void nvm_unregister (char *);extern int nvm_submit_io (struct nvm_dev *,struct nvm_rq *); +extern void nvm_generic_to_addr_mode (struct nvm_dev *,struct nvm_rq *); +extern void nvm_addr_to_generic_mode (struct nvm_dev *,struct nvm_rq *); +extern int nvm_erase_ppa (struct nvm_dev *,struct ppa_addr );extern int nvm_erase_blk (struct nvm_dev *,struct nvm_block *);#else /* CONFIG_NVM */ struct nvm_dev_ops ;
Signature · 1 line
2.1.4
RFC PATCH 2/5 lightnvm: refactor rqd ppa list into set/free
In reply to Matias BjørlingA device may be driven in single, double or quad plane mode. In that case, the rqd must have either one, two, or four PPAs set for a single PPA sent to the device. Refactor this logic into their own functions to be shared by program/erase/read in the core.
--- drivers/lightnvm/core.c | 71 ++++++++++++++++++++++++++++++++++-------------- include/linux/lightnvm.h | 3 ++ 2 files changed, 53 insertions(+), 21 deletions(-)
drivers/lightnvm/core.c +50 -21
@@ -220,40 +220,69 @@ void nvm_generic_to_addr_mode(struct nvm_dev *dev, struct nvm_rq *rqd) }EXPORT_SYMBOL (nvm_generic_to_addr_mode); +int nvm_set_rqd_ppalist (struct nvm_dev *dev,struct nvm_rq *rqd, +struct ppa_addr *ppas,int nr_ppas) +{ +int i, plane_cnt, pl_idx; + +if (dev->plane_mode ==NVM_PLANE_SINGLE && nr_ppas ==1 ) { + rqd->nr_pages =1 ; + rqd->ppa_addr = ppas[0 ]; + +return 0 ; + } + + plane_cnt = (1 << dev->plane_mode); + rqd->nr_pages = plane_cnt * nr_ppas; + +if (dev->ops->max_phys_sect < rqd->nr_pages) +return -EINVAL ; + + rqd->ppa_list =nvm_dev_dma_alloc (dev,GFP_KERNEL , &rqd->dma_ppa_list); +if (!rqd->ppa_list) { +pr_err ("nvm: failed to allocate dma memory\n" ); +return -ENOMEM ; + } + +for (i =0 ; i < nr_ppas; i++) { +for (pl_idx =0 ; pl_idx < plane_cnt; pl_idx++) { + ppas[i].g.pl = pl_idx; + rqd->ppa_list[(i * plane_cnt) + pl_idx] = ppas[i]; + } + } + +return 0 ; +} +EXPORT_SYMBOL (nvm_set_rqd_ppalist); + +void nvm_free_rqd_ppalist (struct nvm_dev *dev,struct nvm_rq *rqd) +{ +if (!rqd->ppa_list) +return ; + +nvm_dev_dma_free (dev, rqd->ppa_list, rqd->dma_ppa_list); +} +EXPORT_SYMBOL (nvm_free_rqd_ppalist); +int nvm_erase_ppa (struct nvm_dev *dev,struct ppa_addr ppa) { -int plane_cnt =0 , pl_idx, ret;struct nvm_rq rqd; +int ret;if (!dev->ops->erase_block)return 0 ; -if (dev->plane_mode ==NVM_PLANE_SINGLE ) { - rqd.nr_pages =1 ; - rqd.ppa_addr = ppa; - }else { - plane_cnt = (1 << dev->plane_mode); - rqd.nr_pages = plane_cnt; +memset (&rqd,0 ,sizeof (struct nvm_rq )); - rqd.ppa_list =nvm_dev_dma_alloc (dev,GFP_KERNEL , - &rqd.dma_ppa_list); -if (!rqd.ppa_list) { -pr_err ("nvm: failed to allocate dma memory\n" ); -return -ENOMEM ; - } - -for (pl_idx =0 ; pl_idx < plane_cnt; pl_idx++) { - ppa.g.pl = pl_idx; - rqd.ppa_list[pl_idx] = ppa; - } - } + ret =nvm_set_rqd_ppalist (dev, &rqd, &ppa,1 ); +if (ret) +return ret;nvm_generic_to_addr_mode (dev, &rqd); ret = dev->ops->erase_block (dev, &rqd); -if (plane_cnt) -nvm_dev_dma_free (dev, rqd.ppa_list, rqd.dma_ppa_list); +nvm_free_rqd_ppalist (dev, &rqd);return ret; }
include/linux/lightnvm.h +3 -0
@@ -429,6 +429,9 @@ extern void nvm_unregister(char *);extern int nvm_submit_io (struct nvm_dev *,struct nvm_rq *);extern void nvm_generic_to_addr_mode (struct nvm_dev *,struct nvm_rq *);extern void nvm_addr_to_generic_mode (struct nvm_dev *,struct nvm_rq *); +extern int nvm_set_rqd_ppalist (struct nvm_dev *,struct nvm_rq *, +struct ppa_addr *,int ); +extern void nvm_free_rqd_ppalist (struct nvm_dev *,struct nvm_rq *);extern int nvm_erase_ppa (struct nvm_dev *,struct ppa_addr );extern int nvm_erase_blk (struct nvm_dev *,struct nvm_block *);#else /* CONFIG_NVM */
Signature · 1 line
2.1.4
RFC PATCH 3/5 lightnvm: add sync support for submit_io
In reply to Matias BjørlingAllow read and write I/Os to be issued synchronous. Users include the LightNVM core to implement system block support and similar.
--- drivers/nvme/host/lightnvm.c | 7 +++++++ include/linux/lightnvm.h | 3 +++ 2 files changed, 10 insertions(+)
drivers/nvme/host/lightnvm.c +7 -0
@@ -496,6 +496,13 @@ static int nvme_nvm_submit_io(struct nvm_dev *dev, struct nvm_rq *rqd) rq->cmd_len =sizeof (struct nvme_nvm_command ); rq->special = (void *)0 ; +if (rqd->flags &NVM_IO_F_SYNC ) { +int err =blk_execute_rq (q,NULL , rq,0 ); +kfree (cmd); +blk_mq_free_request (rq); +return err; + } + rq->end_io_data = rqd;blk_execute_rq_nowait (q,NULL , rq,0 , nvme_nvm_end_io);
include/linux/lightnvm.h +3 -0
@@ -60,6 +60,9 @@ enum {NVM_BLK_T_BAD =0x1 ,NVM_BLK_T_DEV =0x2 ,NVM_BLK_T_HOST =0x4 , + +/* NVM Request Flags */ + NVM_IO_F_SYNC = 0x1, }; struct nvm_id_group {
Signature · 1 line
2.1.4
Re: [PATCH RFC 3/5] lightnvm: add sync support for submit_io
Quoted 2 lines · Matias Bj??rling
Allow read and write I/Os to be issued synchronous. Users include the LightNVM core to implement system block support and similar.
I think the right way to implement this is to wait in the caller, e.g. set your end_io handler to a trivial one that just does a complete and add a completion that you can wait on in the caller.
Re: [PATCH RFC 3/5] lightnvm: add sync support for submit_io
Quoted 8 lines · Christoph Hellwig
Quoted 2 lines · Matias Bj??rling
Allow read and write I/Os to be issued synchronous. Users include the LightNVM core to implement system block support and similar.
I think the right way to implement this is to wait in the caller, e.g. set your
end_iohandler to a trivial one that just does a complete and add a completion that you can wait on in the caller.
Thanks Christoph. I'll change it.
RFC PATCH 4/5 lightnvm: introduce nvm_submit_ppa
In reply to Matias BjørlingInternal logic for both core and media managers, does not have a backing bio for issuing I/Os. Introduce nvm_submit_ppa to allow raw I/Os to be submitted to the underlying device driver.
The function request the device, ppa, data buffer and its length and will submit the I/O synchronously to the device. The return value may therefore be used to detect any errors regarding the issued I/O.
--- drivers/lightnvm/core.c | 31 +++++++++++++++++++++++++++++++ include/linux/lightnvm.h | 1 + 2 files changed, 32 insertions(+)
drivers/lightnvm/core.c +31 -0
@@ -288,6 +288,37 @@ int nvm_erase_ppa(struct nvm_dev *dev, struct ppa_addr ppa) }EXPORT_SYMBOL (nvm_erase_ppa); +int nvm_submit_ppa (struct nvm_dev *dev,struct ppa_addr ppa,int opcode, +void *buf,int len) +{ +struct nvm_rq rqd; +struct bio *bio; +int ret; + + bio =bio_map_kern (dev->q, buf, len,GFP_KERNEL ); +if (IS_ERR_OR_NULL (bio)) +return -ENOMEM ; + +memset (&rqd,0 ,sizeof (struct nvm_rq )); + ret =nvm_set_rqd_ppalist (dev, &rqd, &ppa,1 ); +if (ret) { +bio_put (bio); +return ret; + } + + rqd.opcode = opcode; + rqd.flags =NVM_IO_F_SYNC ; + rqd.bio = bio; +nvm_generic_to_addr_mode (dev, &rqd); + + ret = dev->ops->submit_io (dev, &rqd); + +nvm_free_rqd_ppalist (dev, &rqd); + +return ret; +} +EXPORT_SYMBOL (nvm_submit_ppa); +static int nvm_core_init (struct nvm_dev *dev) {struct nvm_id *id = &dev->identity;
include/linux/lightnvm.h +1 -0
@@ -437,6 +437,7 @@ extern int nvm_set_rqd_ppalist(struct nvm_dev *, struct nvm_rq *,extern void nvm_free_rqd_ppalist (struct nvm_dev *,struct nvm_rq *);extern int nvm_erase_ppa (struct nvm_dev *,struct ppa_addr );extern int nvm_erase_blk (struct nvm_dev *,struct nvm_block *); +extern int nvm_submit_ppa (struct nvm_dev *,struct ppa_addr ,int ,void *,int );#else /* CONFIG_NVM */ struct nvm_dev_ops ;
Signature · 1 line
2.1.4
RFC PATCH 5/5 lightnvm: core on-disk initialization
In reply to Matias BjørlingAn Open-Channel SSD shall be initialized before use. To initialize, we define an on-disk format, that keeps a small set of metadata to bring up the media manager on top of the device.
The initial step is introduced to allow a user to format the disks for a given media manager. During format, a system block is stored on one to three separate luns on the device. Each lun has the system block duplicated. During initialization, the system block can be retrieved and the appropriate media manager can initialized.
The on-disk format currently covers (struct nvm_system_block):
- Magic value "NVMS".
- Monotonic increasing sequence number.
- The physical block erase count.
- Version of the system block format.
- Media manager type.
- Media manager superblock physical address.
The interface provides three functions to manage the system block:
int nvm_init_sysblock(struct nvm_dev *, struct nvm_sb_info *) int nvm_get_sysblock(struct nvm *dev, struct nvm_sb_info *) int nvm_update_sysblock(struct nvm *dev, struct nvm_sb_info *)
Each implement a part of the logic to manage the system block. The initialization creates the first system blocks and mark them on the device. Get retrieves the latest system block by scanning all pages in the associated system blocks. The update sysblock writes new metadata and allocates new block if necessary.
--- drivers/lightnvm/Makefile | 2 +- drivers/lightnvm/core.c | 1 + drivers/lightnvm/sysblk.c | 524 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/lightnvm.h | 29 +++ 4 files changed, 555 insertions(+), 1 deletion(-) create mode 100644 drivers/lightnvm/sysblk.c
drivers/lightnvm/Makefile +1 -1
@@ -2,6 +2,6 @@ # Makefile for Open-Channel SSDs. # -obj-$(CONFIG_NVM) := core.o +obj-$(CONFIG_NVM) := core.o sysblk.o obj-$(CONFIG_NVM_GENNVM) += gennvm.o obj-$(CONFIG_NVM_RRPC) += rrpc.o
drivers/lightnvm/core.c +1 -0
@@ -365,6 +365,7 @@ static int nvm_core_init(struct nvm_dev *dev) dev->nr_chnls; dev->total_pages = dev->total_blocks * dev->pgs_per_blk;INIT_LIST_HEAD (&dev->online_targets); +mutex_init (&dev->mlock);return 0 ; }
drivers/lightnvm/sysblk.c new file +524 -0
524 lines not on this page · raw message
include/linux/lightnvm.h +29 -0
@@ -283,6 +283,8 @@ struct nvm_dev {/* Backend device */ struct request_queue *q;char name[DISK_NAME_LEN ]; + +struct mutex mlock; }; static inline struct ppa_addr generic_to_dev_addr(struct nvm_dev *dev,
@@ -438,6 +440,33 @@ extern void nvm_free_rqd_ppalist(struct nvm_dev *, struct nvm_rq *);extern int nvm_erase_ppa (struct nvm_dev *,struct ppa_addr );extern int nvm_erase_blk (struct nvm_dev *,struct nvm_block *);extern int nvm_submit_ppa (struct nvm_dev *,struct ppa_addr ,int ,void *,int ); + +/* sysblk.c */ +#define NVM_SYSBLK_MAGIC 0x4E564D53/* "NVMS" */ + +/* system block on disk representation */ +struct nvm_system_block { +__be32 magic;/* magic signature */ +__be32 seqnr;/* sequence number */ +__be32 erase_cnt;/* erase count */ +__be16 version;/* version number */ +__be16 mmtype;/* media manager type */ +__be64 fs_ppa;/* PPA for media manager +* superblock */ +}; + +/* system block cpu representation */ +struct nvm_sb_info { +unsigned long seqnr; +unsigned long erase_cnt; +unsigned int version; +unsigned int mmtype; +struct ppa_addr fs_ppa; +}; + +extern int nvm_get_sysblock (struct nvm_dev *,struct nvm_sb_info *); +extern int nvm_update_sysblock (struct nvm_dev *,struct nvm_sb_info *); +extern int nvm_init_sysblock (struct nvm_dev *,struct nvm_sb_info *);#else /* CONFIG_NVM */ struct nvm_dev_ops ;
Signature · 1 line
2.1.4