2015-11-20 09:01:35

by Javier González

[permalink] [raw]
Subject: [PATCH 1/2] lightnvm: keep track of block counts

Maintain number of in use blocks, free blocks, and bad blocks in a per
lun basis. This allows the upper layers to get information about the
state of each lun.

Also, account for blocks reserved to the device on the free block count.
nr_free_blocks matches now the actual number of blocks on the free list
when the device is booted.

Signed-off-by: Javier Gonzalez <[email protected]>
---
drivers/lightnvm/gennvm.c | 14 +++++++++++++-
include/linux/lightnvm.h | 2 ++
2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/lightnvm/gennvm.c b/drivers/lightnvm/gennvm.c
index c0d0eb2..43c01e0 100644
--- a/drivers/lightnvm/gennvm.c
+++ b/drivers/lightnvm/gennvm.c
@@ -60,6 +60,8 @@ static int gennvm_luns_init(struct nvm_dev *dev, struct gen_nvm *gn)
lun->vlun.lun_id = i % dev->luns_per_chnl;
lun->vlun.chnl_id = i / dev->luns_per_chnl;
lun->vlun.nr_free_blocks = dev->blks_per_lun;
+ lun->vlun.nr_inuse_blocks = 0;
+ lun->vlun.nr_bad_blocks = 0;
}
return 0;
}
@@ -87,6 +89,7 @@ static int gennvm_block_bb(struct ppa_addr ppa, int nr_blocks, u8 *blks,
}

list_move_tail(&blk->list, &lun->bb_list);
+ lun->vlun.nr_bad_blocks++;
}

return 0;
@@ -139,6 +142,7 @@ static int gennvm_block_map(u64 slba, u32 nlb, __le64 *entries, void *private)
list_move_tail(&blk->list, &lun->used_list);
blk->type = 1;
lun->vlun.nr_free_blocks--;
+ lun->vlun.nr_inuse_blocks++;
}
}

@@ -167,8 +171,10 @@ static int gennvm_blocks_init(struct nvm_dev *dev, struct gen_nvm *gn)
block->id = cur_block_id++;

/* First block is reserved for device */
- if (unlikely(lun_iter == 0 && blk_iter == 0))
+ if (unlikely(lun_iter == 0 && blk_iter == 0)) {
+ lun->vlun.nr_free_blocks--;
continue;
+ }

list_add_tail(&block->list, &lun->free_list);
}
@@ -266,6 +272,7 @@ static struct nvm_block *gennvm_get_blk(struct nvm_dev *dev,
blk->type = 1;

lun->vlun.nr_free_blocks--;
+ lun->vlun.nr_inuse_blocks++;

spin_unlock(&vlun->lock);
out:
@@ -283,16 +290,21 @@ static void gennvm_put_blk(struct nvm_dev *dev, struct nvm_block *blk)
case 1:
list_move_tail(&blk->list, &lun->free_list);
lun->vlun.nr_free_blocks++;
+ lun->vlun.nr_inuse_blocks--;
blk->type = 0;
break;
case 2:
list_move_tail(&blk->list, &lun->bb_list);
+ lun->vlun.nr_bad_blocks++;
+ lun->vlun.nr_inuse_blocks--;
break;
default:
WARN_ON_ONCE(1);
pr_err("gennvm: erroneous block type (%lu -> %u)\n",
blk->id, blk->type);
list_move_tail(&blk->list, &lun->bb_list);
+ lun->vlun.nr_bad_blocks++;
+ lun->vlun.nr_inuse_blocks--;
}

spin_unlock(&vlun->lock);
diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h
index 2581cea..76acd15 100644
--- a/include/linux/lightnvm.h
+++ b/include/linux/lightnvm.h
@@ -213,7 +213,9 @@ struct nvm_lun {
int lun_id;
int chnl_id;

+ unsigned int nr_inuse_blocks; /* Number of used blocks */
unsigned int nr_free_blocks; /* Number of unused blocks */
+ unsigned int nr_bad_blocks; /* Number of bad blocks */
struct nvm_block *blocks;

spinlock_t lock;
--
2.1.4


2015-11-20 09:01:38

by Javier González

[permalink] [raw]
Subject: [PATCH 2/2] lightnvm: add lun information to show debug interf.

Add free block, used block, and bad block information to the show debug
interface. This information is used to debug how targets track blocks.

Also, change debug function name to make it more generic.

Signed-off-by: Javier Gonzalez <[email protected]>
---
drivers/lightnvm/core.c | 2 +-
drivers/lightnvm/gennvm.c | 19 ++++++++++++++-----
include/linux/lightnvm.h | 4 ++--
3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index 51e0008..e0072b5 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -544,7 +544,7 @@ static int nvm_configure_show(const char *val)
if (!dev->mt)
return 0;

- dev->mt->free_blocks_print(dev);
+ dev->mt->lun_info_print(dev);

return 0;
}
diff --git a/drivers/lightnvm/gennvm.c b/drivers/lightnvm/gennvm.c
index 43c01e0..e20e74e 100644
--- a/drivers/lightnvm/gennvm.c
+++ b/drivers/lightnvm/gennvm.c
@@ -464,15 +464,24 @@ static struct nvm_lun *gennvm_get_lun(struct nvm_dev *dev, int lunid)
return &gn->luns[lunid].vlun;
}

