block: fix handling for BIO_NO_PAGE_REF [Linux 5.1]

block: fix handling for BIO_NO_PAGE_REF [Linux 5.1]

This Linux kernel change "block: fix handling for BIO_NO_PAGE_REF" is included in the Linux 5.1 release. This change is authored by Ming Lei <ming.lei [at]> on Fri Apr 26 18:45:20 2019 +0800. The commit for this change in Linux stable tree is 60a27b9 (patch).

block: fix handling for BIO_NO_PAGE_REF

Commit 399254aaf489211 ("block: add BIO_NO_PAGE_REF flag") introduces
BIO_NO_PAGE_REF, and once this flag is set for one bio, all pages
in the bio won't be get/put during IO.

However, if one bio is submitted via __blkdev_direct_IO_simple(),
even though BIO_NO_PAGE_REF is set, pages still may be put.

Fixes this issue by avoiding to put pages if BIO_NO_PAGE_REF is

Fixes: 399254aaf489211 ("block: add BIO_NO_PAGE_REF flag")
Reviewed-by: Christoph Hellwig <>
Signed-off-by: Ming Lei <>
Signed-off-by: Jens Axboe <>

There are 3 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 fs/block_dev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/block_dev.c b/fs/block_dev.c
index 24615c7..bb28e2e 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -264,7 +264,8 @@ static void blkdev_bio_end_io_simple(struct bio *bio)
    bio_for_each_segment_all(bvec, &bio, i, iter_all) {
        if (should_dirty && !PageCompound(bvec->bv_page))
-       put_page(bvec->bv_page);
+       if (!bio_flagged(&bio, BIO_NO_PAGE_REF))
+           put_page(bvec->bv_page);

    if (unlikely(bio.bi_status))

Leave a Reply

Your email address will not be published. Required fields are marked *