lightnvm updates for 4.18
Hi Jens,
Please pick up the following patches.
Changes since v2:
Rebased write error recovery patch on top of latest for-4.18/block
Added (missed the first round)
lightnvm: pblk: only try to recover lines with written smeta
lightnvm: pblk: kick writer on new flush points
lightnvm: pblk: take bitmap alloc. out of critical section
Changes since v1:
Removed
lightnvm: pblk: sync RB and RL states during GC
lightnvm: error handling when whole line is bad
lightnvm: pblk: handle case when mw_cunits equals to 0
Added
lightnvm: pblk: remove unnecessary bio_get/put
Thanks!
Hans Holmberg (5):
lightnvm: pblk: rework write error recovery path
lightnvm: pblk: garbage collect lines with failed writes
lightnvm: pblk: fix smeta write error path
lightnvm: pblk: only try to recover lines with written smeta
lightnvm: pblk: kick writer on new flush points
Igor Konopko (2):
lightnvm: proper error handling for pblk_bio_add_pages
lightnvm: fix partial read error path
Javier González (2):
lightnvm: pblk: remove unnecessary bio_get/put
lightnvm: pblk: take bitmap alloc. out of critical section
Marcin Dziegielewski (1):
lightnvm: pblk: add possibility to set write buffer size manually
drivers/lightnvm/pblk-cache.c | 10 +- drivers/lightnvm/pblk-core.c | 157 +++++++++++++++------- drivers/lightnvm/pblk-gc.c | 102 ++++++++------ drivers/lightnvm/pblk-init.c | 62 ++++++--- drivers/lightnvm/pblk-rb.c | 43 +----- drivers/lightnvm/pblk-read.c | 69 +++++----- drivers/lightnvm/pblk-recovery.c | 121 +++-------------- drivers/lightnvm/pblk-rl.c | 29 +++- drivers/lightnvm/pblk-sysfs.c | 15 ++- drivers/lightnvm/pblk-write.c | 281 +++++++++++++++++++++++++-------------- drivers/lightnvm/pblk.h | 37 ++++-- 11 files changed, 524 insertions(+), 402 deletions(-)
Signature · 1 line
2.11.0
[GIT PULL 01/10] lightnvm: pblk: rework write error recovery path
From: Hans Holmberg <[email protected]>
The write error recovery path is incomplete, so rework the write error recovery handling to do resubmits directly from the write buffer.
When a write error occurs, the remaining sectors in the chunk are mapped out and invalidated and the request inserted in a resubmit list.
The writer thread checks if there are any requests to resubmit, scans and invalidates any lbas that have been overwritten by later writes and resubmits the failed entries.
--- drivers/lightnvm/pblk-init.c | 2 + drivers/lightnvm/pblk-rb.c | 39 ------ drivers/lightnvm/pblk-recovery.c | 91 ------------- drivers/lightnvm/pblk-write.c | 279 +++++++++++++++++++++++++-------------- drivers/lightnvm/pblk.h | 11 +- 5 files changed, 187 insertions(+), 235 deletions(-)
drivers/lightnvm/pblk-init.c +2 -0
@@ -426,6 +426,7 @@ static int pblk_core_init(struct pblk *pblk) goto free_r_end_wq;INIT_LIST_HEAD (&pblk->compl_list); +INIT_LIST_HEAD (&pblk->resubmit_list);return 0 ;
@@ -1185,6 +1186,7 @@ static void *pblk_init(struct nvm_tgt_dev *dev, struct gendisk *tdisk, pblk->state =PBLK_STATE_RUNNING ; pblk->gc.gc_enabled =0 ; +spin_lock_init (&pblk->resubmit_lock);spin_lock_init (&pblk->trans_lock);spin_lock_init (&pblk->lock);
drivers/lightnvm/pblk-rb.c +0 -39
@@ -503,45 +503,6 @@ int pblk_rb_may_write_gc(struct pblk_rb *rb, unsigned int nr_entries, }/* -* The caller of this function must ensure that the backpointer will not -* overwrite the entries passed on the list. -*/ -unsigned int pblk_rb_read_to_bio_list (struct pblk_rb *rb,struct bio *bio, -struct list_head *list, -unsigned int max) -{ -struct pblk_rb_entry *entry, *tentry; -struct page *page; -unsigned int read =0 ; -int ret; - -list_for_each_entry_safe (entry, tentry, list, index) { -if (read > max) { -pr_err ("pblk: too many entries on list\n" ); - goto out; - } - - page =virt_to_page (entry->data); -if (!page) { -pr_err ("pblk: could not allocate write bio page\n" ); - goto out; - } - - ret =bio_add_page (bio, page, rb->seg_size,0 ); -if (ret != rb->seg_size) { -pr_err ("pblk: could not add page to write bio\n" ); - goto out; - } - -list_del (&entry->index); - read++; - } - -out: -return read; -} - -/* * Read available entries on rb and add them to the given bio. To avoid a memory * copy, a page reference to the write buffer is used to be added to the bio. *
drivers/lightnvm/pblk-recovery.c +0 -91
97 lines not on this page · raw message
drivers/lightnvm/pblk-write.c +182 -97
322 lines not on this page · raw message
drivers/lightnvm/pblk.h +3 -8
@@ -128,7 +128,6 @@ struct pblk_pad_rq {struct pblk_rec_ctx {struct pblk *pblk;struct nvm_rq *rqd; -struct list_head failed;struct work_struct ws_rec; };
@@ -664,6 +663,9 @@ struct pblk {struct list_head compl_list; +spinlock_t resubmit_lock;/* Resubmit list lock */ +struct list_head resubmit_list;/* Resubmit list for failed writes*/ +mempool_t page_bio_pool;mempool_t gen_ws_pool;mempool_t rec_pool;
@@ -713,9 +715,6 @@ void pblk_rb_sync_l2p(struct pblk_rb *rb);unsigned int pblk_rb_read_to_bio (struct pblk_rb *rb,struct nvm_rq *rqd,unsigned int pos,unsigned int nr_entries,unsigned int count); -unsigned int pblk_rb_read_to_bio_list (struct pblk_rb *rb,struct bio *bio, -struct list_head *list, -unsigned int max);int pblk_rb_copy_to_bio (struct pblk_rb *rb,struct bio *bio,sector_t lba,struct ppa_addr ppa,int bio_iter,bool advanced_bio);unsigned int pblk_rb_read_commit (struct pblk_rb *rb,unsigned int entries);
@@ -848,13 +847,9 @@ int pblk_submit_read_gc(struct pblk *pblk, struct pblk_gc_rq *gc_rq);/* * pblk recovery */ -void pblk_submit_rec (struct work_struct *work);struct pblk_line *pblk_recov_l2p (struct pblk *pblk);int pblk_recov_pad (struct pblk *pblk);int pblk_recov_check_emeta (struct pblk *pblk,struct line_emeta *emeta); -int pblk_recov_setup_rq (struct pblk *pblk,struct pblk_c_ctx *c_ctx, -struct pblk_rec_ctx *recovery,u64 *comp_bits, -unsigned int comp);/* * pblk gc
Signature · 1 line
2.11.0
[GIT PULL 02/10] lightnvm: pblk: garbage collect lines with failed writes
In reply to Matias BjørlingFrom: Hans Holmberg <[email protected]>
Write failures should not happen under normal circumstances, so in order to bring the chunk back into a known state as soon as possible, evacuate all the valid data out of the line and let the fw judge if the block can be written to in the next reset cycle.
Do this by introducing a new gc list for lines with failed writes, and ensure that the rate limiter allocates a small portion of the write bandwidth to get the job done.
The lba list is saved in memory for use during gc as we cannot gurantee that the emeta data is readable if a write error occurred.
--- drivers/lightnvm/pblk-core.c | 45 ++++++++++++++++++- drivers/lightnvm/pblk-gc.c | 102 +++++++++++++++++++++++++++--------------- drivers/lightnvm/pblk-init.c | 46 ++++++++++++------- drivers/lightnvm/pblk-rl.c | 29 ++++++++++-- drivers/lightnvm/pblk-sysfs.c | 15 ++++++- drivers/lightnvm/pblk-write.c | 2 + drivers/lightnvm/pblk.h | 25 +++++++++-- 7 files changed, 200 insertions(+), 64 deletions(-)
drivers/lightnvm/pblk-core.c +43 -2
@@ -373,7 +373,13 @@ struct list_head *pblk_line_gc_list(struct pblk *pblk, struct pblk_line *line)lockdep_assert_held (&line->lock); -if (!vsc) { +if (line->w_err_gc->has_write_err) { +if (line->gc_group !=PBLK_LINEGC_WERR ) { + line->gc_group =PBLK_LINEGC_WERR ; + move_list = &l_mg->gc_werr_list; +pblk_rl_werr_line_in (&pblk->rl); + } + }else if (!vsc) {if (line->gc_group !=PBLK_LINEGC_FULL ) { line->gc_group =PBLK_LINEGC_FULL ; move_list = &l_mg->gc_full_list;
@@ -1589,8 +1595,13 @@ static void __pblk_line_put(struct pblk *pblk, struct pblk_line *line) line->state =PBLK_LINESTATE_FREE ; line->gc_group =PBLK_LINEGC_NONE ;pblk_line_free (line); + +if (line->w_err_gc->has_write_err) { +pblk_rl_werr_line_out (&pblk->rl); + line->w_err_gc->has_write_err =0 ; + } +spin_unlock (&line->lock); -atomic_dec (&gc->pipeline_gc);spin_lock (&l_mg->free_lock);
@@ -1753,11 +1764,34 @@ void pblk_line_close_meta(struct pblk *pblk, struct pblk_line *line)spin_lock (&l_mg->close_lock);spin_lock (&line->lock); + +/* Update the in-memory start address for emeta, in case it has +* shifted due to write errors +*/ +if (line->emeta_ssec != line->cur_sec) + line->emeta_ssec = line->cur_sec; +list_add_tail (&line->list, &l_mg->emeta_list);spin_unlock (&line->lock);spin_unlock (&l_mg->close_lock);pblk_line_should_sync_meta (pblk); + + +} + +static void pblk_save_lba_list (struct pblk *pblk,struct pblk_line *line) +{ +struct pblk_line_meta *lm = &pblk->lm; +struct pblk_line_mgmt *l_mg = &pblk->l_mg; +unsigned int lba_list_size = lm->emeta_len[2 ]; +struct pblk_w_err_gc *w_err_gc = line->w_err_gc; +struct pblk_emeta *emeta = line->emeta; + + w_err_gc->lba_list =pblk_malloc (lba_list_size, + l_mg->emeta_alloc_type,GFP_KERNEL ); +memcpy (w_err_gc->lba_list,emeta_to_lbas (pblk, emeta->buf), + lba_list_size); }void pblk_line_close_ws (struct work_struct *work)
@@ -1766,6 +1800,13 @@ void pblk_line_close_ws(struct work_struct *work) ws);struct pblk *pblk = line_ws->pblk;struct pblk_line *line = line_ws->line; +struct pblk_w_err_gc *w_err_gc = line->w_err_gc; + +/* Write errors makes the emeta start address stored in smeta invalid, +* so keep a copy of the lba list until we've gc'd the line +*/ +if (w_err_gc->has_write_err) +pblk_save_lba_list (pblk, line);pblk_line_close (pblk, line);mempool_free (line_ws, &pblk->gen_ws_pool);
drivers/lightnvm/pblk-gc.c +65 -37
159 lines not on this page · raw message
drivers/lightnvm/pblk-init.c +31 -15
88 lines not on this page · raw message
drivers/lightnvm/pblk-rl.c +25 -4
@@ -73,6 +73,16 @@ void pblk_rl_user_in(struct pblk_rl *rl, int nr_entries)pblk_rl_kick_u_timer (rl); } +void pblk_rl_werr_line_in (struct pblk_rl *rl) +{ +atomic_inc (&rl->werr_lines); +} + +void pblk_rl_werr_line_out (struct pblk_rl *rl) +{ +atomic_dec (&rl->werr_lines); +} +void pblk_rl_gc_in (struct pblk_rl *rl,int nr_entries) {atomic_add (nr_entries, &rl->rb_gc_cnt);
@@ -99,11 +109,21 @@ static void __pblk_rl_update_rates(struct pblk_rl *rl, { struct pblk *pblk = container_of(rl, struct pblk, rl);int max = rl->rb_budget; +int werr_gc_needed =atomic_read (&rl->werr_lines);if (free_blocks >= rl->high) { - rl->rb_user_max = max; - rl->rb_gc_max =0 ; - rl->rb_state =PBLK_RL_HIGH ; +if (werr_gc_needed) { +/* Allocate a small budget for recovering +* lines with write errors +*/ + rl->rb_gc_max =1 << rl->rb_windows_pw; + rl->rb_user_max = max - rl->rb_gc_max; + rl->rb_state =PBLK_RL_WERR ; + }else { + rl->rb_user_max = max; + rl->rb_gc_max =0 ; + rl->rb_state =PBLK_RL_OFF ; + } }else if (free_blocks < rl->high) {int shift = rl->high_pw - rl->rb_windows_pw;int user_windows = free_blocks >> shift;
@@ -124,7 +144,7 @@ static void __pblk_rl_update_rates(struct pblk_rl *rl, rl->rb_state =PBLK_RL_LOW ; } -if (rl->rb_state == (PBLK_RL_MID |PBLK_RL_LOW )) +if (rl->rb_state !=PBLK_RL_OFF )pblk_gc_should_start (pblk);else pblk_gc_should_stop (pblk);
@@ -221,6 +241,7 @@ void pblk_rl_init(struct pblk_rl *rl, int budget)atomic_set (&rl->rb_user_cnt,0 );atomic_set (&rl->rb_gc_cnt,0 );atomic_set (&rl->rb_space,-1 ); +atomic_set (&rl->werr_lines,0 );timer_setup (&rl->u_timer, pblk_rl_u_timer,0 );
drivers/lightnvm/pblk-sysfs.c +13 -2
@@ -173,6 +173,8 @@ static ssize_t pblk_sysfs_lines(struct pblk *pblk, char *page)int free_line_cnt =0 , closed_line_cnt =0 , emeta_line_cnt =0 ;int d_line_cnt =0 , l_line_cnt =0 ;int gc_full =0 , gc_high =0 , gc_mid =0 , gc_low =0 , gc_empty =0 ; +int gc_werr =0 ; +int bad =0 , cor =0 ;int msecs =0 , cur_sec =0 , vsc =0 , sec_in_line =0 ;int map_weight =0 , meta_weight =0 ;
@@ -237,6 +239,15 @@ static ssize_t pblk_sysfs_lines(struct pblk *pblk, char *page) gc_empty++; } +list_for_each_entry (line, &l_mg->gc_werr_list, list) { +if (line->type ==PBLK_LINETYPE_DATA ) + d_line_cnt++; +else if (line->type ==PBLK_LINETYPE_LOG ) + l_line_cnt++; + closed_line_cnt++; + gc_werr++; + } +list_for_each_entry (line, &l_mg->bad_list, list) bad++;list_for_each_entry (line, &l_mg->corrupt_list, list)
@@ -275,8 +286,8 @@ static ssize_t pblk_sysfs_lines(struct pblk *pblk, char *page) l_mg->nr_lines); sz +=snprintf (page + sz,PAGE_SIZE - sz, -"GC: full:%d, high:%d, mid:%d, low:%d, empty:%d, queue:%d\n" , - gc_full, gc_high, gc_mid, gc_low, gc_empty, +"GC: full:%d, high:%d, mid:%d, low:%d, empty:%d, werr: %d, queue:%d\n" , + gc_full, gc_high, gc_mid, gc_low, gc_empty, gc_werr,atomic_read (&pblk->gc.read_inflight_gc)); sz += snprintf(page + sz, PAGE_SIZE - sz,
drivers/lightnvm/pblk-write.c +2 -0
@@ -136,6 +136,7 @@ static void pblk_map_remaining(struct pblk *pblk, struct ppa_addr *ppa) } } + line->w_err_gc->has_write_err =1 ;spin_unlock (&line->lock); }
@@ -279,6 +280,7 @@ static void pblk_end_io_write_meta(struct nvm_rq *rqd)if (rqd->error) {pblk_log_write_err (pblk, rqd);pr_err ("pblk: metadata I/O failed. Line %d\n" , line->id); + line->w_err_gc->has_write_err =1 ; } sync =atomic_add_return (rqd->nr_ppas, &emeta->sync);
drivers/lightnvm/pblk.h +21 -4
@@ -89,12 +89,14 @@ struct pblk_sec_meta {/* The number of GC lists and the rate-limiter states go together. This way the * rate-limiter can dictate how much GC is needed based on resource utilization. */ -#define PBLK_GC_NR_LISTS 3 +#define PBLK_GC_NR_LISTS 4enum { -PBLK_RL_HIGH =1 , -PBLK_RL_MID =2 , -PBLK_RL_LOW =3 , +PBLK_RL_OFF =0 , +PBLK_RL_WERR =1 , +PBLK_RL_HIGH =2 , +PBLK_RL_MID =3 , +PBLK_RL_LOW =4 };#define pblk_dma_meta_size (sizeof(struct pblk_sec_meta) * PBLK_MAX_REQ_ADDRS)
@@ -278,6 +280,8 @@ struct pblk_rl {int rb_user_active;int rb_gc_active; +atomic_t werr_lines;/* Number of write error lines that needs gc */ +struct timer_list u_timer;unsigned long long nr_secs;
@@ -311,6 +315,7 @@ enum {PBLK_LINEGC_MID =23 ,PBLK_LINEGC_HIGH =24 ,PBLK_LINEGC_FULL =25 , + PBLK_LINEGC_WERR = 26 };#define PBLK_MAGIC 0x70626c6b/*pblk*/
@@ -412,6 +417,11 @@ struct pblk_smeta {struct line_smeta *buf;/* smeta buffer in persistent format */ }; +struct pblk_w_err_gc { +int has_write_err; +__le64 *lba_list; +}; +struct pblk_line {struct pblk *pblk;unsigned int id;/* Line number corresponds to the
@@ -457,6 +467,8 @@ struct pblk_line {struct kref ref;/* Write buffer L2P references */ +struct pblk_w_err_gc *w_err_gc;/* Write error gc recovery metadata */ +spinlock_t lock;/* Necessary for invalid_bitmap only */ };
@@ -488,6 +500,8 @@ struct pblk_line_mgmt {struct list_head gc_mid_list;/* Full lines ready to GC, mid isc */ struct list_head gc_low_list;/* Full lines ready to GC, low isc */ +struct list_head gc_werr_list;/* Write err recovery list */ +struct list_head gc_full_list;/* Full lines ready to GC, no valid */ struct list_head gc_empty_list;/* Full lines close, all valid */
@@ -890,6 +904,9 @@ void pblk_rl_free_lines_dec(struct pblk_rl *rl, struct pblk_line *line, bool used);int pblk_rl_is_limit (struct pblk_rl *rl); +void pblk_rl_werr_line_in (struct pblk_rl *rl); +void pblk_rl_werr_line_out (struct pblk_rl *rl); +/* * pblk sysfs */
Signature · 1 line
2.11.0
[GIT PULL 03/10] lightnvm: pblk: fix smeta write error path
In reply to Matias BjørlingFrom: Hans Holmberg <[email protected]>
Smeta write errors were previously ignored. Skip these lines instead and throw them back on the free list, so the chunks will go through a reset cycle before we attempt to use the line again.
--- drivers/lightnvm/pblk-core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/lightnvm/pblk-core.c +4 -3
@@ -849,9 +849,10 @@ static int pblk_line_submit_smeta_io(struct pblk *pblk, struct pblk_line *line,atomic_dec (&pblk->inflight_io);if (rqd.error) { -if (dir ==PBLK_WRITE ) +if (dir ==PBLK_WRITE ) {pblk_log_write_err (pblk, &rqd); -else if (dir ==PBLK_READ ) + ret =1 ; + }else if (dir ==PBLK_READ )pblk_log_read_err (pblk, &rqd); }
@@ -1101,7 +1102,7 @@ static int pblk_line_init_bb(struct pblk *pblk, struct pblk_line *line,if (init &&pblk_line_submit_smeta_io (pblk, line, off,PBLK_WRITE )) {pr_debug ("pblk: line smeta I/O failed. Retry\n" ); -return 1 ; +return 0 ; }bitmap_copy (line->invalid_bitmap, line->map_bitmap, lm->sec_per_line);
Signature · 1 line
2.11.0
[GIT PULL 04/10] lightnvm: proper error handling for pblk_bio_add_pages
In reply to Matias BjørlingFrom: Igor Konopko <[email protected]>
Currently in case of error caused by bio_pc_add_page in pblk_bio_add_pages two issues occur when calling from pblk_rb_read_to_bio(). First one is in pblk_bio_free_pages, since we are trying to free pages not allocated from our mempool. Second one is the warn from dma_pool_free, that we are trying to free NULL pointer dma.
This commit fix both issues.
--- drivers/lightnvm/pblk-core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/lightnvm/pblk-core.c +4 -2
@@ -278,7 +278,9 @@ void pblk_free_rqd(struct pblk *pblk, struct nvm_rq *rqd, int type)return ; } -nvm_dev_dma_free (dev->parent, rqd->meta_list, rqd->dma_meta_list); +if (rqd->meta_list) +nvm_dev_dma_free (dev->parent, rqd->meta_list, + rqd->dma_meta_list);mempool_free (rqd, pool); }
@@ -316,7 +318,7 @@ int pblk_bio_add_pages(struct pblk *pblk, struct bio *bio, gfp_t flags,return 0 ; err: -pblk_bio_free_pages (pblk, bio,0 , i -1 ); +pblk_bio_free_pages (pblk, bio, (bio->bi_vcnt - i), i);return -1 ; }
Signature · 1 line
2.11.0
[GIT PULL 05/10] lightnvm: fix partial read error path
In reply to Matias BjørlingFrom: Igor Konopko <[email protected]>
When error occurs during bio_add_page on partial read path, pblk tries to free pages twice.
--- drivers/lightnvm/pblk-read.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/lightnvm/pblk-read.c +4 -4
@@ -256,7 +256,7 @@ static int pblk_partial_read_bio(struct pblk *pblk, struct nvm_rq *rqd, new_bio =bio_alloc (GFP_KERNEL , nr_holes);if (pblk_bio_add_pages (pblk, new_bio,GFP_KERNEL , nr_holes)) - goto err; + goto err_add_pages;if (nr_holes != new_bio->bi_vcnt) {pr_err ("pblk: malformed bio\n" );
@@ -347,10 +347,10 @@ static int pblk_partial_read_bio(struct pblk *pblk, struct nvm_rq *rqd,return NVM_IO_OK ; err: -pr_err ("pblk: failed to perform partial read\n" ); -/* Free allocated pages in new bio */ -pblk_bio_free_pages (pblk, bio,0 , new_bio->bi_vcnt); +pblk_bio_free_pages (pblk, new_bio,0 , new_bio->bi_vcnt); +err_add_pages: +pr_err ("pblk: failed to perform partial read\n" );__pblk_end_io_read (pblk, rqd, false);return NVM_IO_ERR ; }
Signature · 1 line
2.11.0
[GIT PULL 06/10] lightnvm: pblk: add possibility to set write buffer size manually
In reply to Matias BjørlingFrom: Marcin Dziegielewski <[email protected]>
In some cases, users can want set write buffer size manually, e.g. to adjust it to specific workload. This patch provides the possibility to set write buffer size via module parameter feature.
--- drivers/lightnvm/pblk-init.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/lightnvm/pblk-init.c +12 -2
@@ -20,6 +20,11 @@#include "pblk.h" +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);
@@ -172,10 +177,15 @@ static int pblk_rwb_init(struct pblk *pblk)struct nvm_tgt_dev *dev = pblk->dev;struct nvm_geo *geo = &dev->geo;struct pblk_rb_entry *entries; -unsigned long nr_entries; +unsigned long nr_entries, buffer_size;unsigned int power_size, power_seg_sz; - nr_entries =pblk_rb_calculate_size (pblk->pgs_in_buffer); +if (write_buffer_size && (write_buffer_size > pblk->pgs_in_buffer)) + buffer_size = write_buffer_size; +else + buffer_size = pblk->pgs_in_buffer; + + nr_entries =pblk_rb_calculate_size (buffer_size); entries =vzalloc (nr_entries *sizeof (struct pblk_rb_entry ));if (!entries)
Signature · 1 line
2.11.0
[GIT PULL 07/10] lightnvm: pblk: remove unnecessary bio_get/put
In reply to Matias BjørlingFrom: Javier González <[email protected]>
In the read path, pblk gets a reference to the incoming bio and puts it after ending the bio. Though this behavior is correct, it is unnecessary since pblk is the one putting the bio, therefore, it cannot disappear underneath it.
Removing this reference, allows to clean up rqd->bio and avoids pointer bouncing for the different read paths. Now, the incoming bio always resides in the read context and pblk's internal bios (if any) reside in rqd->bio.
--- drivers/lightnvm/pblk-read.c | 65 +++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 37 deletions(-)
drivers/lightnvm/pblk-read.c +28 -37
@@ -39,10 +39,10 @@ static int pblk_read_from_cache(struct pblk *pblk, struct bio *bio, }static void pblk_read_ppalist_rq (struct pblk *pblk,struct nvm_rq *rqd, -sector_t blba,unsigned long *read_bitmap) +struct bio *bio,sector_t blba, +unsigned long *read_bitmap) {struct pblk_sec_meta *meta_list = rqd->meta_list; -struct bio *bio = rqd->bio;struct ppa_addr ppas[PBLK_MAX_REQ_ADDRS ];int nr_secs = rqd->nr_ppas;bool advanced_bio = false;
@@ -189,7 +189,6 @@ static void pblk_end_user_read(struct bio *bio)WARN_ONCE (bio->bi_status,"pblk: corrupted read bio\n" );#endif bio_endio (bio); -bio_put (bio); } static void __pblk_end_io_read(struct pblk *pblk, struct nvm_rq *rqd,
@@ -197,23 +196,18 @@ static void __pblk_end_io_read(struct pblk *pblk, struct nvm_rq *rqd, {struct nvm_tgt_dev *dev = pblk->dev;struct pblk_g_ctx *r_ctx =nvm_rq_to_pdu (rqd); -struct bio *bio = rqd->bio; +struct bio *int_bio = rqd->bio;unsigned long start_time = r_ctx->start_time;generic_end_io_acct (dev->q,READ , &pblk->disk->part0, start_time);if (rqd->error)pblk_log_read_err (pblk, rqd); -#ifdef CONFIG_NVM_DEBUG - else - WARN_ONCE(bio->bi_status, "pblk: corrupted read error\n"); -#endif pblk_read_check_seq (pblk, rqd, r_ctx->lba); -bio_put (bio); -if (r_ctx->private) -pblk_end_user_read ((struct bio *)r_ctx->private); +if (int_bio) +bio_put (int_bio);if (put_line)pblk_read_put_rqd_kref (pblk, rqd);
@@ -230,16 +224,19 @@ static void __pblk_end_io_read(struct pblk *pblk, struct nvm_rq *rqd,static void pblk_end_io_read (struct nvm_rq *rqd) {struct pblk *pblk = rqd->private; +struct pblk_g_ctx *r_ctx =nvm_rq_to_pdu (rqd); +struct bio *bio = (struct bio *)r_ctx->private; +pblk_end_user_read (bio);__pblk_end_io_read (pblk, rqd, true); } -static int pblk_partial_read_bio (struct pblk *pblk,struct nvm_rq *rqd, -unsigned int bio_init_idx, -unsigned long *read_bitmap) +static int pblk_partial_read (struct pblk *pblk,struct nvm_rq *rqd, +struct bio *orig_bio,unsigned int bio_init_idx, +unsigned long *read_bitmap) { -struct bio *new_bio, *bio = rqd->bio;struct pblk_sec_meta *meta_list = rqd->meta_list; +struct bio *new_bio;struct bio_vec src_bv, dst_bv;void *ppa_ptr =NULL ;void *src_p, *dst_p;
@@ -256,11 +253,11 @@ static int pblk_partial_read_bio(struct pblk *pblk, struct nvm_rq *rqd, new_bio =bio_alloc (GFP_KERNEL , nr_holes);if (pblk_bio_add_pages (pblk, new_bio,GFP_KERNEL , nr_holes)) - goto err_add_pages; + goto fail_add_pages;if (nr_holes != new_bio->bi_vcnt) {pr_err ("pblk: malformed bio\n" ); - goto err; + goto fail; }for (i =0 ; i < nr_secs; i++)
@@ -283,7 +280,7 @@ static int pblk_partial_read_bio(struct pblk *pblk, struct nvm_rq *rqd,if (ret) {bio_put (rqd->bio);pr_err ("pblk: sync read IO submission failed\n" ); - goto err; + goto fail; }if (rqd->error) {
@@ -319,7 +316,7 @@ static int pblk_partial_read_bio(struct pblk *pblk, struct nvm_rq *rqd, meta_list[hole].lba = lba_list_media[i]; src_bv = new_bio->bi_io_vec[i++]; - dst_bv = bio->bi_io_vec[bio_init_idx + hole]; + dst_bv = orig_bio->bi_io_vec[bio_init_idx + hole]; src_p =kmap_atomic (src_bv.bv_page); dst_p =kmap_atomic (dst_bv.bv_page);
@@ -338,28 +335,26 @@ static int pblk_partial_read_bio(struct pblk *pblk, struct nvm_rq *rqd,bio_put (new_bio); -/* Complete the original bio and associated request */ -bio_endio (bio); - rqd->bio = bio; +/* restore original request */ + rqd->bio =NULL ; rqd->nr_ppas = nr_secs;__pblk_end_io_read (pblk, rqd, false); -return NVM_IO_OK ; +return NVM_IO_DONE ; -err: +fail:/* Free allocated pages in new bio */ pblk_bio_free_pages (pblk, new_bio,0 , new_bio->bi_vcnt); -err_add_pages: +fail_add_pages:pr_err ("pblk: failed to perform partial read\n" );__pblk_end_io_read (pblk, rqd, false);return NVM_IO_ERR ; } -static void pblk_read_rq (struct pblk *pblk,struct nvm_rq *rqd, +static void pblk_read_rq (struct pblk *pblk,struct nvm_rq *rqd,struct bio *bio,sector_t lba,unsigned long *read_bitmap) {struct pblk_sec_meta *meta_list = rqd->meta_list; -struct bio *bio = rqd->bio;struct ppa_addr ppa;pblk_lookup_l2p_seq (pblk, &ppa, lba,1 );
@@ -423,14 +418,15 @@ int pblk_submit_read(struct pblk *pblk, struct bio *bio) rqd =pblk_alloc_rqd (pblk,PBLK_READ ); rqd->opcode =NVM_OP_PREAD ; - rqd->bio = bio; rqd->nr_ppas = nr_secs; + rqd->bio =NULL ;/* cloned bio if needed */ rqd->private = pblk; rqd->end_io = pblk_end_io_read; r_ctx =nvm_rq_to_pdu (rqd); r_ctx->start_time = jiffies; r_ctx->lba = blba; + r_ctx->private = bio;/* original bio */ /* Save the index for this bio's start. This is needed in case * we need to fill a partial read.
@@ -448,17 +444,15 @@ int pblk_submit_read(struct pblk *pblk, struct bio *bio) rqd->ppa_list = rqd->meta_list + pblk_dma_meta_size; rqd->dma_ppa_list = rqd->dma_meta_list + pblk_dma_meta_size; -pblk_read_ppalist_rq (pblk, rqd, blba, &read_bitmap); +pblk_read_ppalist_rq (pblk, rqd, bio, blba, &read_bitmap); }else { -pblk_read_rq (pblk, rqd, blba, &read_bitmap); +pblk_read_rq (pblk, rqd, bio, blba, &read_bitmap); } -bio_get (bio);if (bitmap_full (&read_bitmap, nr_secs)) { -bio_endio (bio);atomic_inc (&pblk->inflight_io);__pblk_end_io_read (pblk, rqd, false); -return NVM_IO_OK ; +return NVM_IO_DONE ; }/* All sectors are to be read from the device */
@@ -473,13 +467,10 @@ int pblk_submit_read(struct pblk *pblk, struct bio *bio) } rqd->bio = int_bio; - r_ctx->private = bio;if (pblk_submit_io (pblk, rqd)) {pr_err ("pblk: read IO submission failed\n" ); ret =NVM_IO_ERR ; -if (int_bio) -bio_put (int_bio); goto fail_end_io; }
@@ -489,7 +480,7 @@ int pblk_submit_read(struct pblk *pblk, struct bio *bio)/* The read bio request could be partially filled by the write buffer, * but there are some holes that need to be read from the drive. */ -return pblk_partial_read_bio (pblk, rqd, bio_init_idx, &read_bitmap); +return pblk_partial_read (pblk, rqd, bio, bio_init_idx, &read_bitmap); fail_rqd_free:pblk_free_rqd (pblk, rqd,PBLK_READ );
Signature · 1 line
2.11.0
[GIT PULL 08/10] lightnvm: pblk: only try to recover lines with written smeta
In reply to Matias BjørlingFrom: Hans Holmberg <[email protected]>
When switching between different lun configurations, there is no guarantee that all lines that contain closed/open chunks have some valid data to recover.
Check that the smeta chunk has been written to instead. Also skip bad lines (that does not have enough good chunks).
--- drivers/lightnvm/pblk-recovery.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-)
drivers/lightnvm/pblk-recovery.c +21 -9
@@ -774,18 +774,30 @@ static void pblk_recov_wa_counters(struct pblk *pblk, }static int pblk_line_was_written (struct pblk_line *line, -struct pblk_line_meta *lm) +struct pblk *pblk) { -int i; -int state_mask =NVM_CHK_ST_OFFLINE |NVM_CHK_ST_FREE ; +struct pblk_line_meta *lm = &pblk->lm; +struct nvm_tgt_dev *dev = pblk->dev; +struct nvm_geo *geo = &dev->geo; +struct nvm_chk_meta *chunk; +struct ppa_addr bppa; +int smeta_blk; -for (i =0 ; i < lm->blk_per_line; i++) { -if (!(line->chks[i].state & state_mask)) -return 1 ; - } +if (line->state ==PBLK_LINESTATE_BAD ) +return 0 ; -return 0 ; + smeta_blk =find_first_zero_bit (line->blk_bitmap, lm->blk_per_line); +if (smeta_blk >= lm->blk_per_line) +return 0 ; + + bppa = pblk->luns[smeta_blk].bppa; + chunk = &line->chks[pblk_ppa_to_pos (geo, bppa)]; + +if (chunk->state &NVM_CHK_ST_FREE ) +return 0 ; + +return 1 ; }struct pblk_line *pblk_recov_l2p (struct pblk *pblk)
@@ -824,7 +836,7 @@ struct pblk_line *pblk_recov_l2p(struct pblk *pblk) line->lun_bitmap = ((void *)(smeta_buf)) +sizeof (struct line_smeta ); -if (!pblk_line_was_written (line, lm)) +if (!pblk_line_was_written (line, pblk))continue ;/* Lines that cannot be read are assumed as not written here */
Signature · 1 line
2.11.0
[GIT PULL 09/10] lightnvm: pblk: kick writer on new flush points
In reply to Matias BjørlingFrom: Hans Holmberg <[email protected]>
Unless we kick the writer directly when setting a new flush point, the user risks having to wait for up to one second (the default timeout for the write thread to be kicked) for the IO to complete.
--- drivers/lightnvm/pblk-cache.c | 10 ++++++---- drivers/lightnvm/pblk-core.c | 2 +- drivers/lightnvm/pblk-rb.c | 4 ++-- drivers/lightnvm/pblk.h | 1 + 4 files changed, 10 insertions(+), 7 deletions(-)
drivers/lightnvm/pblk-cache.c +6 -4
@@ -44,13 +44,15 @@ int pblk_write_to_cache(struct pblk *pblk, struct bio *bio, unsigned long flags) goto out; } -if (unlikely (!bio_has_data (bio))) - goto out; -pblk_ppa_set_empty (&w_ctx.ppa); w_ctx.flags = flags; -if (bio->bi_opf &REQ_PREFLUSH ) +if (bio->bi_opf &REQ_PREFLUSH ) { w_ctx.flags |=PBLK_FLUSH_ENTRY ; +pblk_write_kick (pblk); + } + +if (unlikely (!bio_has_data (bio))) + goto out;for (i =0 ; i < nr_entries; i++) {void *data =bio_data (bio);
drivers/lightnvm/pblk-core.c +1 -1
@@ -322,7 +322,7 @@ int pblk_bio_add_pages(struct pblk *pblk, struct bio *bio, gfp_t flags,return -1 ; } -static void pblk_write_kick (struct pblk *pblk) +void pblk_write_kick (struct pblk *pblk) {wake_up_process (pblk->writer_ts);mod_timer (&pblk->wtimer, jiffies +msecs_to_jiffies (1000 ));
drivers/lightnvm/pblk-rb.c +2 -2
@@ -349,7 +349,7 @@ void pblk_rb_write_entry_gc(struct pblk_rb *rb, void *data, }static int pblk_rb_flush_point_set (struct pblk_rb *rb,struct bio *bio, -unsigned int pos) +unsigned int pos) {struct pblk_rb_entry *entry;unsigned int sync, flush_point;
@@ -419,7 +419,7 @@ void pblk_rb_flush(struct pblk_rb *rb)if (pblk_rb_flush_point_set (rb,NULL , mem))return ; -pblk_write_should_kick (pblk); +pblk_write_kick (pblk); } static int pblk_rb_may_write_flush(struct pblk_rb *rb, unsigned int nr_entries,
drivers/lightnvm/pblk.h +1 -0
@@ -851,6 +851,7 @@ void pblk_map_rq(struct pblk *pblk, struct nvm_rq *rqd, unsigned int sentry,int pblk_write_ts (void *data);void pblk_write_timer_fn (struct timer_list *t);void pblk_write_should_kick (struct pblk *pblk); +void pblk_write_kick (struct pblk *pblk);/* * pblk read path
Signature · 1 line
2.11.0
[GIT PULL 10/10] lightnvm: pblk: take bitmap alloc. out of critical section
In reply to Matias BjørlingFrom: Javier González <[email protected]>
pblk allocates line bitmaps within the line lock unnecessarily. In order to take pressure out of the fast patch, allocate line bitmaps outside of this lock and refactor accordingly.
--- drivers/lightnvm/pblk-core.c | 97 +++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 41 deletions(-)
drivers/lightnvm/pblk-core.c +56 -41
@@ -1067,6 +1067,25 @@ static int pblk_line_init_metadata(struct pblk *pblk, struct pblk_line *line,return 1 ; } +static int pblk_line_alloc_bitmaps (struct pblk *pblk,struct pblk_line *line) +{ +struct pblk_line_meta *lm = &pblk->lm; + + line->map_bitmap =kzalloc (lm->sec_bitmap_len,GFP_KERNEL ); +if (!line->map_bitmap) +return -ENOMEM ; + +/* will be initialized using bb info from map_bitmap */ + line->invalid_bitmap =kmalloc (lm->sec_bitmap_len,GFP_KERNEL ); +if (!line->invalid_bitmap) { +kfree (line->map_bitmap); + line->map_bitmap =NULL ; +return -ENOMEM ; + } + +return 0 ; +} +/* For now lines are always assumed full lines. Thus, smeta former and current * lun bitmaps are omitted. */
@@ -1171,18 +1190,7 @@ static int pblk_line_prepare(struct pblk *pblk, struct pblk_line *line) {struct pblk_line_meta *lm = &pblk->lm;int blk_in_line =atomic_read (&line->blk_in_line); -int blk_to_erase, ret; - - line->map_bitmap =kzalloc (lm->sec_bitmap_len,GFP_ATOMIC ); -if (!line->map_bitmap) -return -ENOMEM ; - -/* will be initialized using bb info from map_bitmap */ - line->invalid_bitmap =kmalloc (lm->sec_bitmap_len,GFP_ATOMIC ); -if (!line->invalid_bitmap) { - ret = -ENOMEM ; - goto fail_free_map_bitmap; - } +int blk_to_erase;/* Bad blocks do not need to be erased */ bitmap_copy (line->erase_bitmap, line->blk_bitmap, lm->blk_per_line);
@@ -1200,15 +1208,15 @@ static int pblk_line_prepare(struct pblk *pblk, struct pblk_line *line) }if (blk_in_line < lm->min_blk_line) { - ret = -EAGAIN ; - goto fail_free_invalid_bitmap; +spin_unlock (&line->lock); +return -EAGAIN ; }if (line->state !=PBLK_LINESTATE_FREE ) {WARN (1 ,"pblk: corrupted line %d, state %d\n" , line->id, line->state); - ret = -EINTR ; - goto fail_free_invalid_bitmap; +spin_unlock (&line->lock); +return -EINTR ; } line->state =PBLK_LINESTATE_OPEN ;
@@ -1222,16 +1230,6 @@ static int pblk_line_prepare(struct pblk *pblk, struct pblk_line *line)kref_init (&line->ref);return 0 ; - -fail_free_invalid_bitmap: -spin_unlock (&line->lock); -kfree (line->invalid_bitmap); - line->invalid_bitmap =NULL ; -fail_free_map_bitmap: -kfree (line->map_bitmap); - line->map_bitmap =NULL ; - -return ret; }int pblk_line_recov_alloc (struct pblk *pblk,struct pblk_line *line)
@@ -1251,13 +1249,16 @@ int pblk_line_recov_alloc(struct pblk *pblk, struct pblk_line *line) }spin_unlock (&l_mg->free_lock); -pblk_rl_free_lines_dec (&pblk->rl, line, true); + ret =pblk_line_alloc_bitmaps (pblk, line); +if (ret) +return ret;if (!pblk_line_init_bb (pblk, line,0 )) {list_add (&line->list, &l_mg->free_list);return -EINTR ; } +pblk_rl_free_lines_dec (&pblk->rl, line, true);return 0 ; }
@@ -1269,6 +1270,24 @@ void pblk_line_recov_close(struct pblk *pblk, struct pblk_line *line) line->emeta =NULL ; } +static void pblk_line_reinit (struct pblk_line *line) +{ + *line->vsc =cpu_to_le32 (EMPTY_ENTRY ); + + line->map_bitmap =NULL ; + line->invalid_bitmap =NULL ; + line->smeta =NULL ; + line->emeta =NULL ; +} + +void pblk_line_free (struct pblk_line *line) +{ +kfree (line->map_bitmap); +kfree (line->invalid_bitmap); + +pblk_line_reinit (line); +} +struct pblk_line *pblk_line_get (struct pblk *pblk) {struct pblk_line_mgmt *l_mg = &pblk->l_mg;
@@ -1335,11 +1354,14 @@ static struct pblk_line *pblk_line_retry(struct pblk *pblk,return NULL ; } + retry_line->map_bitmap = line->map_bitmap; + retry_line->invalid_bitmap = line->invalid_bitmap; retry_line->smeta = line->smeta; retry_line->emeta = line->emeta; retry_line->meta_line = line->meta_line; -pblk_line_free (line); +pblk_line_reinit (line); + l_mg->data_line = retry_line;spin_unlock (&l_mg->free_lock);
@@ -1392,6 +1414,9 @@ struct pblk_line *pblk_line_get_first_data(struct pblk *pblk) }spin_unlock (&l_mg->free_lock); +if (pblk_line_alloc_bitmaps (pblk, line)) +return NULL ; +if (pblk_line_erase (pblk, line)) { line =pblk_line_retry (pblk, line);if (!line)
@@ -1536,6 +1561,9 @@ struct pblk_line *pblk_line_replace_data(struct pblk *pblk) goto retry_erase; } +if (pblk_line_alloc_bitmaps (pblk, new)) +return NULL ; + retry_setup:if (!pblk_line_init_metadata (pblk, new, cur)) { new =pblk_line_retry (pblk, new);
@@ -1575,19 +1603,6 @@ struct pblk_line *pblk_line_replace_data(struct pblk *pblk)return new; } -void pblk_line_free (struct pblk_line *line) -{ -kfree (line->map_bitmap); -kfree (line->invalid_bitmap); - - *line->vsc =cpu_to_le32 (EMPTY_ENTRY ); - - line->map_bitmap =NULL ; - line->invalid_bitmap =NULL ; - line->smeta =NULL ; - line->emeta =NULL ; -} -static void __pblk_line_put (struct pblk *pblk,struct pblk_line *line) {struct pblk_line_mgmt *l_mg = &pblk->l_mg;
Signature · 1 line
2.11.0
Quoted 44 lines · Matias Bjørling
Hi Jens,
Please pick up the following patches.
Changes since v2:
Rebased write error recovery patch on top of latest for-4.18/block
Added (missed the first round)
lightnvm: pblk: only try to recover lines with written smeta
lightnvm: pblk: kick writer on new flush points
lightnvm: pblk: take bitmap alloc. out of critical sectionChanges since v1:
Removed
lightnvm: pblk: sync RB and RL states during GC
lightnvm: error handling when whole line is bad
lightnvm: pblk: handle case whenmw_cunitsequals to 0Added
lightnvm: pblk: remove unnecessary bio_get/putThanks!
Hans Holmberg (5):
lightnvm: pblk: rework write error recovery path
lightnvm: pblk: garbage collect lines with failed writes
lightnvm: pblk: fix smeta write error path
lightnvm: pblk: only try to recover lines with written smeta
lightnvm: pblk: kick writer on new flush pointsIgor Konopko (2):
lightnvm: proper error handling forpblk_bio_add_pages
lightnvm: fix partial read error pathJavier González (2):
lightnvm: pblk: remove unnecessary bio_get/put
lightnvm: pblk: take bitmap alloc. out of critical sectionMarcin Dziegielewski (1):
lightnvm: pblk: add possibility to set write buffer size manually
Quoted 12 lines
drivers/lightnvm/pblk-cache.c | 10 +- drivers/lightnvm/pblk-core.c | 157 +++++++++++++++------- drivers/lightnvm/pblk-gc.c | 102 ++++++++------ drivers/lightnvm/pblk-init.c | 62 ++++++--- drivers/lightnvm/pblk-rb.c | 43 +----- drivers/lightnvm/pblk-read.c | 69 +++++----- drivers/lightnvm/pblk-recovery.c | 121 +++-------------- drivers/lightnvm/pblk-rl.c | 29 +++- drivers/lightnvm/pblk-sysfs.c | 15 ++- drivers/lightnvm/pblk-write.c | 281 +++++++++++++++++++++++++-------------- drivers/lightnvm/pblk.h | 37 ++++-- 11 files changed, 524 insertions(+), 402 deletions(-)
Applied, thanks.
Signature · 1 line
Jens Axboe