-static void gennvm_free_blocks_print(struct nvm_dev *dev)
+static void gennvm_lun_info_print(struct nvm_dev *dev)
{
struct gen_nvm *gn = dev->mp;
struct gen_lun *lun;
unsigned int i;

- gennvm_for_each_lun(gn, lun, i)
- pr_info("%s: lun%8u\t%u\n",
- dev->name, i, lun->vlun.nr_free_blocks);
+
+ gennvm_for_each_lun(gn, lun, i) {
+ spin_lock(&lun->vlun.lock);
+
+ pr_info("%s: lun%8u\t%u\t%u\t%u\n",
+ dev->name, i,
+ lun->vlun.nr_free_blocks,
+ lun->vlun.nr_inuse_blocks,
+ lun->vlun.nr_bad_blocks);
+
+ spin_unlock(&lun->vlun.lock);
+ }
}

static struct nvmm_type gennvm = {
@@ -490,7 +499,7 @@ static struct nvmm_type gennvm = {
.erase_blk = gennvm_erase_blk,

.get_lun = gennvm_get_lun,
- .free_blocks_print = gennvm_free_blocks_print,
+ .lun_info_print = gennvm_lun_info_print,
};

static int __init gennvm_module_init(void)
diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h
index 76acd15..e527d67 100644
--- a/include/linux/lightnvm.h
+++ b/include/linux/lightnvm.h
@@ -380,7 +380,7 @@ typedef int (nvmm_end_io_fn)(struct nvm_rq *, int);
typedef int (nvmm_erase_blk_fn)(struct nvm_dev *, struct nvm_block *,
unsigned long);
typedef struct nvm_lun *(nvmm_get_lun_fn)(struct nvm_dev *, int);
-typedef void (nvmm_free_blocks_print_fn)(struct nvm_dev *);
+typedef void (nvmm_lun_info_print_fn)(struct nvm_dev *);

struct nvmm_type {
const char *name;
@@ -404,7 +404,7 @@ struct nvmm_type {
nvmm_get_lun_fn *get_lun;

/* Statistics */
- nvmm_free_blocks_print_fn *free_blocks_print;
+ nvmm_lun_info_print_fn *lun_info_print;
struct list_head list;
};

--
2.1.4

2015-11-20 12:44:36

by Matias Bjørling

[permalink] [raw]
Subject: Re: [PATCH 2/2] lightnvm: add lun information to show debug interf.

On 11/20/2015 10:01 AM, Javier Gonzalez wrote:
> Add free block, used block, and bad block information to the show debug
> interface. This information is used to debug how targets track blocks.
>
> Also, change debug function name to make it more generic.
>
> Signed-off-by: Javier Gonzalez <[email protected]>
> ---
> drivers/lightnvm/core.c | 2 +-
> drivers/lightnvm/gennvm.c | 19 ++++++++++++++-----
> include/linux/lightnvm.h | 4 ++--
> 3 files changed, 17 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
> index 51e0008..e0072b5 100644
> --- a/drivers/lightnvm/core.c
> +++ b/drivers/lightnvm/core.c
> @@ -544,7 +544,7 @@ static int nvm_configure_show(const char *val)
> if (!dev->mt)
> return 0;
>
> - dev->mt->free_blocks_print(dev);
> + dev->mt->lun_info_print(dev);
>
> return 0;
> }
> diff --git a/drivers/lightnvm/gennvm.c b/drivers/lightnvm/gennvm.c
> index 43c01e0..e20e74e 100644
> --- a/drivers/lightnvm/gennvm.c
> +++ b/drivers/lightnvm/gennvm.c
> @@ -464,15 +464,24 @@ static struct nvm_lun *gennvm_get_lun(struct nvm_dev *dev, int lunid)
> return &gn->luns[lunid].vlun;
> }
>
> -static void gennvm_free_blocks_print(struct nvm_dev *dev)
> +static void gennvm_lun_info_print(struct nvm_dev *dev)
> {
> struct gen_nvm *gn = dev->mp;
> struct gen_lun *lun;
> unsigned int i;
>
> - gennvm_for_each_lun(gn, lun, i)
> - pr_info("%s: lun%8u\t%u\n",
> - dev->name, i, lun->vlun.nr_free_blocks);
> +
> + gennvm_for_each_lun(gn, lun, i) {
> + spin_lock(&lun->vlun.lock);
> +
> + pr_info("%s: lun%8u\t%u\t%u\t%u\n",
> + dev->name, i,
> + lun->vlun.nr_free_blocks,
> + lun->vlun.nr_inuse_blocks,
> + lun->vlun.nr_bad_blocks);
> +
> + spin_unlock(&lun->vlun.lock);
> + }
> }
>
> static struct nvmm_type gennvm = {
> @@ -490,7 +499,7 @@ static struct nvmm_type gennvm = {
> .erase_blk = gennvm_erase_blk,
>
> .get_lun = gennvm_get_lun,
> - .free_blocks_print = gennvm_free_blocks_print,
> + .lun_info_print = gennvm_lun_info_print,
> };
>
> static int __init gennvm_module_init(void)
> diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h
> index 76acd15..e527d67 100644
> --- a/include/linux/lightnvm.h
> +++ b/include/linux/lightnvm.h
> @@ -380,7 +380,7 @@ typedef int (nvmm_end_io_fn)(struct nvm_rq *, int);
> typedef int (nvmm_erase_blk_fn)(struct nvm_dev *, struct nvm_block *,
> unsigned long);
> typedef struct nvm_lun *(nvmm_get_lun_fn)(struct nvm_dev *, int);
> -typedef void (nvmm_free_blocks_print_fn)(struct nvm_dev *);
> +typedef void (nvmm_lun_info_print_fn)(struct nvm_dev *);
>
> struct nvmm_type {
> const char *name;
> @@ -404,7 +404,7 @@ struct nvmm_type {
> nvmm_get_lun_fn *get_lun;
>
> /* Statistics */
> - nvmm_free_blocks_print_fn *free_blocks_print;
> + nvmm_lun_info_print_fn *lun_info_print;
> struct list_head list;
> };
>
>

Thanks, applied.