[PATCH V2] lightnvm: pblk: fix mapping issue on failed writes

Subsystems: the rest

STALE2930d

5 messages, 2 authors, 2018-09-03 · open the first message on its own page

[PATCH V2] lightnvm: pblk: fix mapping issue on failed writes

From: Hans Holmberg <hidden>
Date: 2018-08-31 10:00:00

From: Hans Holmberg <redacted>

On 1.2-devices, the mapping-out of remaning sectors in the
failed-write's block can result in an infinite loop,
stalling the write pipeline, fix this.

Fixes: 6a3abf5beef6 ("lightnvm: pblk: rework write error recovery path")

Signed-off-by: Hans Holmberg <redacted>
---

Changes in V2:
	Moved the helper function pblk_next_ppa_in_blk to lightnvm core
	Renamed variable done->last in the helper function
	

 drivers/lightnvm/pblk-write.c | 10 +---------
 include/linux/lightnvm.h      | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 9 deletions(-)
diff --git a/drivers/lightnvm/pblk-write.c b/drivers/lightnvm/pblk-write.c
index 5e6df65d392c..922506d2d0a6 100644
--- a/drivers/lightnvm/pblk-write.c
+++ b/drivers/lightnvm/pblk-write.c
@@ -125,15 +125,7 @@ static void pblk_map_remaining(struct pblk *pblk, struct ppa_addr *ppa)
 		if (!test_and_set_bit(paddr, line->invalid_bitmap))
 			le32_add_cpu(line->vsc, -1);
 
-		if (geo->version == NVM_OCSSD_SPEC_12) {
-			map_ppa.ppa++;
-			if (map_ppa.g.pg == geo->num_pg)
-				done = 1;
-		} else {
-			map_ppa.m.sec++;
-			if (map_ppa.m.sec == geo->clba)
-				done = 1;
-		}
+		done = nvm_next_ppa_in_blk(geo, &map_ppa);
 	}
 
 	line->w_err_gc->has_write_err = 1;
diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h
index 09f65c6c6676..2a6cbfe1d1b4 100644
--- a/include/linux/lightnvm.h
+++ b/include/linux/lightnvm.h
@@ -593,6 +593,40 @@ static inline u32 nvm_ppa64_to_ppa32(struct nvm_dev *dev,
 	return ppa32;
 }
 
+static inline int nvm_next_ppa_in_blk(struct nvm_geo *geo, struct ppa_addr *ppa)
+{
+	int last = 0;
+
+	if (geo->version == NVM_OCSSD_SPEC_12) {
+		int sec = ppa->g.sec;
+
+		sec++;
+		if (sec == geo->ws_min) {
+			int pg = ppa->g.pg;
+
+			sec = 0;
+			pg++;
+			if (pg == geo->num_pg) {
+				int pl = ppa->g.pl;
+
+				pg = 0;
+				pl++;
+				if (pl == geo->num_pln)
+					last = 1;
+
+				ppa->g.pl = pl;
+			}
+			ppa->g.pg = pg;
+		}
+		ppa->g.sec = sec;
+	} else {
+		ppa->m.sec++;
+		if (ppa->m.sec == geo->clba)
+			last = 1;
+	}
+
+	return last;
+}
 
 typedef blk_qc_t (nvm_tgt_make_rq_fn)(struct request_queue *, struct bio *);
 typedef sector_t (nvm_tgt_capacity_fn)(void *);
-- 
2.7.4

[PATCH] lightnvm: pblk: stop recreating global caches

From: Hans Holmberg <hidden>
Date: 2018-08-31 10:00:03

From: Hans Holmberg <redacted>

Pblk should not create a set of global caches every time
a pblk instance is created. The global caches should be
made available only when there is one or more pblk instances.

This patch bundles the global caches together with a kref
keeping track of whether the caches should be available or not.

Signed-off-by: Hans Holmberg <redacted>
---
 drivers/lightnvm/pblk-init.c | 113 ++++++++++++++++++++++++++-----------------
 1 file changed, 68 insertions(+), 45 deletions(-)
diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
index 9aebdee8e4c9..e2cdd840e7d0 100644
--- a/drivers/lightnvm/pblk-init.c
+++ b/drivers/lightnvm/pblk-init.c
@@ -26,9 +26,19 @@ static unsigned int write_buffer_size;
 module_param(write_buffer_size, uint, 0644);
 MODULE_PARM_DESC(write_buffer_size, "number of entries in a write buffer");
 
-static struct kmem_cache *pblk_ws_cache, *pblk_rec_cache, *pblk_g_rq_cache,
-				*pblk_w_rq_cache;
-static DECLARE_RWSEM(pblk_lock);
+struct pblk_global_caches {
+	struct kmem_cache *ws_cache;
+	struct kmem_cache *rec_cache;
+	struct kmem_cache *g_rq_cache;
+	struct kmem_cache *w_rq_cache;
+	struct kref kref;
+};
+
+static struct pblk_global_caches caches = {
+	.kref = KREF_INIT(0)
+};
+
+static DECLARE_RWSEM(pblk_lock);	/* Protects global caches */
 struct bio_set pblk_bio_set;
 
 static int pblk_rw_io(struct request_queue *q, struct pblk *pblk,
@@ -307,53 +317,68 @@ static int pblk_set_addrf(struct pblk *pblk)
 	return 0;
 }
 
-static int pblk_init_global_caches(struct pblk *pblk)
+static int pblk_get_global_caches(void)
 {
 	down_write(&pblk_lock);
-	pblk_ws_cache = kmem_cache_create("pblk_blk_ws",
+
+	if (kref_read(&caches.kref) > 0)
+		goto caches_available;
+
+	caches.ws_cache = kmem_cache_create("pblk_blk_ws",
 				sizeof(struct pblk_line_ws), 0, 0, NULL);
-	if (!pblk_ws_cache) {
-		up_write(&pblk_lock);
-		return -ENOMEM;
-	}
+	if (!caches.ws_cache)
+		goto fail;
 
-	pblk_rec_cache = kmem_cache_create("pblk_rec",
+	caches.rec_cache = kmem_cache_create("pblk_rec",
 				sizeof(struct pblk_rec_ctx), 0, 0, NULL);
-	if (!pblk_rec_cache) {
-		kmem_cache_destroy(pblk_ws_cache);
-		up_write(&pblk_lock);
-		return -ENOMEM;
-	}
+	if (!caches.rec_cache)
+		goto fail_destroy_ws_cache;
 
-	pblk_g_rq_cache = kmem_cache_create("pblk_g_rq", pblk_g_rq_size,
+	caches.g_rq_cache = kmem_cache_create("pblk_g_rq", pblk_g_rq_size,
 				0, 0, NULL);
-	if (!pblk_g_rq_cache) {
-		kmem_cache_destroy(pblk_ws_cache);
-		kmem_cache_destroy(pblk_rec_cache);
-		up_write(&pblk_lock);
-		return -ENOMEM;
-	}
+	if (!caches.g_rq_cache)
+		goto fail_destroy_rec_cache;
 
-	pblk_w_rq_cache = kmem_cache_create("pblk_w_rq", pblk_w_rq_size,
+	caches.w_rq_cache = kmem_cache_create("pblk_w_rq", pblk_w_rq_size,
 				0, 0, NULL);
-	if (!pblk_w_rq_cache) {
-		kmem_cache_destroy(pblk_ws_cache);
-		kmem_cache_destroy(pblk_rec_cache);
-		kmem_cache_destroy(pblk_g_rq_cache);
-		up_write(&pblk_lock);
-		return -ENOMEM;
-	}
+	if (!caches.w_rq_cache)
+		goto fail_destroy_g_rq_cache;
+
+caches_available:
+	kref_get(&caches.kref);
 	up_write(&pblk_lock);
 
 	return 0;
+
+fail_destroy_g_rq_cache:
+	kmem_cache_destroy(caches.g_rq_cache);
+fail_destroy_rec_cache:
+	kmem_cache_destroy(caches.rec_cache);
+fail_destroy_ws_cache:
+	kmem_cache_destroy(caches.ws_cache);
+fail:
+	up_write(&pblk_lock);
+
+	return -ENOMEM;
 }
 
-static void pblk_free_global_caches(struct pblk *pblk)
+static void pblk_destroy_global_caches(struct kref *ref)
 {
-	kmem_cache_destroy(pblk_ws_cache);
-	kmem_cache_destroy(pblk_rec_cache);
-	kmem_cache_destroy(pblk_g_rq_cache);
-	kmem_cache_destroy(pblk_w_rq_cache);
+	struct pblk_global_caches *c;
+
+	c = container_of(ref, struct pblk_global_caches, kref);
+
+	kmem_cache_destroy(c->ws_cache);
+	kmem_cache_destroy(c->rec_cache);
+	kmem_cache_destroy(c->g_rq_cache);
+	kmem_cache_destroy(c->w_rq_cache);
+}
+
+static void pblk_put_global_caches(void)
+{
+	down_write(&pblk_lock);
+	kref_put(&caches.kref, pblk_destroy_global_caches);
+	up_write(&pblk_lock);
 }
 
 static int pblk_core_init(struct pblk *pblk)
@@ -382,7 +407,7 @@ static int pblk_core_init(struct pblk *pblk)
 	if (!pblk->pad_dist)
 		return -ENOMEM;
 
-	if (pblk_init_global_caches(pblk))
+	if (pblk_get_global_caches())
 		goto fail_free_pad_dist;
 
 	/* Internal bios can be at most the sectors signaled by the device. */
@@ -391,27 +416,27 @@ static int pblk_core_init(struct pblk *pblk)
 		goto free_global_caches;
 
 	ret = mempool_init_slab_pool(&pblk->gen_ws_pool, PBLK_GEN_WS_POOL_SIZE,
-				     pblk_ws_cache);
+				     caches.ws_cache);
 	if (ret)
 		goto free_page_bio_pool;
 
 	ret = mempool_init_slab_pool(&pblk->rec_pool, geo->all_luns,
-				     pblk_rec_cache);
+				     caches.rec_cache);
 	if (ret)
 		goto free_gen_ws_pool;
 
 	ret = mempool_init_slab_pool(&pblk->r_rq_pool, geo->all_luns,
-				     pblk_g_rq_cache);
+				     caches.g_rq_cache);
 	if (ret)
 		goto free_rec_pool;
 
 	ret = mempool_init_slab_pool(&pblk->e_rq_pool, geo->all_luns,
-				     pblk_g_rq_cache);
+				     caches.g_rq_cache);
 	if (ret)
 		goto free_r_rq_pool;
 
 	ret = mempool_init_slab_pool(&pblk->w_rq_pool, geo->all_luns,
-				     pblk_w_rq_cache);
+				     caches.w_rq_cache);
 	if (ret)
 		goto free_e_rq_pool;
 
