Skip to content

Commit

Permalink
block: optionally mark pages dirty in bio_release_pages
Browse files Browse the repository at this point in the history
A lot of callers of bio_release_pages also want to mark the released
pages as dirty.  Add a mark_dirty parameter to avoid a second
relatively expensive bio_for_each_segment_all loop.

Reviewed-by: Minwoo Im <minwoo.im.dev@gmail.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Christoph Hellwig authored and Jens Axboe committed Jun 29, 2019
1 parent b2d0d99 commit d241a95
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions block/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -845,16 +845,19 @@ static void bio_get_pages(struct bio *bio)
get_page(bvec->bv_page);
}

void bio_release_pages(struct bio *bio)
void bio_release_pages(struct bio *bio, bool mark_dirty)
{
struct bvec_iter_all iter_all;
struct bio_vec *bvec;

if (bio_flagged(bio, BIO_NO_PAGE_REF))
return;

bio_for_each_segment_all(bvec, bio, iter_all)
bio_for_each_segment_all(bvec, bio, iter_all) {
if (mark_dirty && !PageCompound(bvec->bv_page))
set_page_dirty_lock(bvec->bv_page);
put_page(bvec->bv_page);
}
}

static int __bio_iov_bvec_add_pages(struct bio *bio, struct iov_iter *iter)
Expand Down Expand Up @@ -1683,8 +1686,7 @@ static void bio_dirty_fn(struct work_struct *work)
while ((bio = next) != NULL) {
next = bio->bi_private;

bio_set_pages_dirty(bio);
bio_release_pages(bio);
bio_release_pages(bio, true);
bio_put(bio);
}
}
Expand All @@ -1700,7 +1702,7 @@ void bio_check_pages_dirty(struct bio *bio)
goto defer;
}

bio_release_pages(bio);
bio_release_pages(bio, false);
bio_put(bio);
return;
defer:
Expand Down
2 changes: 1 addition & 1 deletion include/linux/bio.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ bool __bio_try_merge_page(struct bio *bio, struct page *page,
void __bio_add_page(struct bio *bio, struct page *page,
unsigned int len, unsigned int off);
int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter);
void bio_release_pages(struct bio *bio);
void bio_release_pages(struct bio *bio, bool mark_dirty);
struct rq_map_data;
extern struct bio *bio_map_user_iov(struct request_queue *,
struct iov_iter *, gfp_t);
Expand Down

0 comments on commit d241a95

Please sign in to comment.