* [PATCH v2 0/9] Convert several functions in page_io.c to use a folio
@ 2023-07-19 9:58 Peng Zhang
2023-07-19 9:58 ` [PATCH v2 1/9] mm/page_io: remove unneeded ClearPageUptodate() Peng Zhang
` (8 more replies)
0 siblings, 9 replies; 15+ messages in thread
From: Peng Zhang @ 2023-07-19 9:58 UTC (permalink / raw)
To: linux-mm, linux-kernel, willy
Cc: sidhartha.kumar, akpm, wangkefeng.wang, sunnanyong, ZhangPeng
From: ZhangPeng <zhangpeng362@huawei.com>
This patch series converts several functions in page_io.c to use a
folio, which can remove several implicit calls to compound_head().
Changelog:
v2:
- remove unneeded ClearPageUptodate() and SetPageError(), suggested by
Matthew Wilcox
- convert bio_first_page_all() to bio_first_folio_all(), suggested by
Matthew Wilcox
- convert PageTransHuge to folio_test_pmd_mappable per Matthew Wilcox
ZhangPeng (9):
mm/page_io: remove unneeded ClearPageUptodate()
mm/page_io: remove unneeded SetPageError()
mm/page_io: convert bio_first_page_all() to bio_first_folio_all()
mm/page_io: use a folio in __end_swap_bio_read()
mm/page_io: use a folio in sio_read_complete()
mm/page_io: use a folio in swap_writepage_bdev_sync()
mm/page_io: use a folio in swap_writepage_bdev_async()
mm/page_io: convert count_swpout_vm_event() to take in a folio
mm/page_io: convert bio_associate_blkg_from_page() to take in a folio
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 | 55 +++++++++++++++-----------------
6 files changed, 32 insertions(+), 35 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 1/9] mm/page_io: remove unneeded ClearPageUptodate()
2023-07-19 9:58 [PATCH v2 0/9] Convert several functions in page_io.c to use a folio Peng Zhang
@ 2023-07-19 9:58 ` Peng Zhang
2023-07-19 9:58 ` [PATCH v2 2/9] mm/page_io: remove unneeded SetPageError() Peng Zhang
` (7 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Peng Zhang @ 2023-07-19 9:58 UTC (permalink / raw)
To: linux-mm, linux-kernel, willy
Cc: sidhartha.kumar, akpm, wangkefeng.wang, sunnanyong, ZhangPeng
From: ZhangPeng <zhangpeng362@huawei.com>
The VM_BUG_ON_FOLIO in swap_readpage() ensures that the page is already
!uptodate in __end_swap_bio_read() and sio_read_complete().
Just remove unneeded ClearPageUptodate().
Suggested-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
---
mm/page_io.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/mm/page_io.c b/mm/page_io.c
index 8741d3a0d48a..3087a69a014b 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -62,7 +62,6 @@ static void __end_swap_bio_read(struct bio *bio)
if (bio->bi_status) {
SetPageError(page);
- ClearPageUptodate(page);
pr_alert_ratelimited("Read-error on swap-device (%u:%u:%llu)\n",
MAJOR(bio_dev(bio)), MINOR(bio_dev(bio)),
(unsigned long long)bio->bi_iter.bi_sector);
@@ -417,7 +416,6 @@ static void sio_read_complete(struct kiocb *iocb, long ret)
struct page *page = sio->bvec[p].bv_page;
SetPageError(page);
- ClearPageUptodate(page);
unlock_page(page);
}
pr_alert_ratelimited("Read-error on swap-device\n");
--
2.25.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 2/9] mm/page_io: remove unneeded SetPageError()
2023-07-19 9:58 [PATCH v2 0/9] Convert several functions in page_io.c to use a folio Peng Zhang
2023-07-19 9:58 ` [PATCH v2 1/9] mm/page_io: remove unneeded ClearPageUptodate() Peng Zhang
@ 2023-07-19 9:58 ` Peng Zhang
2023-07-19 9:58 ` [PATCH v2 3/9] mm/page_io: convert bio_first_page_all() to bio_first_folio_all() Peng Zhang
` (6 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Peng Zhang @ 2023-07-19 9:58 UTC (permalink / raw)
To: linux-mm, linux-kernel, willy
Cc: sidhartha.kumar, akpm, wangkefeng.wang, sunnanyong, ZhangPeng
From: ZhangPeng <zhangpeng362@huawei.com>
Nobody checks the PageError()/folio_test_error() for the page/folio in
__end_swap_bio_read/write() and sio_write_complete(). Therefore, we
don't need to set the error flag. Just drop it.
Suggested-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
---
mm/page_io.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/mm/page_io.c b/mm/page_io.c
index 3087a69a014b..5ddb5d9c5013 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -32,7 +32,6 @@ static void __end_swap_bio_write(struct bio *bio)
struct page *page = bio_first_page_all(bio);
if (bio->bi_status) {
- SetPageError(page);
/*
* We failed to write the page out to swap-space.
* Re-dirty the page in order to avoid it being reclaimed.
@@ -61,7 +60,6 @@ static void __end_swap_bio_read(struct bio *bio)
struct page *page = bio_first_page_all(bio);
if (bio->bi_status) {
- SetPageError(page);
pr_alert_ratelimited("Read-error on swap-device (%u:%u:%llu)\n",
MAJOR(bio_dev(bio)), MINOR(bio_dev(bio)),
(unsigned long long)bio->bi_iter.bi_sector);
@@ -415,7 +413,6 @@ static void sio_read_complete(struct kiocb *iocb, long ret)
for (p = 0; p < sio->pages; p++) {
struct page *page = sio->bvec[p].bv_page;
- SetPageError(page);
unlock_page(page);
}
pr_alert_ratelimited("Read-error on swap-device\n");
--
2.25.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 3/9] mm/page_io: convert bio_first_page_all() to bio_first_folio_all()
2023-07-19 9:58 [PATCH v2 0/9] Convert several functions in page_io.c to use a folio Peng Zhang
2023-07-19 9:58 ` [PATCH v2 1/9] mm/page_io: remove unneeded ClearPageUptodate() Peng Zhang
2023-07-19 9:58 ` [PATCH v2 2/9] mm/page_io: remove unneeded SetPageError() Peng Zhang
@ 2023-07-19 9:58 ` Peng Zhang
2023-07-19 14:17 ` Matthew Wilcox
2023-07-19 9:58 ` [PATCH v2 4/9] mm/page_io: use a folio in __end_swap_bio_read() Peng Zhang
` (5 subsequent siblings)
8 siblings, 1 reply; 15+ messages in thread
From: Peng Zhang @ 2023-07-19 9:58 UTC (permalink / raw)
To: linux-mm, linux-kernel, willy
Cc: sidhartha.kumar, akpm, wangkefeng.wang, sunnanyong, ZhangPeng
From: ZhangPeng <zhangpeng362@huawei.com>
Convert bio_first_page_all() to bio_first_folio_all() to return a
folio, which makes it easier to use.
Suggested-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
---
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
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 4/9] mm/page_io: use a folio in __end_swap_bio_read()
2023-07-19 9:58 [PATCH v2 0/9] Convert several functions in page_io.c to use a folio Peng Zhang
` (2 preceding siblings ...)
2023-07-19 9:58 ` [PATCH v2 3/9] mm/page_io: convert bio_first_page_all() to bio_first_folio_all() Peng Zhang
@ 2023-07-19 9:58 ` Peng Zhang
2023-07-19 9:58 ` [PATCH v2 5/9] mm/page_io: use a folio in sio_read_complete() Peng Zhang
` (4 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Peng Zhang @ 2023-07-19 9:58 UTC (permalink / raw)
To: linux-mm, linux-kernel, willy
Cc: sidhartha.kumar, akpm, wangkefeng.wang, sunnanyong, ZhangPeng
From: ZhangPeng <zhangpeng362@huawei.com>
Saves one implicit call to compound_head().
Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
---
mm/page_io.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/mm/page_io.c b/mm/page_io.c
index e21d570c873d..6520687bd282 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -57,16 +57,16 @@ static void end_swap_bio_write(struct bio *bio)
static void __end_swap_bio_read(struct bio *bio)
{
- struct page *page = &bio_first_folio_all(bio)->page;
+ struct folio *folio = bio_first_folio_all(bio);
if (bio->bi_status) {
pr_alert_ratelimited("Read-error on swap-device (%u:%u:%llu)\n",
MAJOR(bio_dev(bio)), MINOR(bio_dev(bio)),
(unsigned long long)bio->bi_iter.bi_sector);
} else {
- SetPageUptodate(page);
+ folio_mark_uptodate(folio);
}
- unlock_page(page);
+ folio_unlock(folio);
}
static void end_swap_bio_read(struct bio *bio)
--
2.25.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 5/9] mm/page_io: use a folio in sio_read_complete()
2023-07-19 9:58 [PATCH v2 0/9] Convert several functions in page_io.c to use a folio Peng Zhang
` (3 preceding siblings ...)
2023-07-19 9:58 ` [PATCH v2 4/9] mm/page_io: use a folio in __end_swap_bio_read() Peng Zhang
@ 2023-07-19 9:58 ` Peng Zhang
2023-07-19 9:58 ` [PATCH v2 6/9] mm/page_io: use a folio in swap_writepage_bdev_sync() Peng Zhang
` (3 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Peng Zhang @ 2023-07-19 9:58 UTC (permalink / raw)
To: linux-mm, linux-kernel, willy
Cc: sidhartha.kumar, akpm, wangkefeng.wang, sunnanyong, ZhangPeng
From: ZhangPeng <zhangpeng362@huawei.com>
Saves one implicit call to compound_head().
Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
---
mm/page_io.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/mm/page_io.c b/mm/page_io.c
index 6520687bd282..92f21f380ee8 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -403,17 +403,17 @@ static void sio_read_complete(struct kiocb *iocb, long ret)
if (ret == sio->len) {
for (p = 0; p < sio->pages; p++) {
- struct page *page = sio->bvec[p].bv_page;
+ struct folio *folio = page_folio(sio->bvec[p].bv_page);
- SetPageUptodate(page);
- unlock_page(page);
+ folio_mark_uptodate(folio);
+ folio_unlock(folio);
}
count_vm_events(PSWPIN, sio->pages);
} else {
for (p = 0; p < sio->pages; p++) {
- struct page *page = sio->bvec[p].bv_page;
+ struct folio *folio = page_folio(sio->bvec[p].bv_page);
- unlock_page(page);
+ folio_unlock(folio);
}
pr_alert_ratelimited("Read-error on swap-device\n");
}
--
2.25.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 6/9] mm/page_io: use a folio in swap_writepage_bdev_sync()
2023-07-19 9:58 [PATCH v2 0/9] Convert several functions in page_io.c to use a folio Peng Zhang
` (4 preceding siblings ...)
2023-07-19 9:58 ` [PATCH v2 5/9] mm/page_io: use a folio in sio_read_complete() Peng Zhang
@ 2023-07-19 9:58 ` Peng Zhang
2023-07-19 9:58 ` [PATCH v2 7/9] mm/page_io: use a folio in swap_writepage_bdev_async() Peng Zhang
` (2 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Peng Zhang @ 2023-07-19 9:58 UTC (permalink / raw)
To: linux-mm, linux-kernel, willy
Cc: sidhartha.kumar, akpm, wangkefeng.wang, sunnanyong, ZhangPeng
From: ZhangPeng <zhangpeng362@huawei.com>
Saves one implicit call to compound_head().
Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
mm/page_io.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/mm/page_io.c b/mm/page_io.c
index 92f21f380ee8..0c96ea9dd258 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -331,6 +331,7 @@ static void swap_writepage_bdev_sync(struct page *page,
{
struct bio_vec bv;
struct bio bio;
+ struct folio *folio = page_folio(page);
bio_init(&bio, sis->bdev, &bv, 1,
REQ_OP_WRITE | REQ_SWAP | wbc_to_write_flags(wbc));
@@ -340,8 +341,8 @@ static void swap_writepage_bdev_sync(struct page *page,
bio_associate_blkg_from_page(&bio, page);
count_swpout_vm_event(page);
- set_page_writeback(page);
- unlock_page(page);
+ folio_start_writeback(folio);
+ folio_unlock(folio);
submit_bio_wait(&bio);
__end_swap_bio_write(&bio);
--
2.25.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 7/9] mm/page_io: use a folio in swap_writepage_bdev_async()
2023-07-19 9:58 [PATCH v2 0/9] Convert several functions in page_io.c to use a folio Peng Zhang
` (5 preceding siblings ...)
2023-07-19 9:58 ` [PATCH v2 6/9] mm/page_io: use a folio in swap_writepage_bdev_sync() Peng Zhang
@ 2023-07-19 9:58 ` Peng Zhang
2023-07-19 9:58 ` [PATCH v2 8/9] mm/page_io: convert count_swpout_vm_event() to take in a folio Peng Zhang
2023-07-19 9:58 ` [PATCH v2 9/9] mm/page_io: convert bio_associate_blkg_from_page() " Peng Zhang
8 siblings, 0 replies; 15+ messages in thread
From: Peng Zhang @ 2023-07-19 9:58 UTC (permalink / raw)
To: linux-mm, linux-kernel, willy
Cc: sidhartha.kumar, akpm, wangkefeng.wang, sunnanyong, ZhangPeng
From: ZhangPeng <zhangpeng362@huawei.com>
Saves one implicit call to compound_head().
Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
mm/page_io.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/mm/page_io.c b/mm/page_io.c
index 0c96ea9dd258..e28395331bb0 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -352,6 +352,7 @@ static void swap_writepage_bdev_async(struct page *page,
struct writeback_control *wbc, struct swap_info_struct *sis)
{
struct bio *bio;
+ struct folio *folio = page_folio(page);
bio = bio_alloc(sis->bdev, 1,
REQ_OP_WRITE | REQ_SWAP | wbc_to_write_flags(wbc),
@@ -362,8 +363,8 @@ static void swap_writepage_bdev_async(struct page *page,
bio_associate_blkg_from_page(bio, page);
count_swpout_vm_event(page);
- set_page_writeback(page);
- unlock_page(page);
+ folio_start_writeback(folio);
+ folio_unlock(folio);
submit_bio(bio);
}
--
2.25.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 8/9] mm/page_io: convert count_swpout_vm_event() to take in a folio
2023-07-19 9:58 [PATCH v2 0/9] Convert several functions in page_io.c to use a folio Peng Zhang
` (6 preceding siblings ...)
2023-07-19 9:58 ` [PATCH v2 7/9] mm/page_io: use a folio in swap_writepage_bdev_async() Peng Zhang
@ 2023-07-19 9:58 ` Peng Zhang
2023-07-19 14:24 ` Matthew Wilcox
2023-07-19 9:58 ` [PATCH v2 9/9] mm/page_io: convert bio_associate_blkg_from_page() " Peng Zhang
8 siblings, 1 reply; 15+ messages in thread
From: Peng Zhang @ 2023-07-19 9:58 UTC (permalink / raw)
To: linux-mm, linux-kernel, willy
Cc: sidhartha.kumar, akpm, wangkefeng.wang, sunnanyong, ZhangPeng
From: ZhangPeng <zhangpeng362@huawei.com>
Convert count_swpout_vm_event() to take in a folio. We can remove five
implicit calls to compound_head() by taking in a folio.
Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
---
mm/page_io.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/mm/page_io.c b/mm/page_io.c
index e28395331bb0..fa8caf1c05d8 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -205,13 +205,13 @@ int swap_writepage(struct page *page, struct writeback_control *wbc)
return 0;
}
-static inline void count_swpout_vm_event(struct page *page)
+static inline void count_swpout_vm_event(struct folio *folio)
{
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
- if (unlikely(PageTransHuge(page)))
+ if (unlikely(folio_test_pmd_mappable(folio)))
count_vm_event(THP_SWPOUT);
#endif
- count_vm_events(PSWPOUT, thp_nr_pages(page));
+ count_vm_events(PSWPOUT, folio_nr_pages(folio));
}
#if defined(CONFIG_MEMCG) && defined(CONFIG_BLK_CGROUP)
@@ -280,7 +280,7 @@ static void sio_write_complete(struct kiocb *iocb, long ret)
}
} else {
for (p = 0; p < sio->pages; p++)
- count_swpout_vm_event(sio->bvec[p].bv_page);
+ count_swpout_vm_event(page_folio(sio->bvec[p].bv_page));
}
for (p = 0; p < sio->pages; p++)
@@ -339,7 +339,7 @@ static void swap_writepage_bdev_sync(struct page *page,
__bio_add_page(&bio, page, thp_size(page), 0);
bio_associate_blkg_from_page(&bio, page);
- count_swpout_vm_event(page);
+ count_swpout_vm_event(folio);
folio_start_writeback(folio);
folio_unlock(folio);
@@ -362,7 +362,7 @@ static void swap_writepage_bdev_async(struct page *page,
__bio_add_page(bio, page, thp_size(page), 0);
bio_associate_blkg_from_page(bio, page);
- count_swpout_vm_event(page);
+ count_swpout_vm_event(folio);
folio_start_writeback(folio);
folio_unlock(folio);
submit_bio(bio);
--
2.25.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 9/9] mm/page_io: convert bio_associate_blkg_from_page() to take in a folio
2023-07-19 9:58 [PATCH v2 0/9] Convert several functions in page_io.c to use a folio Peng Zhang
` (7 preceding siblings ...)
2023-07-19 9:58 ` [PATCH v2 8/9] mm/page_io: convert count_swpout_vm_event() to take in a folio Peng Zhang
@ 2023-07-19 9:58 ` Peng Zhang
8 siblings, 0 replies; 15+ messages in thread
From: Peng Zhang @ 2023-07-19 9:58 UTC (permalink / raw)
To: linux-mm, linux-kernel, willy
Cc: sidhartha.kumar, akpm, wangkefeng.wang, sunnanyong, ZhangPeng
From: ZhangPeng <zhangpeng362@huawei.com>
Convert bio_associate_blkg_from_page() to take in a folio. We can remove
two implicit calls to compound_head() by taking in a folio.
Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
mm/page_io.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/mm/page_io.c b/mm/page_io.c
index fa8caf1c05d8..dcb58888dd36 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -215,12 +215,12 @@ static inline void count_swpout_vm_event(struct folio *folio)
}
#if defined(CONFIG_MEMCG) && defined(CONFIG_BLK_CGROUP)
-static void bio_associate_blkg_from_page(struct bio *bio, struct page *page)
+static void bio_associate_blkg_from_page(struct bio *bio, struct folio *folio)
{
struct cgroup_subsys_state *css;
struct mem_cgroup *memcg;
- memcg = page_memcg(page);
+ memcg = folio_memcg(folio);
if (!memcg)
return;
@@ -230,7 +230,7 @@ static void bio_associate_blkg_from_page(struct bio *bio, struct page *page)
rcu_read_unlock();
}
#else
-#define bio_associate_blkg_from_page(bio, page) do { } while (0)
+#define bio_associate_blkg_from_page(bio, folio) do { } while (0)
#endif /* CONFIG_MEMCG && CONFIG_BLK_CGROUP */
struct swap_iocb {
@@ -338,7 +338,7 @@ static void swap_writepage_bdev_sync(struct page *page,
bio.bi_iter.bi_sector = swap_page_sector(page);
__bio_add_page(&bio, page, thp_size(page), 0);
- bio_associate_blkg_from_page(&bio, page);
+ bio_associate_blkg_from_page(&bio, folio);
count_swpout_vm_event(folio);
folio_start_writeback(folio);
@@ -361,7 +361,7 @@ static void swap_writepage_bdev_async(struct page *page,
bio->bi_end_io = end_swap_bio_write;
__bio_add_page(bio, page, thp_size(page), 0);
- bio_associate_blkg_from_page(bio, page);
+ bio_associate_blkg_from_page(bio, folio);
count_swpout_vm_event(folio);
folio_start_writeback(folio);
folio_unlock(folio);
--
2.25.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 3/9] mm/page_io: convert bio_first_page_all() to bio_first_folio_all()
2023-07-19 9:58 ` [PATCH v2 3/9] mm/page_io: convert bio_first_page_all() to bio_first_folio_all() Peng Zhang
@ 2023-07-19 14:17 ` Matthew Wilcox
2023-07-20 5:34 ` Christoph Hellwig
2023-07-20 9:31 ` zhangpeng (AS)
0 siblings, 2 replies; 15+ messages in thread
From: Matthew Wilcox @ 2023-07-19 14:17 UTC (permalink / raw)
To: Peng Zhang
Cc: linux-mm, linux-kernel, sidhartha.kumar, akpm, wangkefeng.wang,
sunnanyong
On Wed, Jul 19, 2023 at 05:58:42PM +0800, Peng Zhang wrote:
> From: ZhangPeng <zhangpeng362@huawei.com>
>
> 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@infradead.org>
> Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
> ---
> 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
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 8/9] mm/page_io: convert count_swpout_vm_event() to take in a folio
2023-07-19 9:58 ` [PATCH v2 8/9] mm/page_io: convert count_swpout_vm_event() to take in a folio Peng Zhang
@ 2023-07-19 14:24 ` Matthew Wilcox
2023-07-20 9:31 ` zhangpeng (AS)
0 siblings, 1 reply; 15+ messages in thread
From: Matthew Wilcox @ 2023-07-19 14:24 UTC (permalink / raw)
To: Peng Zhang
Cc: linux-mm, linux-kernel, sidhartha.kumar, akpm, wangkefeng.wang,
sunnanyong
On Wed, Jul 19, 2023 at 05:58:47PM +0800, Peng Zhang wrote:
> -static inline void count_swpout_vm_event(struct page *page)
> +static inline void count_swpout_vm_event(struct folio *folio)
> {
> #ifdef CONFIG_TRANSPARENT_HUGEPAGE
> - if (unlikely(PageTransHuge(page)))
> + if (unlikely(folio_test_pmd_mappable(folio)))
> count_vm_event(THP_SWPOUT);
> #endif
As I said in my earlier response, you don't need the ifdefs. Check
the definition of folio_test_pmd_mappable.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 3/9] mm/page_io: convert bio_first_page_all() to bio_first_folio_all()
2023-07-19 14:17 ` Matthew Wilcox
@ 2023-07-20 5:34 ` Christoph Hellwig
2023-07-20 9:31 ` zhangpeng (AS)
1 sibling, 0 replies; 15+ messages in thread
From: Christoph Hellwig @ 2023-07-20 5:34 UTC (permalink / raw)
To: Matthew Wilcox
Cc: Peng Zhang, linux-mm, linux-kernel, sidhartha.kumar, akpm,
wangkefeng.wang, sunnanyong
On Wed, Jul 19, 2023 at 03:17:34PM +0100, Matthew Wilcox wrote:
> On Wed, Jul 19, 2023 at 05:58:42PM +0800, Peng Zhang wrote:
> > From: ZhangPeng <zhangpeng362@huawei.com>
> >
> > 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.
To add another opinion: I'd really like to see bio_first_page_all
go away. The right way to iterate over the pages is an iterator.
If we really want to micro-opimize not setting up an iteator because
we know we have exactly one page/folio just stash it into bi_private.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 3/9] mm/page_io: convert bio_first_page_all() to bio_first_folio_all()
2023-07-19 14:17 ` Matthew Wilcox
2023-07-20 5:34 ` Christoph Hellwig
@ 2023-07-20 9:31 ` zhangpeng (AS)
1 sibling, 0 replies; 15+ messages in thread
From: zhangpeng (AS) @ 2023-07-20 9:31 UTC (permalink / raw)
To: Matthew Wilcox
Cc: linux-mm, linux-kernel, sidhartha.kumar, akpm, wangkefeng.wang,
sunnanyong
On 2023/7/19 22:17, Matthew Wilcox wrote:
> On Wed, Jul 19, 2023 at 05:58:42PM +0800, Peng Zhang wrote:
>> From: ZhangPeng<zhangpeng362@huawei.com>
>>
>> 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.
Sorry for my misunderstanding, I will fix it in the next version.
>> Suggested-by: Matthew Wilcox (Oracle)<willy@infradead.org>
>> Signed-off-by: ZhangPeng<zhangpeng362@huawei.com>
>> ---
>> 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
>>
--
Best Regards,
Peng
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 8/9] mm/page_io: convert count_swpout_vm_event() to take in a folio
2023-07-19 14:24 ` Matthew Wilcox
@ 2023-07-20 9:31 ` zhangpeng (AS)
0 siblings, 0 replies; 15+ messages in thread
From: zhangpeng (AS) @ 2023-07-20 9:31 UTC (permalink / raw)
To: Matthew Wilcox
Cc: linux-mm, linux-kernel, sidhartha.kumar, akpm, wangkefeng.wang,
sunnanyong
On 2023/7/19 22:24, Matthew Wilcox wrote:
> On Wed, Jul 19, 2023 at 05:58:47PM +0800, Peng Zhang wrote:
>> -static inline void count_swpout_vm_event(struct page *page)
>> +static inline void count_swpout_vm_event(struct folio *folio)
>> {
>> #ifdef CONFIG_TRANSPARENT_HUGEPAGE
>> - if (unlikely(PageTransHuge(page)))
>> + if (unlikely(folio_test_pmd_mappable(folio)))
>> count_vm_event(THP_SWPOUT);
>> #endif
> As I said in my earlier response, you don't need the ifdefs. Check
> the definition of folio_test_pmd_mappable.
Sorry I forgot to delete the ifdefs. I'll fix it in a v3.
Thanks.
--
Best Regards,
Peng
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2023-07-20 9:31 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-19 9:58 [PATCH v2 0/9] Convert several functions in page_io.c to use a folio Peng Zhang
2023-07-19 9:58 ` [PATCH v2 1/9] mm/page_io: remove unneeded ClearPageUptodate() Peng Zhang
2023-07-19 9:58 ` [PATCH v2 2/9] mm/page_io: remove unneeded SetPageError() Peng Zhang
2023-07-19 9:58 ` [PATCH v2 3/9] mm/page_io: convert bio_first_page_all() to bio_first_folio_all() Peng Zhang
2023-07-19 14:17 ` Matthew Wilcox
2023-07-20 5:34 ` Christoph Hellwig
2023-07-20 9:31 ` zhangpeng (AS)
2023-07-19 9:58 ` [PATCH v2 4/9] mm/page_io: use a folio in __end_swap_bio_read() Peng Zhang
2023-07-19 9:58 ` [PATCH v2 5/9] mm/page_io: use a folio in sio_read_complete() Peng Zhang
2023-07-19 9:58 ` [PATCH v2 6/9] mm/page_io: use a folio in swap_writepage_bdev_sync() Peng Zhang
2023-07-19 9:58 ` [PATCH v2 7/9] mm/page_io: use a folio in swap_writepage_bdev_async() Peng Zhang
2023-07-19 9:58 ` [PATCH v2 8/9] mm/page_io: convert count_swpout_vm_event() to take in a folio Peng Zhang
2023-07-19 14:24 ` Matthew Wilcox
2023-07-20 9:31 ` zhangpeng (AS)
2023-07-19 9:58 ` [PATCH v2 9/9] mm/page_io: convert bio_associate_blkg_from_page() " Peng Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox