Skip to content

Commit b4cdc42

Browse files
javigonaxboe
authored andcommitted
lightnvm: pblk: prevent stall due to wb threshold
In order to respect mw_cuinits, pblk's write buffer maintains a backpointer to protect data not yet persisted; when writing to the write buffer, this backpointer defines a threshold that pblk's rate-limiter enforces. On small PU configurations, the following scenarios might take place: (i) the threshold is larger than the write buffer and (ii) the threshold is smaller than the write buffer, but larger than the maximun allowed split bio - 256KB at this moment (Note that writes are not always split - we only do this when we the size of the buffer is smaller than the buffer). In both cases, pblk's rate-limiter prevents the I/O to be written to the buffer, thus stalling. This patch fixes the original backpointer implementation by considering the threshold both on buffer creation and on the rate-limiters path, when bio_split is triggered (case (ii) above). Fixes: 766c8ce ("lightnvm: pblk: guarantee that backpointer is respected on writer stall") Signed-off-by: Javier González <javier@javigon.com> Reviewed-by: Hans Holmberg <hans.holmberg@cnexlabs.com> Signed-off-by: Matias Bjørling <mb@lightnvm.io> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent aa8759d commit b4cdc42

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

‎drivers/lightnvm/pblk-rb.c‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,23 @@ void pblk_rb_free(struct pblk_rb *rb)
4545
/*
4646
* pblk_rb_calculate_size -- calculate the size of the write buffer
4747
*/
48-
static unsigned int pblk_rb_calculate_size(unsigned int nr_entries)
48+
static unsigned int pblk_rb_calculate_size(unsigned int nr_entries,
49+
unsigned int threshold)
4950
{
50-
/* Alloc a write buffer that can at least fit 128 entries */
51-
return (1 << max(get_count_order(nr_entries), 7));
51+
unsigned int thr_sz = 1 << (get_count_order(threshold + NVM_MAX_VLBA));
52+
unsigned int max_sz = max(thr_sz, nr_entries);
53+
unsigned int max_io;
54+
55+
/* Alloc a write buffer that can (i) fit at least two split bios
56+
* (considering max I/O size NVM_MAX_VLBA, and (ii) guarantee that the
57+
* threshold will be respected
58+
*/
59+
max_io = (1 << max((int)(get_count_order(max_sz)),
60+
(int)(get_count_order(NVM_MAX_VLBA << 1))));
61+
if ((threshold + NVM_MAX_VLBA) >= max_io)
62+
max_io <<= 1;
63+
64+
return max_io;
5265
}
5366

5467
/*
@@ -67,12 +80,12 @@ int pblk_rb_init(struct pblk_rb *rb, unsigned int size, unsigned int threshold,
6780
unsigned int alloc_order, order, iter;
6881
unsigned int nr_entries;
6982

70-
nr_entries = pblk_rb_calculate_size(size);
83+
nr_entries = pblk_rb_calculate_size(size, threshold);
7184
entries = vzalloc(array_size(nr_entries, sizeof(struct pblk_rb_entry)));
7285
if (!entries)
7386
return -ENOMEM;
7487

75-
power_size = get_count_order(size);
88+
power_size = get_count_order(nr_entries);
7689
power_seg_sz = get_count_order(seg_size);
7790

7891
down_write(&pblk_rb_lock);
@@ -149,7 +162,7 @@ int pblk_rb_init(struct pblk_rb *rb, unsigned int size, unsigned int threshold,
149162
* Initialize rate-limiter, which controls access to the write buffer
150163
* by user and GC I/O
151164
*/
152-
pblk_rl_init(&pblk->rl, rb->nr_entries);
165+
pblk_rl_init(&pblk->rl, rb->nr_entries, threshold);
153166

154167
return 0;
155168
}

‎drivers/lightnvm/pblk-rl.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void pblk_rl_free(struct pblk_rl *rl)
207207
del_timer(&rl->u_timer);
208208
}
209209

210-
void pblk_rl_init(struct pblk_rl *rl, int budget)
210+
void pblk_rl_init(struct pblk_rl *rl, int budget, int threshold)
211211
{
212212
struct pblk *pblk = container_of(rl, struct pblk, rl);
213213
struct nvm_tgt_dev *dev = pblk->dev;
@@ -217,7 +217,6 @@ void pblk_rl_init(struct pblk_rl *rl, int budget)
217217
int sec_meta, blk_meta;
218218
unsigned int rb_windows;
219219

220-
221220
/* Consider sectors used for metadata */
222221
sec_meta = (lm->smeta_sec + lm->emeta_sec[0]) * l_mg->nr_free_lines;
223222
blk_meta = DIV_ROUND_UP(sec_meta, geo->clba);
@@ -234,7 +233,7 @@ void pblk_rl_init(struct pblk_rl *rl, int budget)
234233
/* To start with, all buffer is available to user I/O writers */
235234
rl->rb_budget = budget;
236235
rl->rb_user_max = budget;
237-
rl->rb_max_io = budget >> 1;
236+
rl->rb_max_io = threshold ? (budget - threshold) : (budget - 1);
238237
rl->rb_gc_max = 0;
239238
rl->rb_state = PBLK_RL_HIGH;
240239

‎drivers/lightnvm/pblk.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ int pblk_gc_sysfs_force(struct pblk *pblk, int force);
924924
/*
925925
* pblk rate limiter
926926
*/
927-
void pblk_rl_init(struct pblk_rl *rl, int budget);
927+
void pblk_rl_init(struct pblk_rl *rl, int budget, int threshold);
928928
void pblk_rl_free(struct pblk_rl *rl);
929929
void pblk_rl_update_rates(struct pblk_rl *rl);
930930
int pblk_rl_high_thrs(struct pblk_rl *rl);

0 commit comments

Comments
 (0)