lightnvm: pblk bug fixes for 4.14
cover lightnvm: pblk bug fixes for 4.14
Hi Jens,
Here are the pblk bug fixes for this window.
The patches apply on your for-4.14/block, and you can be found at:
https://github.com/OpenChannelSSD/linux/tree/pblk.for-4.14
Thanks,
Javier
Javier González (6):
lightnvm: pblk: check for failed mempool alloc.
lightnvm: pblk: initialize debug stat counter
lightnvm: pblk: use right flag for GC allocation
lightnvm: pblk: free padded entries in write buffer
lightnvm: pblk: fix write I/O sync stat
lightnvm: pblk: avoid deadlock on low LUN config
drivers/lightnvm/pblk-core.c | 5 ++++- drivers/lightnvm/pblk-init.c | 3 ++- drivers/lightnvm/pblk-read.c | 7 +++++-- drivers/lightnvm/pblk-rl.c | 6 ++++++ drivers/lightnvm/pblk-write.c | 16 ++++++++++++---- drivers/lightnvm/pblk.h | 2 ++ 6 files changed, 31 insertions(+), 8 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/6 lightnvm: pblk: check for failed mempool alloc.
Check for failed mempool allocations and act accordingly.
--- drivers/lightnvm/pblk-core.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/lightnvm/pblk-core.c +4 -0
@@ -165,6 +165,8 @@ struct nvm_rq *pblk_alloc_rqd(struct pblk *pblk, int rw) } rqd =mempool_alloc (pool,GFP_KERNEL ); +if (!rqd) +return NULL ;memset (rqd,0 , rq_size);return rqd;
@@ -1478,6 +1480,8 @@ int pblk_blk_erase_async(struct pblk *pblk, struct ppa_addr ppa)int err; rqd =mempool_alloc (pblk->g_rq_pool,GFP_KERNEL ); +if (!rqd) +return -ENOMEM ;memset (rqd,0 , pblk_g_rq_size);pblk_setup_e_rq (pblk, rqd, ppa);
Signature · 1 line
2.7.4
Re: [PATCH 1/6] lightnvm: pblk: check for failed mempool alloc.
Quoted 1 line · Javier Gonz�lez
Check for failed mempool allocations and act accordingly.
Are you sure it is needed? Quoting from mempool_alloc()s Documentation:
"[...] Note that due to preallocation, this function *never* fails when called from process contexts. (it might fail if called from an IRQ context.) [...]"
Byte,
Johannes
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: Felix Imend�rffer, Jane Smithard, Graham Norton HRB 21284 (AG N�rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Jens Axboe
maintainerRe: [PATCH 1/6] lightnvm: pblk: check for failed mempool alloc.
Quoted 6 lines · Johannes Thumshirn
Quoted 1 line · Javier González
Check for failed mempool allocations and act accordingly.
Are you sure it is needed? Quoting from mempool_alloc()s Documentation:
"[...] Note that due to preallocation, this function *never* fails when called from process contexts. (it might fail if called from an IRQ context.) [...]"
It's not needed, mempool() will never fail if __GFP_WAIT is set in the mask. The use case here is GFP_KERNEL, which does include __GFP_WAIT.
Signature · 1 line
Jens Axboe
Re: [PATCH 1/6] lightnvm: pblk: check for failed mempool alloc.
Quoted 12 lines · Jens Axboe
Quoted 6 lines · Johannes Thumshirn
Quoted 1 line · Javier González
Check for failed mempool allocations and act accordingly.
Are you sure it is needed? Quoting from mempool_alloc()s Documentation:
"[...] Note that due to preallocation, this function *never* fails when called from process contexts. (it might fail if called from an IRQ context.) [...]"It's not needed,
mempool()will never fail if__GFP_WAITis set in the mask. The use case here isGFP_KERNEL, which does include__GFP_WAIT.
Thanks for the clarification. Do you just drop the patch, or do you want me to re-send the series?
I see that I do this other places, I'll clean it up for next window.
Thanks,
Javier
Jens Axboe
maintainerRe: [PATCH 1/6] lightnvm: pblk: check for failed mempool alloc.
Quoted 10 lines · Javier González
Quoted 10 lines · Jens Axboe
Quoted 6 lines · Johannes Thumshirn
Quoted 1 line · Javier González
Check for failed mempool allocations and act accordingly.
Are you sure it is needed? Quoting from mempool_alloc()s Documentation:
"[...] Note that due to preallocation, this function *never* fails when called from process contexts. (it might fail if called from an IRQ context.) [...]"
Quoted 5 lines
Quoted 2 lines
It's not needed,
mempool()will never fail if__GFP_WAITis set in the mask. The use case here isGFP_KERNEL, which does include__GFP_WAIT.Thanks for the clarification. Do you just drop the patch, or do you want me to re-send the series?
No need to resend. I'll pick up the others in a day or two, once people have had some time to go over them.
Signature · 1 line
Jens Axboe
Re: [PATCH 1/6] lightnvm: pblk: check for failed mempool alloc.
Quoted 13 lines · Jens Axboe
Quoted 10 lines · Javier González
Quoted 10 lines · Jens Axboe
Quoted 6 lines · Johannes Thumshirn
Quoted 1 line · Javier González
Check for failed mempool allocations and act accordingly.
Are you sure it is needed? Quoting from mempool_alloc()s Documentation:
"[...] Note that due to preallocation, this function *never* fails when called from process contexts. (it might fail if called from an IRQ context.) [...]"
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
It's not needed,
mempool()will never fail if__GFP_WAITis set in the mask. The use case here isGFP_KERNEL, which does include__GFP_WAIT.Thanks for the clarification. Do you just drop the patch, or do you want me to re-send the series?
No need to resend. I'll pick up the others in a day or two, once people have had some time to go over them.
Thanks. And apologies for the delay on the patches...
Javier
Jens Axboe
maintainerRe: [PATCH 1/6] lightnvm: pblk: check for failed mempool alloc.
In reply to Jens AxboeQuoted 11 lines · Jens Axboe
Quoted 10 lines · Javier González
Quoted 10 lines · Jens Axboe
Quoted 6 lines · Johannes Thumshirn
Quoted 1 line · Javier González
Check for failed mempool allocations and act accordingly.
Are you sure it is needed? Quoting from mempool_alloc()s Documentation:
"[...] Note that due to preallocation, this function *never* fails when called from process contexts. (it might fail if called from an IRQ context.) [...]"
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
It's not needed,
mempool()will never fail if__GFP_WAITis set in the mask. The use case here isGFP_KERNEL, which does include__GFP_WAIT.Thanks for the clarification. Do you just drop the patch, or do you want me to re-send the series?
No need to resend. I'll pick up the others in a day or two, once people have had some time to go over them.
I took a quick look at your mempool usage, and I'm not sure it's correct. For a mempool to work, you have to ensure that you provide a forward progress guarantee. With that guarantee, you know that if you do end up sleeping on allocation, you already have items inflight that will be freed when that operation completes. In other words, all allocations must have a defined and finite life time, as any allocation can potentially sleep/block for that life time. You can't allocate something and hold on to it forever, then you are violating the terms of agreement that makes a mempool work.
The first one that caught my eye is pblk->page_pool. You have this loop:
for (i = 0; i < nr_pages; i++) {
page = mempool_alloc(pblk->page_pool, flags);
if (!page)
goto err;
ret = bio_add_pc_page(q, bio, page, PBLK_EXPOSED_PAGE_SIZE, 0);
if (ret != PBLK_EXPOSED_PAGE_SIZE) {
pr_err("pblk: could not add page to bio\n");
mempool_free(page, pblk->page_pool);
goto err;
}
} which looks suspect. This mempool is created with a reserve pool of PAGE_POOL_SIZE (16) members. Do we know if the bio has 16 pages or less? If not, then this is broken and can deadlock forever.
You have a lot of mempool usage in the code, would probably not hurt to audit all of them.
Signature · 1 line
Jens Axboe
Re: [PATCH 1/6] lightnvm: pblk: check for failed mempool alloc.
Quoted 23 lines · Jens Axboe
Quoted 11 lines · Jens Axboe
Quoted 10 lines · Javier González
Quoted 10 lines · Jens Axboe
Quoted 6 lines · Johannes Thumshirn
Quoted 1 line · Javier González
Check for failed mempool allocations and act accordingly.
Are you sure it is needed? Quoting from mempool_alloc()s Documentation:
"[...] Note that due to preallocation, this function *never* fails when called from process contexts. (it might fail if called from an IRQ context.) [...]"Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
It's not needed,
mempool()will never fail if__GFP_WAITis set in the mask. The use case here isGFP_KERNEL, which does include__GFP_WAIT.Thanks for the clarification. Do you just drop the patch, or do you want me to re-send the series?
No need to resend. I'll pick up the others in a day or two, once people have had some time to go over them.
Quoted 9 lines
I took a quick look at your mempool usage, and I'm not sure it's correct. For a mempool to work, you have to ensure that you provide a forward progress guarantee. With that guarantee, you know that if you do end up sleeping on allocation, you already have items inflight that will be freed when that operation completes. In other words, all allocations must have a defined and finite life time, as any allocation can potentially sleep/block for that life time. You can't allocate something and hold on to it forever, then you are violating the terms of agreement that makes a mempool work.
I understood the part of guaranteeing the number of inflight items to keep the mempool active without waiting, but I must admit that I assumed that the mempool would resize when getting pressure and that the penalty would be increased latency, not the mempool giving up and causing a deadlock.
Quoted 16 lines
The first one that caught my eye is
pblk->page_pool. You have this loop:for (i = 0; i < nr_pages; i++) { page = mempool_alloc(pblk->page_pool, flags); if (!page) goto err; ret = bio_add_pc_page(q, bio, page, PBLK_EXPOSED_PAGE_SIZE, 0); if (ret != PBLK_EXPOSED_PAGE_SIZE) { pr_err("pblk: could not add page to bio\n"); mempool_free(page, pblk->page_pool); goto err; } }
Quoted 3 lines
which looks suspect. This mempool is created with a reserve pool of
PAGE_POOL_SIZE(16) members. Do we know if the bio has 16 pages or less? If not, then this is broken and can deadlock forever.
I can see that in this case, the 16 elements do not hold. In the read path, we can guarantee that a read will be <= 64 sectors (4KB pages), so this is definitely wrong. I'll fix it tomorrow.
Since we are at it, I have for some time wondered what's the right way to balance the mempool sizes so that we are a good citizen and perform at the same time. I don't see a lot of code using mempool_resize to tune the min_nr based on load. For example, in our write path, the numbers are easy to calculate, but on the read path I completely over-dimensioned the mempool to ensure not having to wait for the completion path. Any good rule of thumb here?
Quoted 2 lines
You have a lot of mempool usage in the code, would probably not hurt to audit all of them.
Yes. I will take a look and add comments to the sizes.
Thanks Jens,
Javier
Re: [PATCH 1/6] lightnvm: pblk: check for failed mempool alloc.
In reply to Jens AxboeQuoted 10 lines · Jens Axboe
Quoted 6 lines · Johannes Thumshirn
Quoted 1 line · Javier Gonz�lez
Check for failed mempool allocations and act accordingly.
Are you sure it is needed? Quoting from mempool_alloc()s Documentation:
"[...] Note that due to preallocation, this function *never* fails when called from process contexts. (it might fail if called from an IRQ context.) [...]"It's not needed,
mempool()will never fail if__GFP_WAITis set in the mask. The use case here isGFP_KERNEL, which does include__GFP_WAIT.
Exactly. Maybe I shouldn't have it phrased as a question though...
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: Felix Imend�rffer, Jane Smithard, Graham Norton HRB 21284 (AG N�rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
PATCH 2/6 lightnvm: pblk: initialize debug stat counter
In reply to Javier GonzálezInitialize the stat counter for garbage collected reads.
--- drivers/lightnvm/pblk-init.c | 1 + 1 file changed, 1 insertion(+)
drivers/lightnvm/pblk-init.c +1 -0
@@ -944,6 +944,7 @@ static void *pblk_init(struct nvm_tgt_dev *dev, struct gendisk *tdisk,atomic_long_set (&pblk->recov_writes,0 );atomic_long_set (&pblk->recov_writes,0 );atomic_long_set (&pblk->recov_gc_writes,0 ); +atomic_long_set (&pblk->recov_gc_reads,0 );#endif atomic_long_set (&pblk->read_failed,0 );
Signature · 1 line
2.7.4
Re: [PATCH 2/6] lightnvm: pblk: initialize debug stat counter
Looks good,
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: Felix Imend�rffer, Jane Smithard, Graham Norton HRB 21284 (AG N�rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
PATCH 3/6 lightnvm: pblk: use right flag for GC allocation
In reply to Javier GonzálezThe data buffer for the GC path allocates virtual memory through vmalloc. When this change was introduced, a flag signaling kmalloc'ed memory was wrongly introduced. Use the right flag when creating a bio from this buffer.
--- drivers/lightnvm/pblk-read.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/lightnvm/pblk-read.c +5 -2
@@ -499,7 +499,7 @@ int pblk_submit_read_gc(struct pblk *pblk, u64 *lba_list, void *data, data_len = (*secs_to_gc) * geo->sec_size; bio =pblk_bio_map_addr (pblk, data, *secs_to_gc, data_len, -PBLK_KMALLOC_META ,GFP_KERNEL ); +PBLK_VMALLOC_META ,GFP_KERNEL );if (IS_ERR (bio)) {pr_err ("pblk: could not allocate GC bio (%lu)\n" ,PTR_ERR (bio)); goto err_free_dma;
@@ -519,7 +519,7 @@ int pblk_submit_read_gc(struct pblk *pblk, u64 *lba_list, void *data,if (ret) {bio_endio (bio);pr_err ("pblk: GC read request failed\n" ); - goto err_free_dma; + goto err_free_bio; } if (!wait_for_completion_io_timeout(&wait,
@@ -541,10 +541,13 @@ int pblk_submit_read_gc(struct pblk *pblk, u64 *lba_list, void *data,atomic_long_sub (*secs_to_gc, &pblk->inflight_reads);#endif +bio_put (bio); out:nvm_dev_dma_free (dev->parent, rqd.meta_list, rqd.dma_meta_list);return NVM_IO_OK ; +err_free_bio: +bio_put (bio); err_free_dma:nvm_dev_dma_free (dev->parent, rqd.meta_list, rqd.dma_meta_list);return NVM_IO_ERR ;
Signature · 1 line
2.7.4
Re: [PATCH 3/6] lightnvm: pblk: use right flag for GC allocation
Looks good,
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: Felix Imend�rffer, Jane Smithard, Graham Norton HRB 21284 (AG N�rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
PATCH 4/6 lightnvm: pblk: free padded entries in write buffer
In reply to Javier GonzálezWhen a REQ_FLUSH reaches pblk, the bio cannot be directly completed. Instead, data on the write buffer is flushed and the bio is completed on the completion pah. This might require some sectors to be padded in order to guarantee a successful write.
This patch fixes a memory leak on the padded pages. A consequence of this bad free was that internal bios not containing data (only a flush) were not being completed.
--- drivers/lightnvm/pblk-core.c | 1 - drivers/lightnvm/pblk-write.c | 14 +++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-)
drivers/lightnvm/pblk-core.c +0 -1
@@ -192,7 +192,6 @@ void pblk_bio_free_pages(struct pblk *pblk, struct bio *bio, int off,WARN_ON (off + nr_pages != bio->bi_vcnt); -bio_advance (bio, off *PBLK_EXPOSED_PAGE_SIZE );for (i = off; i < nr_pages + off; i++) { bv = bio->bi_io_vec[i];mempool_free (bv.bv_page, pblk->page_pool);
drivers/lightnvm/pblk-write.c +11 -3
@@ -25,13 +25,20 @@ static unsigned long pblk_end_w_bio(struct pblk *pblk, struct nvm_rq *rqd,unsigned long ret;int i; -for (i =0 ; i < c_ctx->nr_valid; i++) { + i =0 ; +do {struct pblk_w_ctx *w_ctx; w_ctx =pblk_rb_w_ctx (&pblk->rwb, c_ctx->sentry + i);while ((original_bio =bio_list_pop (&w_ctx->bios)))bio_endio (original_bio); - } + + i++; + }while (i < c_ctx->nr_valid); + +if (c_ctx->nr_padded) +pblk_bio_free_pages (pblk, rqd->bio, c_ctx->nr_valid, + c_ctx->nr_padded);#ifdef CONFIG_NVM_DEBUG atomic_long_add (c_ctx->nr_valid, &pblk->sync_writes);
@@ -521,7 +528,8 @@ static void pblk_free_write_rqd(struct pblk *pblk, struct nvm_rq *rqd)struct bio *bio = rqd->bio;if (c_ctx->nr_padded) -pblk_bio_free_pages (pblk, bio, rqd->nr_ppas, c_ctx->nr_padded); +pblk_bio_free_pages (pblk, bio, c_ctx->nr_valid, + c_ctx->nr_padded); }static int pblk_submit_write (struct pblk *pblk)
Signature · 1 line
2.7.4
Re: [PATCH 4/6] lightnvm: pblk: free padded entries in write buffer
Quoted 1 line · Javier Gonz�lez
the completion pah. This might require some sectors to be padded in
^ path
Looks good otherwise,
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: Felix Imend�rffer, Jane Smithard, Graham Norton HRB 21284 (AG N�rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
PATCH 5/6 lightnvm: pblk: fix write I/O sync stat
In reply to Javier GonzálezFix stat counter to collect the right number of I/Os being synced on the completion path.
--- drivers/lightnvm/pblk-write.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/lightnvm/pblk-write.c +1 -1
@@ -41,7 +41,7 @@ static unsigned long pblk_end_w_bio(struct pblk *pblk, struct nvm_rq *rqd, c_ctx->nr_padded);#ifdef CONFIG_NVM_DEBUG -atomic_long_add (c_ctx->nr_valid, &pblk->sync_writes); +atomic_long_add (rqd->nr_ppas, &pblk->sync_writes);#endif ret =pblk_rb_sync_advance (&pblk->rwb, c_ctx->nr_valid);
Signature · 1 line
2.7.4
Re: [PATCH 5/6] lightnvm: pblk: fix write I/O sync stat
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: Felix Imend�rffer, Jane Smithard, Graham Norton HRB 21284 (AG N�rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
PATCH 6/6 lightnvm: pblk: avoid deadlock on low LUN config
In reply to Javier GonzálezOn low LUN configurations, make sure not to send bios that are bigger than the buffer size.
--- drivers/lightnvm/pblk-init.c | 2 +- drivers/lightnvm/pblk-rl.c | 6 ++++++ drivers/lightnvm/pblk.h | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-)
drivers/lightnvm/pblk-init.c +1 -1
@@ -46,7 +46,7 @@ static int pblk_rw_io(struct request_queue *q, struct pblk *pblk,* user I/Os. Unless stalled, the rate limiter leaves at least 256KB * available for user I/O. */ -if (unlikely (pblk_get_secs (bio) >=pblk_rl_sysfs_rate_show (&pblk->rl))) +if (pblk_get_secs (bio) >pblk_rl_max_io (&pblk->rl))blk_queue_split (q, &bio);return pblk_write_to_cache (pblk, bio,PBLK_IOTYPE_USER );
drivers/lightnvm/pblk-rl.c +6 -0
@@ -178,6 +178,11 @@ int pblk_rl_sysfs_rate_show(struct pblk_rl *rl)return rl->rb_user_max; } +int pblk_rl_max_io (struct pblk_rl *rl) +{ +return rl->rb_max_io; +} +static void pblk_rl_u_timer (unsigned long data) {struct pblk_rl *rl = (struct pblk_rl *)data;
@@ -214,6 +219,7 @@ void pblk_rl_init(struct pblk_rl *rl, int budget)/* To start with, all buffer is available to user I/O writers */ rl->rb_budget = budget; rl->rb_user_max = budget; + rl->rb_max_io = budget >>1 ; rl->rb_gc_max =0 ; rl->rb_state =PBLK_RL_HIGH ;
drivers/lightnvm/pblk.h +2 -0
@@ -267,6 +267,7 @@ struct pblk_rl {int rb_gc_max;/* Max buffer entries available for GC I/O */ int rb_gc_rsv;/* Reserved buffer entries for GC I/O */ int rb_state;/* Rate-limiter current state */ +int rb_max_io;/* Maximum size for an I/O giving the config */ atomic_t rb_user_cnt;/* User I/O buffer counter */ atomic_t rb_gc_cnt;/* GC I/O buffer counter */
@@ -844,6 +845,7 @@ int pblk_rl_gc_may_insert(struct pblk_rl *rl, int nr_entries);void pblk_rl_gc_in (struct pblk_rl *rl,int nr_entries);void pblk_rl_out (struct pblk_rl *rl,int nr_user,int nr_gc);int pblk_rl_sysfs_rate_show (struct pblk_rl *rl); +int pblk_rl_max_io (struct pblk_rl *rl);void pblk_rl_free_lines_inc (struct pblk_rl *rl,struct pblk_line *line);void pblk_rl_free_lines_dec (struct pblk_rl *rl,struct pblk_line *line);void pblk_rl_set_space_limit (struct pblk_rl *rl,int entries_left);
Signature · 1 line
2.7.4