Re: [PATCH v2 3/9] mm/page_io: convert bio_first_page_all() to bio_first_folio_all()

From: Matthew Wilcox
Date: Wed Jul 19 2023 - 10:18:27 EST


On Wed, Jul 19, 2023 at 05:58:42PM +0800, Peng Zhang wrote:
> From: ZhangPeng <zhangpeng362@xxxxxxxxxx>
>
> Convert bio_first_page_all() to bio_first_folio_all() to return a
> folio, which makes it easier to use.

This wasn't what I was suggesting. Indeed, this may introduce bugs.
I was suggesting adding bio_first_folio_all() so that it can be used
by code that knows this is what it wants.

> Suggested-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx>
> Signed-off-by: ZhangPeng <zhangpeng362@xxxxxxxxxx>
> ---
> Documentation/block/biovecs.rst | 2 +-
> drivers/block/drbd/drbd_bitmap.c | 2 +-
> fs/f2fs/data.c | 2 +-
> include/linux/bio.h | 4 ++--
> kernel/power/swap.c | 2 +-
> mm/page_io.c | 4 ++--
> 6 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/Documentation/block/biovecs.rst b/Documentation/block/biovecs.rst
> index ddb867e0185b..258f6faed333 100644
> --- a/Documentation/block/biovecs.rst
> +++ b/Documentation/block/biovecs.rst
> @@ -133,7 +133,7 @@ Usage of helpers:
> bio_for_each_segment_all()
> bio_for_each_bvec_all()
> bio_first_bvec_all()
> - bio_first_page_all()
> + bio_first_folio_all()
> bio_last_bvec_all()
>
> * The following helpers iterate over single-page segment. The passed 'struct
> diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
> index 85ca000a0564..ce1a07ba85ff 100644
> --- a/drivers/block/drbd/drbd_bitmap.c
> +++ b/drivers/block/drbd/drbd_bitmap.c
> @@ -939,7 +939,7 @@ static void drbd_bm_endio(struct bio *bio)
> struct drbd_bm_aio_ctx *ctx = bio->bi_private;
> struct drbd_device *device = ctx->device;
> struct drbd_bitmap *b = device->bitmap;
> - unsigned int idx = bm_page_to_idx(bio_first_page_all(bio));
> + unsigned int idx = bm_page_to_idx(&bio_first_folio_all(bio)->page);
>
> if ((ctx->flags & BM_AIO_COPY_PAGES) == 0 &&
> !bm_test_page_unchanged(b->bm_pages[idx]))
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 5882afe71d82..6706858de984 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -288,7 +288,7 @@ static void f2fs_post_read_work(struct work_struct *work)
>
> static void f2fs_read_end_io(struct bio *bio)
> {
> - struct f2fs_sb_info *sbi = F2FS_P_SB(bio_first_page_all(bio));
> + struct f2fs_sb_info *sbi = F2FS_P_SB(&bio_first_folio_all(bio)->page);
> struct bio_post_read_ctx *ctx;
> bool intask = in_task();
>
> diff --git a/include/linux/bio.h b/include/linux/bio.h
> index c4f5b5228105..7d2979d24530 100644
> --- a/include/linux/bio.h
> +++ b/include/linux/bio.h
> @@ -248,9 +248,9 @@ static inline struct bio_vec *bio_first_bvec_all(struct bio *bio)
> return bio->bi_io_vec;
> }
>
> -static inline struct page *bio_first_page_all(struct bio *bio)
> +static inline struct folio *bio_first_folio_all(struct bio *bio)
> {
> - return bio_first_bvec_all(bio)->bv_page;
> + return page_folio(bio_first_bvec_all(bio)->bv_page);
> }
>
> static inline struct bio_vec *bio_last_bvec_all(struct bio *bio)
> diff --git a/kernel/power/swap.c b/kernel/power/swap.c
> index f6ebcd00c410..2796ce48ca4b 100644
> --- a/kernel/power/swap.c
> +++ b/kernel/power/swap.c
> @@ -247,7 +247,7 @@ static void hib_finish_batch(struct hib_bio_batch *hb)
> static void hib_end_io(struct bio *bio)
> {
> struct hib_bio_batch *hb = bio->bi_private;
> - struct page *page = bio_first_page_all(bio);
> + struct page *page = &bio_first_folio_all(bio)->page;
>
> if (bio->bi_status) {
> pr_alert("Read-error on swap-device (%u:%u:%Lu)\n",
> diff --git a/mm/page_io.c b/mm/page_io.c
> index 5ddb5d9c5013..e21d570c873d 100644
> --- a/mm/page_io.c
> +++ b/mm/page_io.c
> @@ -29,7 +29,7 @@
>
> static void __end_swap_bio_write(struct bio *bio)
> {
> - struct page *page = bio_first_page_all(bio);
> + struct page *page = &bio_first_folio_all(bio)->page;
>
> if (bio->bi_status) {
> /*
> @@ -57,7 +57,7 @@ static void end_swap_bio_write(struct bio *bio)
>
> static void __end_swap_bio_read(struct bio *bio)
> {
> - struct page *page = bio_first_page_all(bio);
> + struct page *page = &bio_first_folio_all(bio)->page;
>
> if (bio->bi_status) {
> pr_alert_ratelimited("Read-error on swap-device (%u:%u:%llu)\n",
> --
> 2.25.1
>