@@ -457,7 +482,7 @@ static int pblk_core_init(struct pblk *pblk)
 free_page_bio_pool:
 	mempool_exit(&pblk->page_bio_pool);
 free_global_caches:
-	pblk_free_global_caches(pblk);
+	pblk_put_global_caches();
 fail_free_pad_dist:
 	kfree(pblk->pad_dist);
 	return -ENOMEM;
@@ -481,7 +506,7 @@ static void pblk_core_free(struct pblk *pblk)
 	mempool_exit(&pblk->e_rq_pool);
 	mempool_exit(&pblk->w_rq_pool);
 
-	pblk_free_global_caches(pblk);
+	pblk_put_global_caches();
 	kfree(pblk->pad_dist);
 }
 
@@ -1074,7 +1099,6 @@ static void pblk_exit(void *private, bool graceful)
 {
 	struct pblk *pblk = private;
 
-	down_write(&pblk_lock);
 	pblk_gc_exit(pblk, graceful);
 	pblk_tear_down(pblk, graceful);
 
@@ -1083,7 +1107,6 @@ static void pblk_exit(void *private, bool graceful)
 #endif
 
 	pblk_free(pblk);
-	up_write(&pblk_lock);
 }
 
 static sector_t pblk_capacity(void *private)
-- 
2.7.4

Re: [PATCH] lightnvm: pblk: stop recreating global caches

From: Matias Bjørling <hidden>
Date: 2018-08-31 14:14:35

On 08/31/2018 11:59 AM, Hans Holmberg wrote:
quoted hunk
From: Hans Holmberg <redacted>

Pblk should not create a set of global caches every time
a pblk instance is created. The global caches should be
made available only when there is one or more pblk instances.

