lightnvm: pblk: fix freeing of merged pages
authorHeiner Litz <hlitz@ucsc.edu>
Fri, 21 Jun 2019 09:11:59 +0000 (11:11 +0200)
committerJens Axboe <axboe@kernel.dk>
Fri, 21 Jun 2019 09:14:29 +0000 (03:14 -0600)
bio_add_pc_page() may merge pages when a bio is padded due to a flush.
Fix iteration over the bio to free the correct pages in case of a merge.

Signed-off-by: Heiner Litz <hlitz@ucsc.edu>
Reviewed-by: Javier González <javier@javigon.com>
Signed-off-by: Matias Bjørling <mb@lightnvm.io>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/lightnvm/pblk-core.c

index 7735378043199dd1eb1437449bfcce0d994965f5..f546e6f28b8afbad37f89315272efb040722bfcd 100644 (file)
@@ -323,14 +323,16 @@ void pblk_free_rqd(struct pblk *pblk, struct nvm_rq *rqd, int type)
 void pblk_bio_free_pages(struct pblk *pblk, struct bio *bio, int off,
                         int nr_pages)
 {
-       struct bio_vec bv;
-       int i;
-
-       WARN_ON(off + nr_pages != bio->bi_vcnt);
-
-       for (i = off; i < nr_pages + off; i++) {
-               bv = bio->bi_io_vec[i];
-               mempool_free(bv.bv_page, &pblk->page_bio_pool);
+       struct bio_vec *bv;
+       struct page *page;
+       int i, e, nbv = 0;
+
+       for (i = 0; i < bio->bi_vcnt; i++) {
+               bv = &bio->bi_io_vec[i];
+               page = bv->bv_page;
+               for (e = 0; e < bv->bv_len; e += PBLK_EXPOSED_PAGE_SIZE, nbv++)
+                       if (nbv >= off)
+                               mempool_free(page++, &pblk->page_bio_pool);
        }
 }