cleanup bio page releasing
Subsystems (3)
Hi Jens,
this series cleans up the various direct I/O and pass through routines by switching them over to common bio helpers.
The last patch just unconditionally applies the no page ref behavior for bvec iters. I looked at all the callers, and there is none that drops the pre-required references before completing the request.
PATCH 1/9 block: move the BIO_NO_PAGE_REF check into bio_release_pages
Move the BIO_NO_PAGE_REF check into bio_release_pages instead of duplicating it in both callers.
Also make the function available outside of bio.c so that we can reuse it in other direct I/O implementations.
--- block/bio.c | 11 ++++++----- include/linux/bio.h | 1 + 2 files changed, 7 insertions(+), 5 deletions(-)
block/bio.c +6 -5
@@ -845,11 +845,14 @@ static void bio_get_pages(struct bio *bio)get_page (bvec->bv_page); } -static void bio_release_pages (struct bio *bio) +void bio_release_pages (struct bio *bio) {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)put_page (bvec->bv_page); }
@@ -1681,8 +1684,7 @@ static void bio_dirty_fn(struct work_struct *work) next = bio->bi_private;bio_set_pages_dirty (bio); -if (!bio_flagged (bio,BIO_NO_PAGE_REF )) -bio_release_pages (bio); +bio_release_pages (bio);bio_put (bio); } }
@@ -1698,8 +1700,7 @@ void bio_check_pages_dirty(struct bio *bio) goto defer; } -if (!bio_flagged (bio,BIO_NO_PAGE_REF )) -bio_release_pages (bio); +bio_release_pages (bio);bio_put (bio);return ; defer:
include/linux/bio.h +1 -0
@@ -426,6 +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);struct rq_map_data ;extern struct bio *bio_map_user_iov (struct request_queue *,struct iov_iter *,gfp_t );
Signature · 1 line
2.20.1
Re: [PATCH 1/9] block: move the BIO_NO_PAGE_REF check into bio_release_pages
Quoted 2 lines · Christoph Hellwig
Move the
BIO_NO_PAGE_REFcheck intobio_release_pagesinstead of duplicating it in both callers.
This part looks good to me.
Quoted 2 lines
Also make the function available outside of
bio.cso that we can reuse it in other direct I/O implementations.
This is also for the next patches.
PATCH 2/9 block: optionally mark pages dirty in bio_release_pages
In reply to Christoph HellwigA 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.
--- block/bio.c | 12 +++++++----- include/linux/bio.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-)
block/bio.c +7 -5
@@ -845,7 +845,7 @@ 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;
@@ -853,8 +853,11 @@ void bio_release_pages(struct bio *bio)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)
@@ -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); } }
@@ -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:
include/linux/bio.h +1 -1
@@ -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 );
Signature · 1 line
2.20.1
Re: [PATCH 2/9] block: optionally mark pages dirty in bio_release_pages
Quoted 24 lines · Christoph Hellwig
A lot of callers of
bio_release_pagesalso want to mark the released pages as dirty. Add amark_dirtyparameter to avoid a second relatively expensivebio_for_each_segment_allloop.Signed-off-by Christoph Hellwig <[email protected]>--- block/bio.c | 12 +++++++----- include/linux/bio.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-)block/bio.c +1
-1@@ -845,7 +845,7 @@ 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;
block/bio.c void bio_release_pages(struct bio *bio) · line 858
Quoted 7 lines
block/bio.c +3
-1@@ -853,8 +853,11 @@ void bio_release_pages(struct bio *bio)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);
Christoph,
Could you please explain a bit why we should not make it dirty in case of compound page?
Re: [PATCH 2/9] block: optionally mark pages dirty in bio_release_pages
On 6/26/19, 1:52 PM, "[email protected] on behalf of Minwoo Im" <[email protected] on behalf of [email protected]> wrote:
On 19-06-26 15:49:21, Christoph Hellwig wrote:
> 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.
>
> Signed-off-by: Christoph Hellwig <[email protected]>
> ---
> block/bio.c | 12 +++++++-----
> include/linux/bio.h | 2 +-
> 2 files changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/block/bio.c b/block/bio.c
> index 9bc7d28ae997..7f3920b6baca 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -845,7 +845,7 @@ 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;
> @@ -853,8 +853,11 @@ void bio_release_pages(struct bio *bio)
> 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);
Christoph,
Could you please explain a bit why we should not make it dirty in case
of compound page?Maybe because of [PATCH 7/9] block_dev: use bio_release_pages in bio_unmap_user :-
@@ -259,13 +258,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,
} __set_current_state(TASK_RUNNING);
- bio_for_each_segment_all(bvec, &bio, iter_all) {
- if (should_dirty && !PageCompound(bvec->bv_page))
- set_page_dirty_lock(bvec->bv_page);
- if (!bio_flagged(&bio, BIO_NO_PAGE_REF))
- put_page(bvec->bv_page);
- }
-
+ bio_release_pages(&bio, should_dirty);
I'll let Christoph confirm that.
Re: [PATCH 2/9] block: optionally mark pages dirty in bio_release_pages
Quoted 56 lines · Chaitanya Kulkarni
On 6/26/19, 1:52 PM, "[email protected] on behalf of Minwoo Im" <[email protected] on behalf of [email protected]> wrote:
On 19-06-26 15:49:21, Christoph Hellwig wrote: > 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. > > Signed-off-by: Christoph Hellwig <[email protected]> > --- > block/bio.c | 12 +++++++----- > include/linux/bio.h | 2 +- > 2 files changed, 8 insertions(+), 6 deletions(-) > > diff --git a/block/bio.c b/block/bio.c > index 9bc7d28ae997..7f3920b6baca 100644 > --- a/block/bio.c > +++ b/block/bio.c > @@ -845,7 +845,7 @@ 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; > @@ -853,8 +853,11 @@ void bio_release_pages(struct bio *bio) > 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); Christoph, Could you please explain a bit why we should not make it dirty in case of compound page?Maybe because of [PATCH 7/9]
block_dev: usebio_release_pagesinbio_unmap_user:-(quoted diff) +1
-7@@ -259,13 +258,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter, } __set_current_state(TASK_RUNNING); - bio_for_each_segment_all(bvec, &bio, iter_all) { - if (should_dirty && !PageCompound(bvec->bv_page)) - set_page_dirty_lock(bvec->bv_page); - if (!bio_flagged(&bio, BIO_NO_PAGE_REF)) - put_page(bvec->bv_page); - } - + bio_release_pages(&bio, should_dirty);
Quoted 1 line
I'll let Christoph confirm that.
Chaitanya,
Thanks for sharing this. Actually I have seen that commit log but didn't catch up why the compound pages are so. Now I understood what Christoph has mentioned.
Thanks for your help, again.
Re: [PATCH 2/9] block: optionally mark pages dirty in bio_release_pages
In reply to Minwoo ImQuoted 2 lines · Minwoo Im
Could you please explain a bit why we should not make it dirty in case of compound page?
PageCompount is only true for the tail pages, and marking them dirty doesn't work. On the other hand marking the head page dirty covers the whole compount, so we are fine.
Re: [PATCH 2/9] block: optionally mark pages dirty in bio_release_pages
Quoted 7 lines · Christoph Hellwig
Quoted 2 lines · Minwoo Im
Could you please explain a bit why we should not make it dirty in case of compound page?
PageCompount is only true for the tail pages, and marking them dirty doesn't work. On the other hand marking the head page dirty covers the whole compount, so we are fine.
Christoph,
Thanks for letting me know this.
PATCH 3/9 block: use bio_release_pages in bio_unmap_user
In reply to Christoph HellwigUse bio_release_pages instead of open coding it.
--- block/bio.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-)
block/bio.c +2 -19
@@ -1437,24 +1437,6 @@ struct bio *bio_map_user_iov(struct request_queue *q,return ERR_PTR (ret); } -static void __bio_unmap_user (struct bio *bio) -{ -struct bio_vec *bvec; -struct bvec_iter_all iter_all; - -/* -* make sure we dirty pages we wrote to -*/ -bio_for_each_segment_all (bvec, bio, iter_all) { -if (bio_data_dir (bio) ==READ ) -set_page_dirty_lock (bvec->bv_page); - -put_page (bvec->bv_page); - } - -bio_put (bio); -} -/** * bio_unmap_user - unmap a bio * @bio: the bio being unmapped
@@ -1466,7 +1448,8 @@ static void __bio_unmap_user(struct bio *bio)*/ void bio_unmap_user (struct bio *bio) { -__bio_unmap_user (bio); +bio_release_pages (bio,bio_data_dir (bio) ==READ ); +bio_put (bio);bio_put (bio); }
Signature · 1 line
2.20.1
Re: [PATCH 3/9] block: use bio_release_pages in bio_unmap_user
Looks good.
Quoted 47 lines · Christoph Hellwig
Use
bio_release_pagesinstead of open coding it.Signed-off-by Christoph Hellwig <[email protected]>--- block/bio.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-)block/bio.c +2
-19@@ -1437,24 +1437,6 @@ struct bio *bio_map_user_iov(struct request_queue *q,return ERR_PTR (ret); } -static void __bio_unmap_user (struct bio *bio) -{ -struct bio_vec *bvec; -struct bvec_iter_all iter_all; - -/* -* make sure we dirty pages we wrote to -*/ -bio_for_each_segment_all (bvec, bio, iter_all) { -if (bio_data_dir (bio) ==READ ) -set_page_dirty_lock (bvec->bv_page); - -put_page (bvec->bv_page); - } - -bio_put (bio); -} -/** * bio_unmap_user - unmap a bio * @bio: the bio being unmapped @@ -1466,7 +1448,8 @@ static void __bio_unmap_user(struct bio *bio)*/ void bio_unmap_user (struct bio *bio) { -__bio_unmap_user (bio); +bio_release_pages (bio,bio_data_dir (bio) ==READ ); +bio_put (bio);bio_put (bio); }
PATCH 4/9 block: use bio_release_pages in bio_map_user_iov
In reply to Christoph HellwigUse bio_release_pages instead of open coding it.
--- block/bio.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
block/bio.c +1 -5
@@ -1362,8 +1362,6 @@ struct bio *bio_map_user_iov(struct request_queue *q,int j;struct bio *bio;int ret; -struct bio_vec *bvec; -struct bvec_iter_all iter_all;if (!iov_iter_count (iter))return ERR_PTR (-EINVAL );
@@ -1430,9 +1428,7 @@ struct bio *bio_map_user_iov(struct request_queue *q,return bio; out_unmap: -bio_for_each_segment_all (bvec, bio, iter_all) { -put_page (bvec->bv_page); - } +bio_release_pages (bio, false);bio_put (bio);return ERR_PTR (ret); }
Signature · 1 line
2.20.1
Re: [PATCH 4/9] block: use bio_release_pages in bio_map_user_iov
This looks good to me.
Re: [PATCH 4/9] block: use bio_release_pages in bio_map_user_iov
In reply to Christoph HellwigLooks good.
Quoted 32 lines · Christoph Hellwig
Use
bio_release_pagesinstead of open coding it.Signed-off-by Christoph Hellwig <[email protected]>--- block/bio.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)block/bio.c +1
-5@@ -1362,8 +1362,6 @@ struct bio *bio_map_user_iov(struct request_queue *q,int j;struct bio *bio;int ret; -struct bio_vec *bvec; -struct bvec_iter_all iter_all;if (!iov_iter_count (iter))return ERR_PTR (-EINVAL );@@ -1430,9 +1428,7 @@ struct bio *bio_map_user_iov(struct request_queue *q,return bio; out_unmap: -bio_for_each_segment_all (bvec, bio, iter_all) { -put_page (bvec->bv_page); - } +bio_release_pages (bio, false);bio_put (bio);return ERR_PTR (ret); }
PATCH 5/9 iomap: use bio_release_pages in iomap_dio_bio_end_io
In reply to Christoph HellwigUse bio_release_pages instead of duplicating it.
--- fs/iomap.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
fs/iomap.c +1 -7
@@ -1595,13 +1595,7 @@ static void iomap_dio_bio_end_io(struct bio *bio)if (should_dirty) {bio_check_pages_dirty (bio); }else { -if (!bio_flagged (bio,BIO_NO_PAGE_REF )) { -struct bvec_iter_all iter_all; -struct bio_vec *bvec; - -bio_for_each_segment_all (bvec, bio, iter_all) -put_page (bvec->bv_page); - } +bio_release_pages (bio, false);bio_put (bio); } }
Signature · 1 line
2.20.1
Re: [PATCH 5/9] iomap: use bio_release_pages in iomap_dio_bio_end_io
This looks good to me.
Re: [PATCH 5/9] iomap: use bio_release_pages in iomap_dio_bio_end_io
In reply to Christoph HellwigLooks good.
Quoted 27 lines · Christoph Hellwig
Use
bio_release_pagesinstead of duplicating it.Signed-off-by Christoph Hellwig <[email protected]>--- fs/iomap.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)fs/iomap.c +1
-7@@ -1595,13 +1595,7 @@ static void iomap_dio_bio_end_io(struct bio *bio)if (should_dirty) {bio_check_pages_dirty (bio); }else { -if (!bio_flagged (bio,BIO_NO_PAGE_REF )) { -struct bvec_iter_all iter_all; -struct bio_vec *bvec; - -bio_for_each_segment_all (bvec, bio, iter_all) -put_page (bvec->bv_page); - } +bio_release_pages (bio, false);bio_put (bio); } }
PATCH 6/9 block_dev: use bio_release_pages in blkdev_bio_end_io
In reply to Christoph HellwigUse bio_release_pages instead of duplicating it.
--- fs/block_dev.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
fs/block_dev.c +1 -7
@@ -335,13 +335,7 @@ static void blkdev_bio_end_io(struct bio *bio)if (should_dirty) {bio_check_pages_dirty (bio); }else { -if (!bio_flagged (bio,BIO_NO_PAGE_REF )) { -struct bvec_iter_all iter_all; -struct bio_vec *bvec; - -bio_for_each_segment_all (bvec, bio, iter_all) -put_page (bvec->bv_page); - } +bio_release_pages (bio, false);bio_put (bio); } }
Signature · 1 line
2.20.1
Re: [PATCH 6/9] block_dev: use bio_release_pages in blkdev_bio_end_io
Re: [PATCH 6/9] block_dev: use bio_release_pages in blkdev_bio_end_io
In reply to Christoph HellwigLooks good.
Quoted 27 lines · Christoph Hellwig
Use
bio_release_pagesinstead of duplicating it.Signed-off-by Christoph Hellwig <[email protected]>--- fs/block_dev.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)fs/block_dev.c +1
-7@@ -335,13 +335,7 @@ static void blkdev_bio_end_io(struct bio *bio)if (should_dirty) {bio_check_pages_dirty (bio); }else { -if (!bio_flagged (bio,BIO_NO_PAGE_REF )) { -struct bvec_iter_all iter_all; -struct bio_vec *bvec; - -bio_for_each_segment_all (bvec, bio, iter_all) -put_page (bvec->bv_page); - } +bio_release_pages (bio, false);bio_put (bio); } }
PATCH 7/9 block_dev: use bio_release_pages in bio_unmap_user
In reply to Christoph HellwigUse bio_release_pages instead of duplicating it.
--- fs/block_dev.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
fs/block_dev.c +2 -9
@@ -203,13 +203,12 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter, {struct file *file = iocb->ki_filp;struct block_device *bdev =I_BDEV (bdev_file_inode (file)); -struct bio_vec inline_vecs[DIO_INLINE_BIO_VECS ], *vecs, *bvec; +struct bio_vec inline_vecs[DIO_INLINE_BIO_VECS ], *vecs;loff_t pos = iocb->ki_pos;bool should_dirty = false;struct bio bio;ssize_t ret;blk_qc_t qc; -struct bvec_iter_all iter_all;if ((pos |iov_iter_alignment (iter)) & (bdev_logical_block_size (bdev) -1 ))
@@ -259,13 +258,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter, }__set_current_state (TASK_RUNNING ); -bio_for_each_segment_all (bvec, &bio, iter_all) { -if (should_dirty && !PageCompound (bvec->bv_page)) -set_page_dirty_lock (bvec->bv_page); -if (!bio_flagged (&bio,BIO_NO_PAGE_REF )) -put_page (bvec->bv_page); - } - +bio_release_pages (&bio, should_dirty);if (unlikely (bio.bi_status)) ret =blk_status_to_errno (bio.bi_status);
Signature · 1 line
2.20.1
Re: [PATCH 7/9] block_dev: use bio_release_pages in bio_unmap_user
Looks good.
Quoted 42 lines · Christoph Hellwig
Use
bio_release_pagesinstead of duplicating it.Signed-off-by Christoph Hellwig <[email protected]>--- fs/block_dev.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)fs/block_dev.c +2
-9@@ -203,13 +203,12 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter, {struct file *file = iocb->ki_filp;struct block_device *bdev =I_BDEV (bdev_file_inode (file)); -struct bio_vec inline_vecs[DIO_INLINE_BIO_VECS ], *vecs, *bvec; +struct bio_vec inline_vecs[DIO_INLINE_BIO_VECS ], *vecs;loff_t pos = iocb->ki_pos;bool should_dirty = false;struct bio bio;ssize_t ret;blk_qc_t qc; -struct bvec_iter_all iter_all;if ((pos |iov_iter_alignment (iter)) & (bdev_logical_block_size (bdev) -1 ))@@ -259,13 +258,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter, }__set_current_state (TASK_RUNNING ); -bio_for_each_segment_all (bvec, &bio, iter_all) { -if (should_dirty && !PageCompound (bvec->bv_page)) -set_page_dirty_lock (bvec->bv_page); -if (!bio_flagged (&bio,BIO_NO_PAGE_REF )) -put_page (bvec->bv_page); - } - +bio_release_pages (&bio, should_dirty);if (unlikely (bio.bi_status)) ret =blk_status_to_errno (bio.bi_status);
PATCH 8/9 direct-io: use bio_release_pages in dio_bio_complete
In reply to Christoph HellwigUse bio_release_pages instead of duplicating it.
--- fs/direct-io.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)
fs/direct-io.c +3 -12
@@ -538,8 +538,8 @@ static struct bio *dio_await_one(struct dio *dio)*/ static blk_status_t dio_bio_complete (struct dio *dio,struct bio *bio) { -struct bio_vec *bvec;blk_status_t err = bio->bi_status; +bool should_dirty = dio->op ==REQ_OP_READ && dio->should_dirty;if (err) {if (err ==BLK_STS_AGAIN && (bio->bi_opf &REQ_NOWAIT ))
@@ -548,19 +548,10 @@ static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio) dio->io_error = -EIO ; } -if (dio->is_async && dio->op ==REQ_OP_READ && dio->should_dirty) { +if (dio->is_async && should_dirty) {bio_check_pages_dirty (bio);/* transfers ownership */ }else { -struct bvec_iter_all iter_all; - -bio_for_each_segment_all (bvec, bio, iter_all) { -struct page *page = bvec->bv_page; - -if (dio->op ==REQ_OP_READ && !PageCompound (page) && - dio->should_dirty) -set_page_dirty_lock (page); -put_page (page); - } +bio_release_pages (bio, should_dirty);bio_put (bio); }return err;
Signature · 1 line
2.20.1
Re: [PATCH 8/9] direct-io: use bio_release_pages in dio_bio_complete
Looks good.
Quoted 44 lines · Christoph Hellwig
Use
bio_release_pagesinstead of duplicating it.Signed-off-by Christoph Hellwig <[email protected]>--- fs/direct-io.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)fs/direct-io.c +3
-12@@ -538,8 +538,8 @@ static struct bio *dio_await_one(struct dio *dio)*/ static blk_status_t dio_bio_complete (struct dio *dio,struct bio *bio) { -struct bio_vec *bvec;blk_status_t err = bio->bi_status; +bool should_dirty = dio->op ==REQ_OP_READ && dio->should_dirty;if (err) {if (err ==BLK_STS_AGAIN && (bio->bi_opf &REQ_NOWAIT ))@@ -548,19 +548,10 @@ static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio) dio->io_error = -EIO ; } -if (dio->is_async && dio->op ==REQ_OP_READ && dio->should_dirty) { +if (dio->is_async && should_dirty) {bio_check_pages_dirty (bio);/* transfers ownership */ }else { -struct bvec_iter_all iter_all; - -bio_for_each_segment_all (bvec, bio, iter_all) { -struct page *page = bvec->bv_page; - -if (dio->op ==REQ_OP_READ && !PageCompound (page) && - dio->should_dirty) -set_page_dirty_lock (page); -put_page (page); - } +bio_release_pages (bio, should_dirty);bio_put (bio); }return err;
PATCH 9/9 block: never take page references for ITER_BVEC
In reply to Christoph HellwigIf we pass pages through an iov_iter we always already have a reference in the caller. Thus remove the ITER_BVEC_FLAG_NO_REF and don't take reference to pages by default for bvec backed iov_iters.
--- block/bio.c | 14 +------------- drivers/block/loop.c | 16 ++++------------ fs/io_uring.c | 3 --- include/linux/uio.h | 10 +--------- 4 files changed, 6 insertions(+), 37 deletions(-)
block/bio.c +1 -13
@@ -836,15 +836,6 @@ int bio_add_page(struct bio *bio, struct page *page, }EXPORT_SYMBOL (bio_add_page); -static void bio_get_pages (struct bio *bio) -{ -struct bvec_iter_all iter_all; -struct bio_vec *bvec; - -bio_for_each_segment_all (bvec, bio, iter_all) -get_page (bvec->bv_page); -} -void bio_release_pages (struct bio *bio,bool mark_dirty) {struct bvec_iter_all iter_all;
@@ -960,11 +951,8 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) ret =__bio_iov_iter_get_pages (bio, iter); }while (!ret &&iov_iter_count (iter) && !bio_full (bio)); -if (iov_iter_bvec_no_ref (iter)) +if (is_bvec)bio_set_flag (bio,BIO_NO_PAGE_REF ); -else if (is_bvec) -bio_get_pages (bio); -return bio->bi_vcnt ?0 : ret; }
drivers/block/loop.c +4 -12
@@ -264,20 +264,12 @@ lo_do_transfer(struct loop_device *lo, int cmd,return ret; } -static inline void loop_iov_iter_bvec (struct iov_iter *i, -unsigned int direction,const struct bio_vec *bvec, -unsigned long nr_segs,size_t count) -{ -iov_iter_bvec (i, direction, bvec, nr_segs, count); - i->type |=ITER_BVEC_FLAG_NO_REF ; -} -static int lo_write_bvec (struct file *file,struct bio_vec *bvec,loff_t *ppos) {struct iov_iter i;ssize_t bw; -loop_iov_iter_bvec (&i,WRITE , bvec,1 , bvec->bv_len); +iov_iter_bvec (&i,WRITE , bvec,1 , bvec->bv_len);file_start_write (file); bw =vfs_iter_write (file, &i, ppos,0 );
@@ -355,7 +347,7 @@ static int lo_read_simple(struct loop_device *lo, struct request *rq,ssize_t len;rq_for_each_segment (bvec, rq, iter) { -loop_iov_iter_bvec (&i,READ , &bvec,1 , bvec.bv_len); +iov_iter_bvec (&i,READ , &bvec,1 , bvec.bv_len); len =vfs_iter_read (lo->lo_backing_file, &i, &pos,0 );if (len <0 )return len;
@@ -396,7 +388,7 @@ static int lo_read_transfer(struct loop_device *lo, struct request *rq, b.bv_offset =0 ; b.bv_len = bvec.bv_len; -loop_iov_iter_bvec (&i,READ , &b,1 , b.bv_len); +iov_iter_bvec (&i,READ , &b,1 , b.bv_len); len =vfs_iter_read (lo->lo_backing_file, &i, &pos,0 );if (len <0 ) { ret = len;
@@ -563,7 +555,7 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, }atomic_set (&cmd->ref,2 ); -loop_iov_iter_bvec (&iter, rw, bvec, nr_bvec,blk_rq_bytes (rq)); +iov_iter_bvec (&iter, rw, bvec, nr_bvec,blk_rq_bytes (rq)); iter.iov_offset = offset; cmd->iocb.ki_pos = pos;
fs/io_uring.c +0 -3
@@ -997,9 +997,6 @@ static int io_import_fixed(struct io_ring_ctx *ctx, int rw,iov_iter_bvec (iter, rw, imu->bvec, imu->nr_bvecs, offset + len);if (offset)iov_iter_advance (iter, offset); - -/* don't drop a reference to these pages */ - iter->type |=ITER_BVEC_FLAG_NO_REF ;return 0 ; }
include/linux/uio.h +1 -9
@@ -19,9 +19,6 @@ struct kvec { };enum iter_type { -/* set if ITER_BVEC doesn't hold a bv_page ref */ -ITER_BVEC_FLAG_NO_REF =2 , -/* iter types */ ITER_IOVEC =4 ,ITER_KVEC =8 ,
@@ -56,7 +53,7 @@ struct iov_iter {static inline enum iter_type iov_iter_type (const struct iov_iter *i) { -return i->type & ~(READ |WRITE |ITER_BVEC_FLAG_NO_REF ); +return i->type & ~(READ |WRITE ); }static inline bool iter_is_iovec (const struct iov_iter *i)
@@ -89,11 +86,6 @@ static inline unsigned char iov_iter_rw(const struct iov_iter *i)return i->type & (READ |WRITE ); } -static inline bool iov_iter_bvec_no_ref (const struct iov_iter *i) -{ -return (i->type &ITER_BVEC_FLAG_NO_REF ) !=0 ; -} -/* * Total number of bytes covered by an iovec. *
Signature · 1 line
2.20.1
Re: [PATCH 9/9] block: never take page references for ITER_BVEC
Quoted 6 lines · Christoph Hellwig
If we pass pages through an
iov_iterwe always already have a reference in the caller. Thus remove theITER_BVEC_FLAG_NO_REFand don't take reference to pages by default for bvec backediov_iters.Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Johannes Thumshirn <[email protected]>
This looks good to me.
Jens Axboe
maintainerQuoted 9 lines · Christoph Hellwig
Hi Jens,
this series cleans up the various direct I/O and pass through routines by switching them over to common bio helpers.
The last patch just unconditionally applies the no page ref behavior for bvec iters. I looked at all the callers, and there is none that drops the pre-required references before completing the request.
Nice cleanup, applied.
Signature · 1 line
Jens Axboe