This patch bundles the global caches together with a kref
keeping track of whether the caches should be available or not.

Signed-off-by: Hans Holmberg <redacted>
---
  drivers/lightnvm/pblk-init.c | 113 ++++++++++++++++++++++++++-----------------
  1 file changed, 68 insertions(+), 45 deletions(-)
diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
index 9aebdee8e4c9..e2cdd840e7d0 100644
--- a/drivers/lightnvm/pblk-init.c
+++ b/drivers/lightnvm/pblk-init.c
@@ -26,9 +26,19 @@ static unsigned int write_buffer_size;
  module_param(write_buffer_size, uint, 0644);
  MODULE_PARM_DESC(write_buffer_size, "number of entries in a write buffer");
  
-static struct kmem_cache *pblk_ws_cache, *pblk_rec_cache, *pblk_g_rq_cache,
-				*pblk_w_rq_cache;
-static DECLARE_RWSEM(pblk_lock);
+struct pblk_global_caches {
How about pblk_caches?
+	struct kmem_cache *ws_cache;
+	struct kmem_cache *rec_cache;
+	struct kmem_cache *g_rq_cache;
+	struct kmem_cache *w_rq_cache;
You can drop _cache from the names now that its implicit from the structure.
+	struct kref kref;
+};
+
+static struct pblk_global_caches caches = {
g_caches? pblk_caches?
+	.kref = KREF_INIT(0)
+};
+
+static DECLARE_RWSEM(pblk_lock);	/* Protects global caches */
pblk_caches_lock? and consider just using a semaphore, we don't need 
separate readers and writers for this.
quoted hunk
  struct bio_set pblk_bio_set;
  
  static int pblk_rw_io(struct request_queue *q, struct pblk *pblk,
@@ -307,53 +317,68 @@ static int pblk_set_addrf(struct pblk *pblk)
  	return 0;
  }
  
-static int pblk_init_global_caches(struct pblk *pblk)
+static int pblk_get_global_caches(void)
Looks like what this one does is initializing the caches. I get the 
get/put concept, but you may want to split it into two other functions. 
Such that you have

pblk_init_caches() (only called by pblk_get_caches)

and

