diff mbox

[9/9] lightnvm: pblk: correct valid lba count calculation

Message ID 1507025113-13351-10-git-send-email-hans.ml.holmberg@owltronix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Hans Holmberg Oct. 3, 2017, 10:05 a.m. UTC
From: Hans Holmberg <hans.holmberg@cnexlabs.com>

During garbage collect, lbas being written can end up
being invalidated. Make sure that this is reflected in
the valid lba count.

Signed-off-by: Hans Holmberg <hans.holmberg@cnexlabs.com>
---
 drivers/lightnvm/pblk-map.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

=?UTF-8?q?Javier=20Gonz=C3=A1lez?= Oct. 3, 2017, 10:41 a.m. UTC | #1
> On 3 Oct 2017, at 12.05, Hans Holmberg <hans.ml.holmberg@owltronix.com> wrote:
> 
> From: Hans Holmberg <hans.holmberg@cnexlabs.com>
> 
> During garbage collect, lbas being written can end up
> being invalidated. Make sure that this is reflected in
> the valid lba count.
> 
> Signed-off-by: Hans Holmberg <hans.holmberg@cnexlabs.com>
> ---
> drivers/lightnvm/pblk-map.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/lightnvm/pblk-map.c b/drivers/lightnvm/pblk-map.c
> index 3bc4c94..6f3ecde 100644
> --- a/drivers/lightnvm/pblk-map.c
> +++ b/drivers/lightnvm/pblk-map.c
> @@ -45,6 +45,8 @@ static void pblk_map_page_data(struct pblk *pblk, unsigned int sentry,
> 	paddr = pblk_alloc_page(pblk, line, nr_secs);
> 
> 	for (i = 0; i < nr_secs; i++, paddr++) {
> +		__le64 addr_empty = cpu_to_le64(ADDR_EMPTY);
> +
> 		/* ppa to be sent to the device */
> 		ppa_list[i] = addr_to_gen_ppa(pblk, paddr, line->id);
> 
> @@ -61,10 +63,9 @@ static void pblk_map_page_data(struct pblk *pblk, unsigned int sentry,
> 			w_ctx->ppa = ppa_list[i];
> 			meta_list[i].lba = cpu_to_le64(w_ctx->lba);
> 			lba_list[paddr] = cpu_to_le64(w_ctx->lba);
> -			line->nr_valid_lbas++;
> +			if (lba_list[paddr] != addr_empty)
> +				line->nr_valid_lbas++;
> 		} else {
> -			__le64 addr_empty = cpu_to_le64(ADDR_EMPTY);
> -
> 			lba_list[paddr] = meta_list[i].lba = addr_empty;
> 			__pblk_map_invalidate(pblk, line, paddr);
> 		}
> --
> 2.7.4

LGTM.

Reviewed-by: Javier González <javier@cnexlabs.com>
diff mbox

Patch

diff --git a/drivers/lightnvm/pblk-map.c b/drivers/lightnvm/pblk-map.c
index 3bc4c94..6f3ecde 100644
--- a/drivers/lightnvm/pblk-map.c
+++ b/drivers/lightnvm/pblk-map.c
@@ -45,6 +45,8 @@  static void pblk_map_page_data(struct pblk *pblk, unsigned int sentry,
 	paddr = pblk_alloc_page(pblk, line, nr_secs);
 
 	for (i = 0; i < nr_secs; i++, paddr++) {
+		__le64 addr_empty = cpu_to_le64(ADDR_EMPTY);
+
 		/* ppa to be sent to the device */
 		ppa_list[i] = addr_to_gen_ppa(pblk, paddr, line->id);
 
@@ -61,10 +63,9 @@  static void pblk_map_page_data(struct pblk *pblk, unsigned int sentry,
 			w_ctx->ppa = ppa_list[i];
 			meta_list[i].lba = cpu_to_le64(w_ctx->lba);
 			lba_list[paddr] = cpu_to_le64(w_ctx->lba);
-			line->nr_valid_lbas++;
+			if (lba_list[paddr] != addr_empty)
+				line->nr_valid_lbas++;
 		} else {
-			__le64 addr_empty = cpu_to_le64(ADDR_EMPTY);
-
 			lba_list[paddr] = meta_list[i].lba = addr_empty;
 			__pblk_map_invalidate(pblk, line, paddr);
 		}