Re: [PATCH 01/20] lightnvm: simplify geometry structure.

2018-02-22 Thread Javier Gonzalez
> On 22 Feb 2018, at 13.22, Matias Bjørling  wrote:
> 
> On 02/22/2018 08:44 AM, Javier Gonzalez wrote:
>>> On 22 Feb 2018, at 08.25, Matias Bjørling  wrote:
>>> 
>>> On 02/21/2018 10:26 AM, Javier González wrote:
 Currently, the device geometry is stored redundantly in the nvm_id and
 nvm_geo structures at a device level. Moreover, when instantiating
 targets on a specific number of LUNs, these structures are replicated
 and manually modified to fit the instance channel and LUN partitioning.
 Instead, create a generic geometry around two base structures:
 nvm_dev_geo, which describes the geometry of the whole device and
 nvm_geo, which describes the geometry of the instance. Since these share
 a big part of the geometry, create a nvm_common_geo structure that keeps
 the static geoometry values that are shared across instances.
 As we introduce support for 2.0, these structures allow to abstract
 spec. specific values and present a common geometry to targets.
 Signed-off-by: Javier González 
 ---
  drivers/lightnvm/core.c  | 137 +++-
  drivers/lightnvm/pblk-core.c |  16 +-
  drivers/lightnvm/pblk-gc.c   |   2 +-
  drivers/lightnvm/pblk-init.c | 123 +++---
  drivers/lightnvm/pblk-read.c |   2 +-
  drivers/lightnvm/pblk-recovery.c |  14 +-
  drivers/lightnvm/pblk-rl.c   |   2 +-
  drivers/lightnvm/pblk-sysfs.c|  39 +++--
  drivers/lightnvm/pblk-write.c|   2 +-
  drivers/lightnvm/pblk.h  |  93 +--
  drivers/nvme/host/lightnvm.c | 339 
 +++
  include/linux/lightnvm.h | 204 ---
  12 files changed, 514 insertions(+), 459 deletions(-)
 diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
 index 689c97b97775..42596afdf64c 100644
 --- a/drivers/lightnvm/core.c
 +++ b/drivers/lightnvm/core.c
 @@ -111,6 +111,7 @@ static void nvm_release_luns_err(struct nvm_dev *dev, 
 int lun_begin,
  static void nvm_remove_tgt_dev(struct nvm_tgt_dev *tgt_dev, int clear)
  {
struct nvm_dev *dev = tgt_dev->parent;
 +  struct nvm_dev_geo *dev_geo = &dev->dev_geo;
struct nvm_dev_map *dev_map = tgt_dev->map;
int i, j;
  @@ -122,7 +123,7 @@ static void nvm_remove_tgt_dev(struct nvm_tgt_dev 
 *tgt_dev, int clear)
if (clear) {
for (j = 0; j < ch_map->nr_luns; j++) {
int lun = j + lun_offs[j];
 -  int lunid = (ch * dev->geo.nr_luns) + lun;
 +  int lunid = (ch * dev_geo->nr_luns) + lun;
WARN_ON(!test_and_clear_bit(lunid,
dev->lun_map));
 @@ -143,19 +144,20 @@ static struct nvm_tgt_dev *nvm_create_tgt_dev(struct 
 nvm_dev *dev,
  u16 lun_begin, u16 lun_end,
  u16 op)
  {
 +  struct nvm_dev_geo *dev_geo = &dev->dev_geo;
struct nvm_tgt_dev *tgt_dev = NULL;
struct nvm_dev_map *dev_rmap = dev->rmap;
struct nvm_dev_map *dev_map;
struct ppa_addr *luns;
int nr_luns = lun_end - lun_begin + 1;
int luns_left = nr_luns;
 -  int nr_chnls = nr_luns / dev->geo.nr_luns;
 -  int nr_chnls_mod = nr_luns % dev->geo.nr_luns;
 -  int bch = lun_begin / dev->geo.nr_luns;
 -  int blun = lun_begin % dev->geo.nr_luns;
 +  int nr_chnls = nr_luns / dev_geo->nr_luns;
 +  int nr_chnls_mod = nr_luns % dev_geo->nr_luns;
 +  int bch = lun_begin / dev_geo->nr_luns;
 +  int blun = lun_begin % dev_geo->nr_luns;
int lunid = 0;
int lun_balanced = 1;
 -  int prev_nr_luns;
 +  int sec_per_lun, prev_nr_luns;
int i, j;
nr_chnls = (nr_chnls_mod == 0) ? nr_chnls : nr_chnls + 1;
 @@ -173,15 +175,15 @@ static struct nvm_tgt_dev *nvm_create_tgt_dev(struct 
 nvm_dev *dev,
if (!luns)
goto err_luns;
  - prev_nr_luns = (luns_left > dev->geo.nr_luns) ?
 -  dev->geo.nr_luns : luns_left;
 +  prev_nr_luns = (luns_left > dev_geo->nr_luns) ?
 +  dev_geo->nr_luns : luns_left;
for (i = 0; i < nr_chnls; i++) {
struct nvm_ch_map *ch_rmap = &dev_rmap->chnls[i + bch];
int *lun_roffs = ch_rmap->lun_offs;
struct nvm_ch_map *ch_map = &dev_map->chnls[i];
int *lun_offs;
 -  int luns_in_chnl = (luns_left > dev->geo.nr_luns) ?
 -  dev->geo.nr_luns : luns_left;
 +  int luns_in_chnl = (luns_left > dev_geo->nr_luns) ?
 +  dev_geo->nr_luns : luns_left;
  

Re: [PATCH 01/20] lightnvm: simplify geometry structure.

2018-02-22 Thread Matias Bjørling

On 02/22/2018 08:44 AM, Javier Gonzalez wrote:



On 22 Feb 2018, at 08.25, Matias Bjørling  wrote:

On 02/21/2018 10:26 AM, Javier González wrote:

Currently, the device geometry is stored redundantly in the nvm_id and
nvm_geo structures at a device level. Moreover, when instantiating
targets on a specific number of LUNs, these structures are replicated
and manually modified to fit the instance channel and LUN partitioning.
Instead, create a generic geometry around two base structures:
nvm_dev_geo, which describes the geometry of the whole device and
nvm_geo, which describes the geometry of the instance. Since these share
a big part of the geometry, create a nvm_common_geo structure that keeps
the static geoometry values that are shared across instances.
As we introduce support for 2.0, these structures allow to abstract
spec. specific values and present a common geometry to targets.
Signed-off-by: Javier González 
---
  drivers/lightnvm/core.c  | 137 +++-
  drivers/lightnvm/pblk-core.c |  16 +-
  drivers/lightnvm/pblk-gc.c   |   2 +-
  drivers/lightnvm/pblk-init.c | 123 +++---
  drivers/lightnvm/pblk-read.c |   2 +-
  drivers/lightnvm/pblk-recovery.c |  14 +-
  drivers/lightnvm/pblk-rl.c   |   2 +-
  drivers/lightnvm/pblk-sysfs.c|  39 +++--
  drivers/lightnvm/pblk-write.c|   2 +-
  drivers/lightnvm/pblk.h  |  93 +--
  drivers/nvme/host/lightnvm.c | 339 +++
  include/linux/lightnvm.h | 204 ---
  12 files changed, 514 insertions(+), 459 deletions(-)
diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index 689c97b97775..42596afdf64c 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -111,6 +111,7 @@ static void nvm_release_luns_err(struct nvm_dev *dev, int 
lun_begin,
  static void nvm_remove_tgt_dev(struct nvm_tgt_dev *tgt_dev, int clear)
  {
struct nvm_dev *dev = tgt_dev->parent;
+   struct nvm_dev_geo *dev_geo = &dev->dev_geo;
struct nvm_dev_map *dev_map = tgt_dev->map;
int i, j;
  @@ -122,7 +123,7 @@ static void nvm_remove_tgt_dev(struct nvm_tgt_dev 
*tgt_dev, int clear)
if (clear) {
for (j = 0; j < ch_map->nr_luns; j++) {
int lun = j + lun_offs[j];
-   int lunid = (ch * dev->geo.nr_luns) + lun;
+   int lunid = (ch * dev_geo->nr_luns) + lun;
WARN_ON(!test_and_clear_bit(lunid,
dev->lun_map));
@@ -143,19 +144,20 @@ static struct nvm_tgt_dev *nvm_create_tgt_dev(struct 
nvm_dev *dev,
  u16 lun_begin, u16 lun_end,
  u16 op)
  {
+   struct nvm_dev_geo *dev_geo = &dev->dev_geo;
struct nvm_tgt_dev *tgt_dev = NULL;
struct nvm_dev_map *dev_rmap = dev->rmap;
struct nvm_dev_map *dev_map;
struct ppa_addr *luns;
int nr_luns = lun_end - lun_begin + 1;
int luns_left = nr_luns;
-   int nr_chnls = nr_luns / dev->geo.nr_luns;
-   int nr_chnls_mod = nr_luns % dev->geo.nr_luns;
-   int bch = lun_begin / dev->geo.nr_luns;
-   int blun = lun_begin % dev->geo.nr_luns;
+   int nr_chnls = nr_luns / dev_geo->nr_luns;
+   int nr_chnls_mod = nr_luns % dev_geo->nr_luns;
+   int bch = lun_begin / dev_geo->nr_luns;
+   int blun = lun_begin % dev_geo->nr_luns;
int lunid = 0;
int lun_balanced = 1;
-   int prev_nr_luns;
+   int sec_per_lun, prev_nr_luns;
int i, j;
nr_chnls = (nr_chnls_mod == 0) ? nr_chnls : nr_chnls + 1;
@@ -173,15 +175,15 @@ static struct nvm_tgt_dev *nvm_create_tgt_dev(struct 
nvm_dev *dev,
if (!luns)
goto err_luns;
  - prev_nr_luns = (luns_left > dev->geo.nr_luns) ?
-   dev->geo.nr_luns : luns_left;
+   prev_nr_luns = (luns_left > dev_geo->nr_luns) ?
+   dev_geo->nr_luns : luns_left;
for (i = 0; i < nr_chnls; i++) {
struct nvm_ch_map *ch_rmap = &dev_rmap->chnls[i + bch];
int *lun_roffs = ch_rmap->lun_offs;
struct nvm_ch_map *ch_map = &dev_map->chnls[i];
int *lun_offs;
-   int luns_in_chnl = (luns_left > dev->geo.nr_luns) ?
-   dev->geo.nr_luns : luns_left;
+   int luns_in_chnl = (luns_left > dev_geo->nr_luns) ?
+   dev_geo->nr_luns : luns_left;
if (lun_balanced && prev_nr_luns != luns_in_chnl)
lun_balanced = 0;
@@ -215,18 +217,22 @@ static struct nvm_tgt_dev *nvm_create_tgt_dev(struct 
nvm_dev *dev,
if (!tgt_dev)
goto err_ch;
  - memcpy(&tgt_dev->geo, &dev->geo, sizeof

Re: [PATCH 01/20] lightnvm: simplify geometry structure.

2018-02-21 Thread Javier Gonzalez

> On 22 Feb 2018, at 08.25, Matias Bjørling  wrote:
> 
> On 02/21/2018 10:26 AM, Javier González wrote:
>> Currently, the device geometry is stored redundantly in the nvm_id and
>> nvm_geo structures at a device level. Moreover, when instantiating
>> targets on a specific number of LUNs, these structures are replicated
>> and manually modified to fit the instance channel and LUN partitioning.
>> Instead, create a generic geometry around two base structures:
>> nvm_dev_geo, which describes the geometry of the whole device and
>> nvm_geo, which describes the geometry of the instance. Since these share
>> a big part of the geometry, create a nvm_common_geo structure that keeps
>> the static geoometry values that are shared across instances.
>> As we introduce support for 2.0, these structures allow to abstract
>> spec. specific values and present a common geometry to targets.
>> Signed-off-by: Javier González 
>> ---
>>  drivers/lightnvm/core.c  | 137 +++-
>>  drivers/lightnvm/pblk-core.c |  16 +-
>>  drivers/lightnvm/pblk-gc.c   |   2 +-
>>  drivers/lightnvm/pblk-init.c | 123 +++---
>>  drivers/lightnvm/pblk-read.c |   2 +-
>>  drivers/lightnvm/pblk-recovery.c |  14 +-
>>  drivers/lightnvm/pblk-rl.c   |   2 +-
>>  drivers/lightnvm/pblk-sysfs.c|  39 +++--
>>  drivers/lightnvm/pblk-write.c|   2 +-
>>  drivers/lightnvm/pblk.h  |  93 +--
>>  drivers/nvme/host/lightnvm.c | 339 
>> +++
>>  include/linux/lightnvm.h | 204 ---
>>  12 files changed, 514 insertions(+), 459 deletions(-)
>> diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
>> index 689c97b97775..42596afdf64c 100644
>> --- a/drivers/lightnvm/core.c
>> +++ b/drivers/lightnvm/core.c
>> @@ -111,6 +111,7 @@ static void nvm_release_luns_err(struct nvm_dev *dev, 
>> int lun_begin,
>>  static void nvm_remove_tgt_dev(struct nvm_tgt_dev *tgt_dev, int clear)
>>  {
>>  struct nvm_dev *dev = tgt_dev->parent;
>> +struct nvm_dev_geo *dev_geo = &dev->dev_geo;
>>  struct nvm_dev_map *dev_map = tgt_dev->map;
>>  int i, j;
>>  @@ -122,7 +123,7 @@ static void nvm_remove_tgt_dev(struct nvm_tgt_dev 
>> *tgt_dev, int clear)
>>  if (clear) {
>>  for (j = 0; j < ch_map->nr_luns; j++) {
>>  int lun = j + lun_offs[j];
>> -int lunid = (ch * dev->geo.nr_luns) + lun;
>> +int lunid = (ch * dev_geo->nr_luns) + lun;
>>  WARN_ON(!test_and_clear_bit(lunid,
>>  dev->lun_map));
>> @@ -143,19 +144,20 @@ static struct nvm_tgt_dev *nvm_create_tgt_dev(struct 
>> nvm_dev *dev,
>>u16 lun_begin, u16 lun_end,
>>u16 op)
>>  {
>> +struct nvm_dev_geo *dev_geo = &dev->dev_geo;
>>  struct nvm_tgt_dev *tgt_dev = NULL;
>>  struct nvm_dev_map *dev_rmap = dev->rmap;
>>  struct nvm_dev_map *dev_map;
>>  struct ppa_addr *luns;
>>  int nr_luns = lun_end - lun_begin + 1;
>>  int luns_left = nr_luns;
>> -int nr_chnls = nr_luns / dev->geo.nr_luns;
>> -int nr_chnls_mod = nr_luns % dev->geo.nr_luns;
>> -int bch = lun_begin / dev->geo.nr_luns;
>> -int blun = lun_begin % dev->geo.nr_luns;
>> +int nr_chnls = nr_luns / dev_geo->nr_luns;
>> +int nr_chnls_mod = nr_luns % dev_geo->nr_luns;
>> +int bch = lun_begin / dev_geo->nr_luns;
>> +int blun = lun_begin % dev_geo->nr_luns;
>>  int lunid = 0;
>>  int lun_balanced = 1;
>> -int prev_nr_luns;
>> +int sec_per_lun, prev_nr_luns;
>>  int i, j;
>>  nr_chnls = (nr_chnls_mod == 0) ? nr_chnls : nr_chnls + 1;
>> @@ -173,15 +175,15 @@ static struct nvm_tgt_dev *nvm_create_tgt_dev(struct 
>> nvm_dev *dev,
>>  if (!luns)
>>  goto err_luns;
>>  -   prev_nr_luns = (luns_left > dev->geo.nr_luns) ?
>> -dev->geo.nr_luns : luns_left;
>> +prev_nr_luns = (luns_left > dev_geo->nr_luns) ?
>> +dev_geo->nr_luns : luns_left;
>>  for (i = 0; i < nr_chnls; i++) {
>>  struct nvm_ch_map *ch_rmap = &dev_rmap->chnls[i + bch];
>>  int *lun_roffs = ch_rmap->lun_offs;
>>  struct nvm_ch_map *ch_map = &dev_map->chnls[i];
>>  int *lun_offs;
>> -int luns_in_chnl = (luns_left > dev->geo.nr_luns) ?
>> -dev->geo.nr_luns : luns_left;
>> +int luns_in_chnl = (luns_left > dev_geo->nr_luns) ?
>> +dev_geo->nr_luns : luns_left;
>>  if (lun_balanced && prev_nr_luns != luns_in_chnl)
>>  lun_balanced = 0;
>> @@ -215,18 +217,22 @@ static struct nvm_tgt_dev *nvm_create_tgt_dev(struct 
>> nvm_dev *dev,
>>  if (!tgt_dev)
>>   

Re: [PATCH 01/20] lightnvm: simplify geometry structure.

2018-02-21 Thread Matias Bjørling

On 02/21/2018 10:26 AM, Javier González wrote:

Currently, the device geometry is stored redundantly in the nvm_id and
nvm_geo structures at a device level. Moreover, when instantiating
targets on a specific number of LUNs, these structures are replicated
and manually modified to fit the instance channel and LUN partitioning.

Instead, create a generic geometry around two base structures:
nvm_dev_geo, which describes the geometry of the whole device and
nvm_geo, which describes the geometry of the instance. Since these share
a big part of the geometry, create a nvm_common_geo structure that keeps
the static geoometry values that are shared across instances.

As we introduce support for 2.0, these structures allow to abstract
spec. specific values and present a common geometry to targets.

Signed-off-by: Javier González 
---
  drivers/lightnvm/core.c  | 137 +++-
  drivers/lightnvm/pblk-core.c |  16 +-
  drivers/lightnvm/pblk-gc.c   |   2 +-
  drivers/lightnvm/pblk-init.c | 123 +++---
  drivers/lightnvm/pblk-read.c |   2 +-
  drivers/lightnvm/pblk-recovery.c |  14 +-
  drivers/lightnvm/pblk-rl.c   |   2 +-
  drivers/lightnvm/pblk-sysfs.c|  39 +++--
  drivers/lightnvm/pblk-write.c|   2 +-
  drivers/lightnvm/pblk.h  |  93 +--
  drivers/nvme/host/lightnvm.c | 339 +++
  include/linux/lightnvm.h | 204 ---
  12 files changed, 514 insertions(+), 459 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index 689c97b97775..42596afdf64c 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -111,6 +111,7 @@ static void nvm_release_luns_err(struct nvm_dev *dev, int 
lun_begin,
  static void nvm_remove_tgt_dev(struct nvm_tgt_dev *tgt_dev, int clear)
  {
struct nvm_dev *dev = tgt_dev->parent;
+   struct nvm_dev_geo *dev_geo = &dev->dev_geo;
struct nvm_dev_map *dev_map = tgt_dev->map;
int i, j;
  
@@ -122,7 +123,7 @@ static void nvm_remove_tgt_dev(struct nvm_tgt_dev *tgt_dev, int clear)

if (clear) {
for (j = 0; j < ch_map->nr_luns; j++) {
int lun = j + lun_offs[j];
-   int lunid = (ch * dev->geo.nr_luns) + lun;
+   int lunid = (ch * dev_geo->nr_luns) + lun;
  
  WARN_ON(!test_and_clear_bit(lunid,

dev->lun_map));
@@ -143,19 +144,20 @@ static struct nvm_tgt_dev *nvm_create_tgt_dev(struct 
nvm_dev *dev,
  u16 lun_begin, u16 lun_end,
  u16 op)
  {
+   struct nvm_dev_geo *dev_geo = &dev->dev_geo;
struct nvm_tgt_dev *tgt_dev = NULL;
struct nvm_dev_map *dev_rmap = dev->rmap;
struct nvm_dev_map *dev_map;
struct ppa_addr *luns;
int nr_luns = lun_end - lun_begin + 1;
int luns_left = nr_luns;
-   int nr_chnls = nr_luns / dev->geo.nr_luns;
-   int nr_chnls_mod = nr_luns % dev->geo.nr_luns;
-   int bch = lun_begin / dev->geo.nr_luns;
-   int blun = lun_begin % dev->geo.nr_luns;
+   int nr_chnls = nr_luns / dev_geo->nr_luns;
+   int nr_chnls_mod = nr_luns % dev_geo->nr_luns;
+   int bch = lun_begin / dev_geo->nr_luns;
+   int blun = lun_begin % dev_geo->nr_luns;
int lunid = 0;
int lun_balanced = 1;
-   int prev_nr_luns;
+   int sec_per_lun, prev_nr_luns;
int i, j;
  
  	nr_chnls = (nr_chnls_mod == 0) ? nr_chnls : nr_chnls + 1;

@@ -173,15 +175,15 @@ static struct nvm_tgt_dev *nvm_create_tgt_dev(struct 
nvm_dev *dev,
if (!luns)
goto err_luns;
  
-	prev_nr_luns = (luns_left > dev->geo.nr_luns) ?

-   dev->geo.nr_luns : luns_left;
+   prev_nr_luns = (luns_left > dev_geo->nr_luns) ?
+   dev_geo->nr_luns : luns_left;
for (i = 0; i < nr_chnls; i++) {
struct nvm_ch_map *ch_rmap = &dev_rmap->chnls[i + bch];
int *lun_roffs = ch_rmap->lun_offs;
struct nvm_ch_map *ch_map = &dev_map->chnls[i];
int *lun_offs;
-   int luns_in_chnl = (luns_left > dev->geo.nr_luns) ?
-   dev->geo.nr_luns : luns_left;
+   int luns_in_chnl = (luns_left > dev_geo->nr_luns) ?
+   dev_geo->nr_luns : luns_left;
  
  		if (lun_balanced && prev_nr_luns != luns_in_chnl)

lun_balanced = 0;
@@ -215,18 +217,22 @@ static struct nvm_tgt_dev *nvm_create_tgt_dev(struct 
nvm_dev *dev,
if (!tgt_dev)
goto err_ch;
  
-	memcpy(&tgt_dev->geo, &dev->geo, sizeof(struct nvm_geo));

/* Target device only owns a portion of the physical device */
tgt_dev->geo.nr_chnls = nr_chnls;