pblk_get_caches()
{
	down(&pblk_cache_sem);
	if (kref_read(&caches.kref) > 0) {
		down(&pblk_cache_sem);
		return 0;
}

	ret = pblk_init_caches(..);
	up(&pblk_cache_sem);
	return ret;
}
quoted hunk
  {
  	down_write(&pblk_lock);
-	pblk_ws_cache = kmem_cache_create("pblk_blk_ws",
+
+	if (kref_read(&caches.kref) > 0)
+		goto caches_available;
+
+	caches.ws_cache = kmem_cache_create("pblk_blk_ws",
  				sizeof(struct pblk_line_ws), 0, 0, NULL);
-	if (!pblk_ws_cache) {
-		up_write(&pblk_lock);
-		return -ENOMEM;
-	}
+	if (!caches.ws_cache)
+		goto fail;
  
-	pblk_rec_cache = kmem_cache_create("pblk_rec",
+	caches.rec_cache = kmem_cache_create("pblk_rec",
  				sizeof(struct pblk_rec_ctx), 0, 0, NULL);
-	if (!pblk_rec_cache) {
-		kmem_cache_destroy(pblk_ws_cache);
-		up_write(&pblk_lock);
-		return -ENOMEM;
-	}
+	if (!caches.rec_cache)
+		goto fail_destroy_ws_cache;
  
-	pblk_g_rq_cache = kmem_cache_create("pblk_g_rq", pblk_g_rq_size,
+	caches.g_rq_cache = kmem_cache_create("pblk_g_rq", pblk_g_rq_size,
  				0, 0, NULL);
-	if (!pblk_g_rq_cache) {
-		kmem_cache_destroy(pblk_ws_cache);
-		kmem_cache_destroy(pblk_rec_cache);
-		up_write(&pblk_lock);
-		return -ENOMEM;
-	}
+	if (!caches.g_rq_cache)
+		goto fail_destroy_rec_cache;
  
-	pblk_w_rq_cache = kmem_cache_create("pblk_w_rq", pblk_w_rq_size,
+	caches.w_rq_cache = kmem_cache_create("pblk_w_rq", pblk_w_rq_size,
  				0, 0, NULL);
-	if (!pblk_w_rq_cache) {
-		kmem_cache_destroy(pblk_ws_cache);
-		kmem_cache_destroy(pblk_rec_cache);
-		kmem_cache_destroy(pblk_g_rq_cache);
-		up_write(&pblk_lock);
-		return -ENOMEM;
-	}
+	if (!caches.w_rq_cache)
+		goto fail_destroy_g_rq_cache;
+
+caches_available:
+	kref_get(&caches.kref);
  	up_write(&pblk_lock);
  
  	return 0;
+
+fail_destroy_g_rq_cache:
+	kmem_cache_destroy(caches.g_rq_cache);
+fail_destroy_rec_cache:
+	kmem_cache_destroy(caches.rec_cache);
+fail_destroy_ws_cache:
+	kmem_cache_destroy(caches.ws_cache);
+fail:
+	up_write(&pblk_lock);
+
+	return -ENOMEM;
  }
  
-static void pblk_free_global_caches(struct pblk *pblk)
+static void pblk_destroy_global_caches(struct kref *ref)
  {
-	kmem_cache_destroy(pblk_ws_cache);
-	kmem_cache_destroy(pblk_rec_cache);
-	kmem_cache_destroy(pblk_g_rq_cache);
-	kmem_cache_destroy(pblk_w_rq_cache);
+	struct pblk_global_caches *c;
+
+	c = container_of(ref, struct pblk_global_caches, kref);
+
+	kmem_cache_destroy(c->ws_cache);
+	kmem_cache_destroy(c->rec_cache);
+	kmem_cache_destroy(c->g_rq_cache);
+	kmem_cache_destroy(c->w_rq_cache);
+}
+
+static void pblk_put_global_caches(void)
+{
+	down_write(&pblk_lock);
+	kref_put(&caches.kref, pblk_destroy_global_caches);
+	up_write(&pblk_lock);
  }
  
  static int pblk_core_init(struct pblk *pblk)
@@ -382,7 +407,7 @@ static int pblk_core_init(struct pblk *pblk)
  	if (!pblk->pad_dist)
  		return -ENOMEM;
  
-	if (pblk_init_global_caches(pblk))
+	if (pblk_get_global_caches())
  		goto fail_free_pad_dist;
  
  	/* Internal bios can be at most the sectors signaled by the device. */
@@ -391,27 +416,27 @@ static int pblk_core_init(struct pblk *pblk)
  		goto free_global_caches;
  
  	ret = mempool_init_slab_pool(&pblk->gen_ws_pool, PBLK_GEN_WS_POOL_SIZE,
-				     pblk_ws_cache);
+				     caches.ws_cache);
  	if (ret)
  		goto free_page_bio_pool;
  
  	ret = mempool_init_slab_pool(&pblk->rec_pool, geo->all_luns,
-				     pblk_rec_cache);
+				     caches.rec_cache);
  	if (ret)
  		goto free_gen_ws_pool;
  
  	ret = mempool_init_slab_pool(&pblk->r_rq_pool, geo->all_luns,
-				     pblk_g_rq_cache);
+				     caches.g_rq_cache);
  	if (ret)
  		goto free_rec_pool;
  
  	ret = mempool_init_slab_pool(&pblk->e_rq_pool, geo->all_luns,
-				     pblk_g_rq_cache);
+				     caches.g_rq_cache);
  	if (ret)
  		goto free_r_rq_pool;
  
  	ret = mempool_init_slab_pool(&pblk->w_rq_pool, geo->all_luns,
-				     pblk_w_rq_cache);
+				     caches.w_rq_cache);
  	if (ret)
  		goto free_e_rq_pool;
  
@@ -457,7 +482,7 @@ static int pblk_core_init(struct pblk *pblk)
  free_page_bio_pool:
  	mempool_exit(&pblk->page_bio_pool);
  free_global_caches:
-	pblk_free_global_caches(pblk);
+	pblk_put_global_caches();
  fail_free_pad_dist:
  	kfree(pblk->pad_dist);
  	return -ENOMEM;
@@ -481,7 +506,7 @@ static void pblk_core_free(struct pblk *pblk)
  	mempool_exit(&pblk->e_rq_pool);
  	mempool_exit(&pblk->w_rq_pool);
  
