lightnvm: pblk: allocate bio size more accurately
authorJavier González <javier@cnexlabs.com>
Fri, 13 Oct 2017 12:46:18 +0000 (14:46 +0200)
committerJens Axboe <axboe@kernel.dk>
Fri, 13 Oct 2017 14:34:57 +0000 (08:34 -0600)
Wait until we know the exact number of ppas to be sent to the device,
before allocating the bio.

Signed-off-by: Javier González <javier@cnexlabs.com>
Signed-off-by: Matias Bjørling <m@bjorling.me>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/lightnvm/pblk-rb.c
drivers/lightnvm/pblk-write.c
drivers/lightnvm/pblk.h

index 05e6b2e9221df380b9e7c9525e2ff5d985fd8e53..1173e2380137dfb3880448c74de129b334ac89de 100644 (file)
@@ -552,12 +552,13 @@ out:
  * persist data on the write buffer to the media.
  */
 unsigned int pblk_rb_read_to_bio(struct pblk_rb *rb, struct nvm_rq *rqd,
-                                struct bio *bio, unsigned int pos,
-                                unsigned int nr_entries, unsigned int count)
+                                unsigned int pos, unsigned int nr_entries,
+                                unsigned int count)
 {
        struct pblk *pblk = container_of(rb, struct pblk, rwb);
        struct request_queue *q = pblk->dev->q;
        struct pblk_c_ctx *c_ctx = nvm_rq_to_pdu(rqd);
+       struct bio *bio = rqd->bio;
        struct pblk_rb_entry *entry;
        struct page *page;
        unsigned int pad = 0, to_read = nr_entries;
index 0c0481cf9f5d2832ca01e8ac731a748375f116b4..140a26edd1d3d292d91c524844626b913c1b966b 100644 (file)
@@ -534,24 +534,24 @@ static int pblk_submit_write(struct pblk *pblk)
        if (!secs_to_flush && secs_avail < pblk->min_write_pgs)
                return 1;
 
-       bio = bio_alloc(GFP_KERNEL, pblk->max_write_pgs);
-
-       bio->bi_iter.bi_sector = 0; /* internal bio */
-       bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
-
-       rqd = pblk_alloc_rqd(pblk, WRITE);
-       rqd->bio = bio;
-
        secs_to_sync = pblk_calc_secs_to_sync(pblk, secs_avail, secs_to_flush);
        if (secs_to_sync > pblk->max_write_pgs) {
                pr_err("pblk: bad buffer sync calculation\n");
-               goto fail_put_bio;
+               return 1;
        }
 
        secs_to_com = (secs_to_sync > secs_avail) ? secs_avail : secs_to_sync;
        pos = pblk_rb_read_commit(&pblk->rwb, secs_to_com);
 
-       if (pblk_rb_read_to_bio(&pblk->rwb, rqd, bio, pos, secs_to_sync,
+       bio = bio_alloc(GFP_KERNEL, secs_to_sync);
+
+       bio->bi_iter.bi_sector = 0; /* internal bio */
+       bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
+
+       rqd = pblk_alloc_rqd(pblk, WRITE);
+       rqd->bio = bio;
+
+       if (pblk_rb_read_to_bio(&pblk->rwb, rqd, pos, secs_to_sync,
                                                                secs_avail)) {
                pr_err("pblk: corrupted write bio\n");
                goto fail_put_bio;
index 876b50f97234aa0946587e6135ab25c38f137f52..9f162057d4971cf902277bf1f0c68c3367b8301b 100644 (file)
@@ -666,8 +666,8 @@ void pblk_rb_flush(struct pblk_rb *rb);
 
 void pblk_rb_sync_l2p(struct pblk_rb *rb);
 unsigned int pblk_rb_read_to_bio(struct pblk_rb *rb, struct nvm_rq *rqd,
-                                struct bio *bio, unsigned int pos,
-                                unsigned int nr_entries, unsigned int count);
+                                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);