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 <javier@cnexlabs.com>
Signed-off-by: Matias Bjørling <m@bjorling.me>
Signed-off-by: Jens Axboe <axboe@fb.com>
This commit is contained in:
Javier Gonzalez 2015-11-20 13:47:56 +01:00 коммит произвёл Jens Axboe
Родитель 47b3115ae7
Коммит 0b59733b95
2 изменённых файлов: 15 добавлений и 1 удалений

Просмотреть файл

@ -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.lun_id = i % dev->luns_per_chnl;
lun->vlun.chnl_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_free_blocks = dev->blks_per_lun;
lun->vlun.nr_inuse_blocks = 0;
lun->vlun.nr_bad_blocks = 0;
} }
return 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); list_move_tail(&blk->list, &lun->bb_list);
lun->vlun.nr_bad_blocks++;
} }
return 0; 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); list_move_tail(&blk->list, &lun->used_list);
blk->type = 1; blk->type = 1;
lun->vlun.nr_free_blocks--; 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++; block->id = cur_block_id++;
/* First block is reserved for device */ /* 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; continue;
}
list_add_tail(&block->list, &lun->free_list); 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; blk->type = 1;
lun->vlun.nr_free_blocks--; lun->vlun.nr_free_blocks--;
lun->vlun.nr_inuse_blocks++;
spin_unlock(&vlun->lock); spin_unlock(&vlun->lock);
out: out:
@ -283,16 +290,21 @@ static void gennvm_put_blk(struct nvm_dev *dev, struct nvm_block *blk)
case 1: case 1:
list_move_tail(&blk->list, &lun->free_list); list_move_tail(&blk->list, &lun->free_list);
lun->vlun.nr_free_blocks++; lun->vlun.nr_free_blocks++;
lun->vlun.nr_inuse_blocks--;
blk->type = 0; blk->type = 0;
break; break;
case 2: case 2:
list_move_tail(&blk->list, &lun->bb_list); list_move_tail(&blk->list, &lun->bb_list);
lun->vlun.nr_bad_blocks++;
lun->vlun.nr_inuse_blocks--;
break; break;
default: default:
WARN_ON_ONCE(1); WARN_ON_ONCE(1);
pr_err("gennvm: erroneous block type (%lu -> %u)\n", pr_err("gennvm: erroneous block type (%lu -> %u)\n",
blk->id, blk->type); blk->id, blk->type);
list_move_tail(&blk->list, &lun->bb_list); list_move_tail(&blk->list, &lun->bb_list);
lun->vlun.nr_bad_blocks++;
lun->vlun.nr_inuse_blocks--;
} }
spin_unlock(&vlun->lock); spin_unlock(&vlun->lock);

Просмотреть файл

@ -213,7 +213,9 @@ struct nvm_lun {
int lun_id; int lun_id;
int chnl_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_free_blocks; /* Number of unused blocks */
unsigned int nr_bad_blocks; /* Number of bad blocks */
struct nvm_block *blocks; struct nvm_block *blocks;
spinlock_t lock; spinlock_t lock;