-	pblk_free_global_caches(pblk);
+	pblk_put_global_caches();
  	kfree(pblk->pad_dist);
  }
  
@@ -1074,7 +1099,6 @@ static void pblk_exit(void *private, bool graceful)
  {
  	struct pblk *pblk = private;
  
-	down_write(&pblk_lock);
  	pblk_gc_exit(pblk, graceful);
  	pblk_tear_down(pblk, graceful);
  
@@ -1083,7 +1107,6 @@ static void pblk_exit(void *private, bool graceful)
  #endif
  
  	pblk_free(pblk);
-	up_write(&pblk_lock);
  }
  
  static sector_t pblk_capacity(void *private)

Re: [PATCH V2] lightnvm: pblk: fix mapping issue on failed writes

From: Matias Bjørling <hidden>
Date: 2018-08-31 14:18:19

On 08/31/2018 11:59 AM, Hans Holmberg wrote:
quoted hunk
From: Hans Holmberg <redacted>

On 1.2-devices, the mapping-out of remaning sectors in the
failed-write's block can result in an infinite loop,
stalling the write pipeline, fix this.

Fixes: 6a3abf5beef6 ("lightnvm: pblk: rework write error recovery path")

Signed-off-by: Hans Holmberg <redacted>
---

Changes in V2:
	Moved the helper function pblk_next_ppa_in_blk to lightnvm core
	Renamed variable done->last in the helper function
	

  drivers/lightnvm/pblk-write.c | 10 +---------
  include/linux/lightnvm.h      | 34 ++++++++++++++++++++++++++++++++++
  2 files changed, 35 insertions(+), 9 deletions(-)
diff --git a/drivers/lightnvm/pblk-write.c b/drivers/lightnvm/pblk-write.c
index 5e6df65d392c..922506d2d0a6 100644
--- a/drivers/lightnvm/pblk-write.c
+++ b/drivers/lightnvm/pblk-write.c
@@ -125,15 +125,7 @@ static void pblk_map_remaining(struct pblk *pblk, struct ppa_addr *ppa)
  		if (!test_and_set_bit(paddr, line->invalid_bitmap))
  			le32_add_cpu(line->vsc, -1);
  
-		if (geo->version == NVM_OCSSD_SPEC_12) {
-			map_ppa.ppa++;
-			if (map_ppa.g.pg == geo->num_pg)
-				done = 1;
-		} else {
-			map_ppa.m.sec++;
-			if (map_ppa.m.sec == geo->clba)
-				done = 1;
-		}
+		done = nvm_next_ppa_in_blk(geo, &map_ppa);
  	}
  
  	line->w_err_gc->has_write_err = 1;
diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h
index 09f65c6c6676..2a6cbfe1d1b4 100644
--- a/include/linux/lightnvm.h
+++ b/include/linux/lightnvm.h
@@ -593,6 +593,40 @@ static inline u32 nvm_ppa64_to_ppa32(struct nvm_dev *dev,
  	return ppa32;
  }
  
+static inline int nvm_next_ppa_in_blk(struct nvm_geo *geo, struct ppa_addr *ppa)
You can pass nvm_tgt_dev here. Then the two unfoldings in 
pblk_map_remaining are not needed.

The naming sounds very 1.2ish, how about nvm_get_next_lba_in_chk?
+{
+	int last = 0;
+
+	if (geo->version == NVM_OCSSD_SPEC_12) {
+		int sec = ppa->g.sec;
+
+		sec++;
+		if (sec == geo->ws_min) {
+			int pg = ppa->g.pg;
+
+			sec = 0;
+			pg++;
+			if (pg == geo->num_pg) {
+				int pl = ppa->g.pl;
+
+				pg = 0;
+				pl++;
+				if (pl == geo->num_pln)
+					last = 1;
+
+				ppa->g.pl = pl;
+			}
+			ppa->g.pg = pg;
+		}
+		ppa->g.sec = sec;
+	} else {
+		ppa->m.sec++;
+		if (ppa->m.sec == geo->clba)
+			last = 1;
+	}
+
+	return last;
+}
  
  typedef blk_qc_t (nvm_tgt_make_rq_fn)(struct request_queue *, struct bio *);
  typedef sector_t (nvm_tgt_capacity_fn)(void *);

Re: [PATCH V2] lightnvm: pblk: fix mapping issue on failed writes

From: Hans Holmberg <hidden>
Date: 2018-09-03 07:57:06

On Fri, Aug 31, 2018 at 4:18 PM Matias Bj=C3=B8rling [off-list ref] wrote=
:
On 08/31/2018 11:59 AM, Hans Holmberg wrote:
quoted
From: Hans Holmberg <redacted>

On 1.2-devices, the mapping-out of remaning sectors in the
failed-write's block can result in an infinite loop,
stalling the write pipeline, fix this.

Fixes: 6a3abf5beef6 ("lightnvm: pblk: rework write error recovery path"=
)
quoted
Signed-off-by: Hans Holmberg <redacted>
---

Changes in V2:
      Moved the helper function pblk_next_ppa_in_blk to lightnvm core
      Renamed variable done->last in the helper function


  drivers/lightnvm/pblk-write.c | 10 +---------
  include/linux/lightnvm.h      | 34 ++++++++++++++++++++++++++++++++++
  2 files changed, 35 insertions(+), 9 deletions(-)
diff --git a/drivers/lightnvm/pblk-write.c b/drivers/lightnvm/pblk-writ=
e.c
quoted
index 5e6df65d392c..922506d2d0a6 100644
--- a/drivers/lightnvm/pblk-write.c
+++ b/drivers/lightnvm/pblk-write.c
@@ -125,15 +125,7 @@ static void pblk_map_remaining(struct pblk *pblk, =
struct ppa_addr *ppa)
quoted
              if (!test_and_set_bit(paddr, line->invalid_bitmap))
                      le32_add_cpu(line->vsc, -1);

-             if (geo->version =3D=3D NVM_OCSSD_SPEC_12) {
-                     map_ppa.ppa++;
-                     if (map_ppa.g.pg =3D=3D geo->num_pg)
-                             done =3D 1;
-             } else {
-                     map_ppa.m.sec++;
-                     if (map_ppa.m.sec =3D=3D geo->clba)
-                             done =3D 1;
-             }
+             done =3D nvm_next_ppa_in_blk(geo, &map_ppa);
      }

      line->w_err_gc->has_write_err =3D 1;
diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h
index 09f65c6c6676..2a6cbfe1d1b4 100644
--- a/include/linux/lightnvm.h
+++ b/include/linux/lightnvm.h
@@ -593,6 +593,40 @@ static inline u32 nvm_ppa64_to_ppa32(struct nvm_de=
v *dev,
quoted
      return ppa32;
  }

+static inline int nvm_next_ppa_in_blk(struct nvm_geo *geo, struct ppa_=
addr *ppa)
You can pass nvm_tgt_dev here. Then the two unfoldings in
pblk_map_remaining are not needed.
Yeah. thats better. fixed.
The naming sounds very 1.2ish, how about nvm_get_next_lba_in_chk?
I used blk because in the generic ppa format (ppa_addr.a), the name is blk.
Chunk is more abstract concept so i think it's better using that going forw=
ard.
Fixed.
quoted
+{
+     int last =3D 0;
+
+     if (geo->version =3D=3D NVM_OCSSD_SPEC_12) {
+             int sec =3D ppa->g.sec;
+
+             sec++;
+             if (sec =3D=3D geo->ws_min) {
+                     int pg =3D ppa->g.pg;
+
+                     sec =3D 0;
+                     pg++;
+                     if (pg =3D=3D geo->num_pg) {
+                             int pl =3D ppa->g.pl;
+
+                             pg =3D 0;
+                             pl++;
+                             if (pl =3D=3D geo->num_pln)
+                                     last =3D 1;
+
+                             ppa->g.pl =3D pl;
+                     }
+                     ppa->g.pg =3D pg;
+             }
+             ppa->g.sec =3D sec;
+     } else {
+             ppa->m.sec++;
+             if (ppa->m.sec =3D=3D geo->clba)
+                     last =3D 1;
+     }
+
+     return last;
+}

  typedef blk_qc_t (nvm_tgt_make_rq_fn)(struct request_queue *, struct =
bio *);
quoted
  typedef sector_t (nvm_tgt_capacity_fn)(void *);
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help