* [PATCH v4 13/16] md/md-bitmap: replace PagePrivate() with page_private()
2026-09-14 2:23 [PATCH v4 00/16] Remove PG_private by using page/folio->private checks instead Zi Yan
@ 2026-09-14 2:24 ` Zi Yan
2026-09-14 2:24 ` [PATCH v4 14/16] buffer: replace page_buffer() with page_private() and delete it Zi Yan
` (6 subsequent siblings)
7 siblings, 0 replies; 22+ messages in thread
From: Zi Yan @ 2026-09-14 2:24 UTC (permalink / raw)
To: David Hildenbrand, Matthew Wilcox (Oracle), Andrew Morton,
Muchun Song, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Baolin Wang,
Nico Pache, Ryan Roberts, Dev Jain, Barry Song, Lance Yang,
Usama Arif, Gregory Price, Ying Huang, Alistair Popple,
Johannes Weiner, Qi Zheng, Shakeel Butt, Kairui Song
Cc: linux-mm, linux-kernel, Zi Yan, Song Liu, Yu Kuai, Li Nan,
Xiao Ni, linux-raid
PagePrivate() is going to be removed along with PG_private and its
implementation has been changed to match page_private().
Assisted-by: LLM
Signed-off-by: Zi Yan <ziy@nvidia.com>
To: Song Liu <song@kernel.org>
To: Yu Kuai <yukuai@fygo.io>
Cc: Li Nan <magiclinan@didiglobal.com>
Cc: Xiao Ni <xiao@kernel.org>
Cc: linux-raid@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
drivers/md/md-bitmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index b8325cb09a371..84122834b6108 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -535,7 +535,7 @@ static void free_buffers(struct page *page)
{
struct buffer_head *bh;
- if (!PagePrivate(page))
+ if (!page_private(page))
return;
bh = page_buffers(page);
--
2.53.0
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH v4 14/16] buffer: replace page_buffer() with page_private() and delete it
2026-09-14 2:23 [PATCH v4 00/16] Remove PG_private by using page/folio->private checks instead Zi Yan
2026-09-14 2:24 ` [PATCH v4 13/16] md/md-bitmap: replace PagePrivate() with page_private() Zi Yan
@ 2026-09-14 2:24 ` Zi Yan
2026-09-14 3:39 ` [PATCH v4 00/16] Remove PG_private by using page/folio->private checks instead Andrew Morton
` (5 subsequent siblings)
7 siblings, 0 replies; 22+ messages in thread
From: Zi Yan @ 2026-09-14 2:24 UTC (permalink / raw)
To: David Hildenbrand, Matthew Wilcox (Oracle), Andrew Morton,
Muchun Song, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Baolin Wang,
Nico Pache, Ryan Roberts, Dev Jain, Barry Song, Lance Yang,
Usama Arif, Gregory Price, Ying Huang, Alistair Popple,
Johannes Weiner, Qi Zheng, Shakeel Butt, Kairui Song
Cc: linux-mm, linux-kernel, Zi Yan, Song Liu, Yu Kuai, Jan Kara,
Li Nan, Xiao Ni, linux-raid, linux-fsdevel
Only two users (in md-bitmap) use page_buffer() and both can be converted
to use page_private(). Convert both and remove page_buffer().
Assisted-by: LLM
Signed-off-by: Zi Yan <ziy@nvidia.com>
To: Song Liu <song@kernel.org>
To: Yu Kuai <yukuai@fygo.io>
To: Jan Kara <jack@suse.cz>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Li Nan <magiclinan@didiglobal.com>
Cc: Xiao Ni <xiao@kernel.org>
Cc: linux-raid@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
drivers/md/md-bitmap.c | 7 +++----
include/linux/buffer_head.h | 6 ------
2 files changed, 3 insertions(+), 10 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 84122834b6108..7b706d3e54901 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -516,7 +516,7 @@ static void end_bitmap_write(struct bio *bio)
static void write_file_page(struct bitmap *bitmap, struct page *page, int wait)
{
- struct buffer_head *bh = page_buffers(page);
+ struct buffer_head *bh = (struct buffer_head *)page_private(page);
while (bh && bh->b_blocknr) {
atomic_inc(&bitmap->pending_writes);
@@ -533,12 +533,11 @@ static void write_file_page(struct bitmap *bitmap, struct page *page, int wait)
static void free_buffers(struct page *page)
{
- struct buffer_head *bh;
+ struct buffer_head *bh = (struct buffer_head *)page_private(page);
- if (!page_private(page))
+ if (!bh)
return;
- bh = page_buffers(page);
while (bh) {
struct buffer_head *next = bh->b_this_page;
free_buffer_head(bh);
diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
index fd2c7115c0542..e47fbd0387b69 100644
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -175,12 +175,6 @@ static inline unsigned long bh_offset(const struct buffer_head *bh)
return (unsigned long)(bh)->b_data & (page_size(bh->b_page) - 1);
}
-/* If we *know* page->private refers to buffer_heads */
-#define page_buffers(page) \
- ({ \
- BUG_ON(!PagePrivate(page)); \
- ((struct buffer_head *)page_private(page)); \
- })
#define folio_buffers(folio) folio_get_private(folio)
void buffer_check_dirty_writeback(struct folio *folio,
--
2.53.0
^ permalink raw reply related [flat|nested] 22+ messages in thread* Re: [PATCH v4 00/16] Remove PG_private by using page/folio->private checks instead
2026-09-14 2:23 [PATCH v4 00/16] Remove PG_private by using page/folio->private checks instead Zi Yan
2026-09-14 2:24 ` [PATCH v4 13/16] md/md-bitmap: replace PagePrivate() with page_private() Zi Yan
2026-09-14 2:24 ` [PATCH v4 14/16] buffer: replace page_buffer() with page_private() and delete it Zi Yan
@ 2026-09-14 3:39 ` Andrew Morton
2026-09-15 17:16 ` Zi Yan
2026-09-14 4:18 ` [PATCH 1/3] md: Use folio_alloc_buffers() Matthew Wilcox (Oracle)
` (4 subsequent siblings)
7 siblings, 1 reply; 22+ messages in thread
From: Andrew Morton @ 2026-09-14 3:39 UTC (permalink / raw)
To: Zi Yan
Cc: David Hildenbrand, Matthew Wilcox (Oracle), Muchun Song,
Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Baolin Wang, Nico Pache,
Ryan Roberts, Dev Jain, Barry Song, Lance Yang, Usama Arif,
Gregory Price, Ying Huang, Alistair Popple, Johannes Weiner,
Qi Zheng, Shakeel Butt, Kairui Song, linux-mm, linux-kernel,
Minchan Kim, Sergey Senozhatsky, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Thomas Gleixner,
Borislav Petkov, Dave Hansen, x86, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
James Clark, H. Peter Anvin, linux-perf-users, Juergen Gross,
Stefano Stabellini, Oleksandr Tyshchenko, xen-devel, Eric Biggers,
Theodore Y. Ts'o, Jaegeuk Kim, linux-fscrypt, Oscar Salvador,
Chao Yu, linux-f2fs-devel, Tal Zussman, Gao Xiang, Jan Kara,
Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li, Chunhai Guo,
linux-erofs, linux-fsdevel, Steven Rostedt, Masami Hiramatsu,
Mathieu Desnoyers, Matthew Brost, Joshua Hahn, Rakie Kim,
Byungchul Park, Axel Rasmussen, Yuanchu Xie, Wei Xu,
linux-trace-kernel, Trond Myklebust, Anna Schumaker, linux-nfs,
Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko, ceph-devel,
Song Liu, Yu Kuai, Li Nan, Xiao Ni, linux-raid,
Richard Weinberger, Zhihao Cheng, linux-mtd, Baoquan He,
Pasha Tatashin, Pratyush Yadav, Jonathan Corbet, Dave Young,
Shuah Khan, kexec, linux-doc
On Sun, 13 Sep 2026 22:23:58 -0400 Zi Yan <ziy@nvidia.com> wrote:
> This patchset removes PG_private to make space for upcoming PG_folio for
> identifying pages from a folio (more details in Note below). Instead of
> checking PG_private, all code is changed to check page/folio->private !=
> NULL instead.
>
> MM people are cc'd on all patches and subsystem people are cc'd on the
> cover letter and corresponding patches.
>
> Patch 6 is picked up separately in f2fs tree, but since mm-new does not
> have it yet, it is sent for MM testing.
AI review claims to have found a pre-existing critical level deadlock
in f2fs:
https://sashiko.dev/#/patchset/20260913-remove-pg_private-v4-0-848550f7574e@nvidia.com
it also had a few things to say about this patchset and, as always,
hugetlb.c.
Thanks, The MM bits appear adequately reviewed and review of the non-MM
bits are, as usual:
Great to have but I won't permit lack of other-than-MM review to
block MM improvements.
So I'll queue it all up and shall push it into -next after a few days.
Acks from non-MM maintainers are appreciated.
If a non-MM patch appears in linux-next I'll autodrop the mm.git copy
of that patch.
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [PATCH v4 00/16] Remove PG_private by using page/folio->private checks instead
2026-09-14 3:39 ` [PATCH v4 00/16] Remove PG_private by using page/folio->private checks instead Andrew Morton
@ 2026-09-15 17:16 ` Zi Yan
0 siblings, 0 replies; 22+ messages in thread
From: Zi Yan @ 2026-09-15 17:16 UTC (permalink / raw)
To: Andrew Morton
Cc: David Hildenbrand, Matthew Wilcox (Oracle), Muchun Song,
Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Baolin Wang, Nico Pache,
Ryan Roberts, Dev Jain, Barry Song, Lance Yang, Usama Arif,
Gregory Price, Ying Huang, Alistair Popple, Johannes Weiner,
Qi Zheng, Shakeel Butt, Kairui Song, linux-mm, linux-kernel,
Minchan Kim, Sergey Senozhatsky, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Thomas Gleixner,
Borislav Petkov, Dave Hansen, x86, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
James Clark, H. Peter Anvin, linux-perf-users, Juergen Gross,
Stefano Stabellini, Oleksandr Tyshchenko, xen-devel, Eric Biggers,
Theodore Y. Ts'o, Jaegeuk Kim, linux-fscrypt, Oscar Salvador,
Chao Yu, linux-f2fs-devel, Tal Zussman, Gao Xiang, Jan Kara,
Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li, Chunhai Guo,
linux-erofs, linux-fsdevel, Steven Rostedt, Masami Hiramatsu,
Mathieu Desnoyers, Matthew Brost, Joshua Hahn, Rakie Kim,
Byungchul Park, Axel Rasmussen, Yuanchu Xie, Wei Xu,
linux-trace-kernel, Trond Myklebust, Anna Schumaker, linux-nfs,
Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko, ceph-devel,
Song Liu, Yu Kuai, Li Nan, Xiao Ni, linux-raid,
Richard Weinberger, Zhihao Cheng, linux-mtd, Baoquan He,
Pasha Tatashin, Pratyush Yadav, Jonathan Corbet, Dave Young,
Shuah Khan, kexec, linux-doc
On 13 Sep 2026, at 23:39, Andrew Morton wrote:
> On Sun, 13 Sep 2026 22:23:58 -0400 Zi Yan <ziy@nvidia.com> wrote:
>
>> This patchset removes PG_private to make space for upcoming PG_folio for
>> identifying pages from a folio (more details in Note below). Instead of
>> checking PG_private, all code is changed to check page/folio->private !=
>> NULL instead.
>>
>> MM people are cc'd on all patches and subsystem people are cc'd on the
>> cover letter and corresponding patches.
>>
>> Patch 6 is picked up separately in f2fs tree, but since mm-new does not
>> have it yet, it is sent for MM testing.
>
> AI review claims to have found a pre-existing critical level deadlock
> in f2fs:
>
> https://sashiko.dev/#/patchset/20260913-remove-pg_private-v4-0-848550f7574e@nvidia.com
>
> it also had a few things to say about this patchset and, as always,
> hugetlb.c.
It seems that Sashiko overwrote my patch reviews with the reviews to
Matthew’s md patches. :/ I wonder if there is a way of recovering them.
>
>
> Thanks, The MM bits appear adequately reviewed and review of the non-MM
> bits are, as usual:
>
> Great to have but I won't permit lack of other-than-MM review to
> block MM improvements.
>
> So I'll queue it all up and shall push it into -next after a few days.
>
> Acks from non-MM maintainers are appreciated.
>
> If a non-MM patch appears in linux-next I'll autodrop the mm.git copy
> of that patch.
Thanks.
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 1/3] md: Use folio_alloc_buffers()
2026-09-14 2:23 [PATCH v4 00/16] Remove PG_private by using page/folio->private checks instead Zi Yan
` (2 preceding siblings ...)
2026-09-14 3:39 ` [PATCH v4 00/16] Remove PG_private by using page/folio->private checks instead Andrew Morton
@ 2026-09-14 4:18 ` Matthew Wilcox (Oracle)
2026-09-14 4:27 ` sashiko-bot
2026-09-14 13:12 ` David Hildenbrand (Arm)
2026-09-14 4:18 ` [PATCH 2/3] md: Use folio APIs in free_page() Matthew Wilcox (Oracle)
` (3 subsequent siblings)
7 siblings, 2 replies; 22+ messages in thread
From: Matthew Wilcox (Oracle) @ 2026-09-14 4:18 UTC (permalink / raw)
To: Zi Yan; +Cc: Matthew Wilcox (Oracle), linux-raid, linux-mm
Remove the last user of alloc_page_buffers(). This isn't _great_,
but prevents new callers of alloc_page_buffers() existing.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
drivers/md/md-bitmap.c | 5 +++--
fs/buffer.c | 8 --------
include/linux/buffer_head.h | 1 -
3 files changed, 3 insertions(+), 11 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index b8325cb09a37..5f1637f974c1 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -560,6 +560,7 @@ static int read_file_page(struct file *file, unsigned long index,
{
int ret = 0;
struct inode *inode = file_inode(file);
+ struct folio *folio = page_folio(page);
struct buffer_head *bh;
sector_t block, blk_cur;
unsigned long blocksize = i_blocksize(inode);
@@ -567,12 +568,12 @@ static int read_file_page(struct file *file, unsigned long index,
pr_debug("read bitmap file (%dB @ %llu)\n", (int)PAGE_SIZE,
(unsigned long long)index << PAGE_SHIFT);
- bh = alloc_page_buffers(page, blocksize);
+ bh = folio_alloc_buffers(folio, blocksize, GFP_NOFS | __GFP_ACCOUNT);
if (!bh) {
ret = -ENOMEM;
goto out;
}
- attach_page_private(page, bh);
+ folio_attach_private(folio, bh);
blk_cur = index << (PAGE_SHIFT - inode->i_blkbits);
while (bh) {
block = blk_cur;
diff --git a/fs/buffer.c b/fs/buffer.c
index c9342aeb8cdf..367be053d07b 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -781,14 +781,6 @@ struct buffer_head *folio_alloc_buffers(struct folio *folio, unsigned long size,
}
EXPORT_SYMBOL_GPL(folio_alloc_buffers);
-struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size)
-{
- gfp_t gfp = GFP_NOFS | __GFP_ACCOUNT;
-
- return folio_alloc_buffers(page_folio(page), size, gfp);
-}
-EXPORT_SYMBOL_GPL(alloc_page_buffers);
-
static inline void link_dev_buffers(struct folio *folio,
struct buffer_head *head)
{
diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
index 1d55f7770cad..c9918176adaa 100644
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -197,7 +197,6 @@ void folio_set_bh(struct buffer_head *bh, struct folio *folio,
unsigned long offset);
struct buffer_head *folio_alloc_buffers(struct folio *folio, unsigned long size,
gfp_t gfp);
-struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size);
struct buffer_head *create_empty_buffers(struct folio *folio,
unsigned long blocksize, unsigned long b_state);
void end_buffer_read_sync(struct buffer_head *bh, int uptodate);
--
2.47.3
^ permalink raw reply related [flat|nested] 22+ messages in thread* Re: [PATCH 1/3] md: Use folio_alloc_buffers()
2026-09-14 4:18 ` [PATCH 1/3] md: Use folio_alloc_buffers() Matthew Wilcox (Oracle)
@ 2026-09-14 4:27 ` sashiko-bot
2026-09-14 13:12 ` David Hildenbrand (Arm)
1 sibling, 0 replies; 22+ messages in thread
From: sashiko-bot @ 2026-09-14 4:27 UTC (permalink / raw)
To: Matthew Wilcox (Oracle); +Cc: yukuai, linux-raid
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Severe memory leak of bitmap pages in free_buffers() when PagePrivate is not set.
--
commit 9822ba9b718b51ce47732b5412e326f063b30c60
Author: Matthew Wilcox (Oracle) <willy@infradead.org>
md: Use folio_alloc_buffers()
This commit removes the last user of alloc_page_buffers(), replacing it
with folio_alloc_buffers() to prevent new callers from existing.
> diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
> index b8325cb09a371..5f1637f974c15 100644
> --- a/drivers/md/md-bitmap.c
> +++ b/drivers/md/md-bitmap.c
> @@ -560,6 +560,7 @@ static int read_file_page(struct file *file, unsigned long index,
> {
> int ret = 0;
> struct inode *inode = file_inode(file);
> + struct folio *folio = page_folio(page);
> struct buffer_head *bh;
> sector_t block, blk_cur;
> unsigned long blocksize = i_blocksize(inode);
> @@ -567,12 +568,12 @@ static int read_file_page(struct file *file, unsigned long index,
> pr_debug("read bitmap file (%dB @ %llu)\n", (int)PAGE_SIZE,
> (unsigned long long)index << PAGE_SHIFT);
>
> - bh = alloc_page_buffers(page, blocksize);
> + bh = folio_alloc_buffers(folio, blocksize, GFP_NOFS | __GFP_ACCOUNT);
> if (!bh) {
> ret = -ENOMEM;
> goto out;
> }
> - attach_page_private(page, bh);
> + folio_attach_private(folio, bh);
[Severity: High]
This isn't a bug introduced by this patch, but it is a severe pre-existing
resource leak in the cleanup path for these pages.
md_bitmap_storage_alloc() allocates pages via alloc_page() for
store->filemap. On teardown, md_bitmap_file_unmap() iterates over these
pages and calls free_buffers() to clean them up.
For internal bitmaps, read_sb_page() uses raw bios and never attaches
buffer heads, so the pages never have the PagePrivate flag set.
When this happens, free_buffers() returns early:
static void free_buffers(struct page *page)
{
struct buffer_head *bh;
if (!PagePrivate(page))
return;
...
detach_page_private(page);
put_page(page);
}
Does this early return mistakenly skip the final put_page() call,
permanently leaking the page when no buffer heads are attached?
This leaks memory pages allocated for the MD bitmap every time an array
with an internal bitmap is stopped, potentially leading to memory
exhaustion.
I verified that the follow-up patches in this series (which migrate this
function to the folio API) faithfully reproduce the exact same leak by
returning early when bh is NULL before calling folio_put(folio).
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260913-remove-pg_private-v4-0-848550f7574e@nvidia.com?part=1
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [PATCH 1/3] md: Use folio_alloc_buffers()
2026-09-14 4:18 ` [PATCH 1/3] md: Use folio_alloc_buffers() Matthew Wilcox (Oracle)
2026-09-14 4:27 ` sashiko-bot
@ 2026-09-14 13:12 ` David Hildenbrand (Arm)
2026-09-14 13:17 ` Matthew Wilcox
1 sibling, 1 reply; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-09-14 13:12 UTC (permalink / raw)
To: Matthew Wilcox (Oracle), Zi Yan; +Cc: linux-raid, linux-mm
On 9/14/26 06:18, Matthew Wilcox (Oracle) wrote:
> Remove the last user of alloc_page_buffers(). This isn't _great_,
You should tell us "why" this isn't great.
Because we're allocating folios although these things are not actually folios? I
can only speculate :)
Code itself looks good.
--
Cheers,
David
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 1/3] md: Use folio_alloc_buffers()
2026-09-14 13:12 ` David Hildenbrand (Arm)
@ 2026-09-14 13:17 ` Matthew Wilcox
2026-09-14 13:20 ` David Hildenbrand (Arm)
0 siblings, 1 reply; 22+ messages in thread
From: Matthew Wilcox @ 2026-09-14 13:17 UTC (permalink / raw)
To: David Hildenbrand (Arm); +Cc: Zi Yan, linux-raid, linux-mm
On Mon, Sep 14, 2026 at 03:12:31PM +0200, David Hildenbrand (Arm) wrote:
> On 9/14/26 06:18, Matthew Wilcox (Oracle) wrote:
> > Remove the last user of alloc_page_buffers(). This isn't _great_,
>
> You should tell us "why" this isn't great.
>
> Because we're allocating folios although these things are not actually folios? I
> can only speculate :)
Well, we actually aren't allocating folios in md-bitmap:
for ( ; pnum < num_pages; pnum++) {
store->filemap[pnum] = alloc_page(GFP_KERNEL|__GFP_ZERO);
and it's not clear to me that we should be allocating folios; they're
internal memory to the md-bitmap code that are never mapped to userspace,
nor enter the page cache. But they do have buffer heads attached to them.
The md-bitmap code probably needs to be rewritten to not use buffer heads
at all, but then I hear from some people that it's scheduled for deletion,
so don't spend any time on it. But I can't find anything official about
that anywhere.
> Code itself looks good.
Thanks!
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [PATCH 1/3] md: Use folio_alloc_buffers()
2026-09-14 13:17 ` Matthew Wilcox
@ 2026-09-14 13:20 ` David Hildenbrand (Arm)
2026-09-14 14:36 ` Zi Yan
0 siblings, 1 reply; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-09-14 13:20 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: Zi Yan, linux-raid, linux-mm
On 9/14/26 15:17, Matthew Wilcox wrote:
> On Mon, Sep 14, 2026 at 03:12:31PM +0200, David Hildenbrand (Arm) wrote:
>> On 9/14/26 06:18, Matthew Wilcox (Oracle) wrote:
>>> Remove the last user of alloc_page_buffers(). This isn't _great_,
>>
>> You should tell us "why" this isn't great.
>>
>> Because we're allocating folios although these things are not actually folios? I
>> can only speculate :)
>
> Well, we actually aren't allocating folios in md-bitmap:
>
> for ( ; pnum < num_pages; pnum++) {
> store->filemap[pnum] = alloc_page(GFP_KERNEL|__GFP_ZERO);
>
> and it's not clear to me that we should be allocating folios; they're
> internal memory to the md-bitmap code that are never mapped to userspace,
> nor enter the page cache. But they do have buffer heads attached to them.
Confusing indeed.
>
> The md-bitmap code probably needs to be rewritten to not use buffer heads
> at all, but then I hear from some people that it's scheduled for deletion,
> so don't spend any time on it. But I can't find anything official about
> that anywhere.
>
>> Code itself looks good.
>
> Thanks!
I'd assume Zi will pick up your patches and can massage the patch description to
summarize why folios are awkward here, but that cleaning this up is future work.
--
Cheers,
David
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [PATCH 1/3] md: Use folio_alloc_buffers()
2026-09-14 13:20 ` David Hildenbrand (Arm)
@ 2026-09-14 14:36 ` Zi Yan
0 siblings, 0 replies; 22+ messages in thread
From: Zi Yan @ 2026-09-14 14:36 UTC (permalink / raw)
To: David Hildenbrand (Arm); +Cc: Matthew Wilcox, linux-raid, linux-mm
On 14 Sep 2026, at 9:20, David Hildenbrand (Arm) wrote:
> On 9/14/26 15:17, Matthew Wilcox wrote:
>> On Mon, Sep 14, 2026 at 03:12:31PM +0200, David Hildenbrand (Arm) wrote:
>>> On 9/14/26 06:18, Matthew Wilcox (Oracle) wrote:
>>>> Remove the last user of alloc_page_buffers(). This isn't _great_,
>>>
>>> You should tell us "why" this isn't great.
>>>
>>> Because we're allocating folios although these things are not actually folios? I
>>> can only speculate :)
>>
>> Well, we actually aren't allocating folios in md-bitmap:
>>
>> for ( ; pnum < num_pages; pnum++) {
>> store->filemap[pnum] = alloc_page(GFP_KERNEL|__GFP_ZERO);
>>
>> and it's not clear to me that we should be allocating folios; they're
>> internal memory to the md-bitmap code that are never mapped to userspace,
>> nor enter the page cache. But they do have buffer heads attached to them.
>
> Confusing indeed.
>
>>
>> The md-bitmap code probably needs to be rewritten to not use buffer heads
>> at all, but then I hear from some people that it's scheduled for deletion,
>> so don't spend any time on it. But I can't find anything official about
>> that anywhere.
>>
>>> Code itself looks good.
>>
>> Thanks!
>
> I'd assume Zi will pick up your patches and can massage the patch description to
> summarize why folios are awkward here, but that cleaning this up is future work.
Will do the replacement.
The new description:
Remove the last user of alloc_page_buffers(). Use folio_alloc_buffers()
instead, since alloc_page_buffers() is a wrap over it. Although
the pages used in md-bitmap are not folios, as they are not mapped
into userspace nor enter the page cache, but they still have buffer heads
attached. Cleaning up the code to not use buffer heads is future work.
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 2/3] md: Use folio APIs in free_page()
2026-09-14 2:23 [PATCH v4 00/16] Remove PG_private by using page/folio->private checks instead Zi Yan
` (3 preceding siblings ...)
2026-09-14 4:18 ` [PATCH 1/3] md: Use folio_alloc_buffers() Matthew Wilcox (Oracle)
@ 2026-09-14 4:18 ` Matthew Wilcox (Oracle)
2026-09-14 4:31 ` sashiko-bot
2026-09-14 13:13 ` David Hildenbrand (Arm)
2026-09-14 4:18 ` [PATCH 3/3] md: Remove the last use of page_buffers() Matthew Wilcox (Oracle)
` (2 subsequent siblings)
7 siblings, 2 replies; 22+ messages in thread
From: Matthew Wilcox (Oracle) @ 2026-09-14 4:18 UTC (permalink / raw)
To: Zi Yan; +Cc: Matthew Wilcox (Oracle), linux-raid, linux-mm
Convert the page to a folio. This removes some of the last uses of a
few page APIs (detach_page_private(), page_buffers()). Replaces two
calls to compound_head() with one.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
drivers/md/md-bitmap.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 5f1637f974c1..7b42db87d536 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -533,19 +533,18 @@ static void write_file_page(struct bitmap *bitmap, struct page *page, int wait)
static void free_buffers(struct page *page)
{
- struct buffer_head *bh;
+ struct folio *folio = page_folio(page);
+ struct buffer_head *bh = folio_detach_private(folio);
- if (!PagePrivate(page))
+ if (!bh)
return;
- bh = page_buffers(page);
while (bh) {
struct buffer_head *next = bh->b_this_page;
free_buffer_head(bh);
bh = next;
}
- detach_page_private(page);
- put_page(page);
+ folio_put(folio);
}
/* read a page from a file.
--
2.47.3
^ permalink raw reply related [flat|nested] 22+ messages in thread* Re: [PATCH 2/3] md: Use folio APIs in free_page()
2026-09-14 4:18 ` [PATCH 2/3] md: Use folio APIs in free_page() Matthew Wilcox (Oracle)
@ 2026-09-14 4:31 ` sashiko-bot
2026-09-14 16:21 ` Matthew Wilcox
2026-09-14 13:13 ` David Hildenbrand (Arm)
1 sibling, 1 reply; 22+ messages in thread
From: sashiko-bot @ 2026-09-14 4:31 UTC (permalink / raw)
To: Matthew Wilcox (Oracle); +Cc: yukuai, linux-raid
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Memory leak of internal bitmap pages and uninitialized file bitmap pages during teardown or error handling due to an early return in free_buffers().
--
commit d68f524234e61e6567e52a27e09b9d2546ab54af
Author: Matthew Wilcox (Oracle) <willy@infradead.org>
md: Use folio APIs in free_page()
This commit converts the page to a folio, removing some of the last uses of
a few page APIs and replacing two calls to compound_head() with one.
> diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
> index 5f1637f974c15..7b42db87d536d 100644
> --- a/drivers/md/md-bitmap.c
> +++ b/drivers/md/md-bitmap.c
> @@ -533,19 +533,18 @@ static void write_file_page(struct bitmap *bitmap, struct page *page, int wait)
>
> static void free_buffers(struct page *page)
> {
> - struct buffer_head *bh;
> + struct folio *folio = page_folio(page);
> + struct buffer_head *bh = folio_detach_private(folio);
>
> - if (!PagePrivate(page))
> + if (!bh)
> return;
[Severity: High]
This is a pre-existing issue, but this early return skips the folio_put()
required to drop the base allocation reference for pages that do not have
buffers attached.
For internal bitmaps, pages are allocated via alloc_page() with a refcount
of 1 in md_bitmap_storage_alloc():
drivers/md/md-bitmap.c:md_bitmap_storage_alloc() {
...
store->filemap[pnum] = alloc_page(GFP_KERNEL|__GFP_ZERO);
...
}
During MD array teardown or failure, md_bitmap_file_unmap() calls
free_buffers() on these pages:
drivers/md/md-bitmap.c:md_bitmap_file_unmap() {
...
free_buffers(map[pages]);
...
}
Because internal bitmap pages don't have buffers attached, (!bh) evaluates
to true, triggering the early return and completely bypassing the folio_put()
at the end of the function.
This permanently leaks the pages allocated for the internal bitmap's filemap
and superblock.
Does this early return need to be updated so that folio_put() is still
called for folios without buffers?
> - bh = page_buffers(page);
> while (bh) {
> struct buffer_head *next = bh->b_this_page;
> free_buffer_head(bh);
> bh = next;
> }
> - detach_page_private(page);
> - put_page(page);
> + folio_put(folio);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260913-remove-pg_private-v4-0-848550f7574e@nvidia.com?part=2
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [PATCH 2/3] md: Use folio APIs in free_page()
2026-09-14 4:31 ` sashiko-bot
@ 2026-09-14 16:21 ` Matthew Wilcox
2026-09-14 16:25 ` Zi Yan
0 siblings, 1 reply; 22+ messages in thread
From: Matthew Wilcox @ 2026-09-14 16:21 UTC (permalink / raw)
To: sashiko-reviews; +Cc: yukuai, linux-raid, Zi Yan, David Hildenbrand, linux-mm
On Mon, Sep 14, 2026 at 04:31:29AM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] Memory leak of internal bitmap pages and uninitialized file bitmap pages during teardown or error handling due to an early return in free_buffers().
> --
Yes, I thought the early return looked weird. I just believed that I
hadn't looked into the code enough to understand why it looked weird but
was right. Since the AI says it's wrong, I'm happy to believe it's wrong.
It's probably not really a high seveirty problem because most RAIDs are
set up once and then never removed, so the leak doesn't matter.
The other thing that looks weird is that this code believes the b_this_page
list is NULL terminated. Most loops over "all BHs attached to a folio"
have a circular list. However, that is established by link_dev_buffers()
which is not called by md-bitmap. So it's correct, even though weird.
The good news is this is an easy fix:
@@ -536,9 +536,6 @@ static void free_buffers(struct page *page)
struct folio *folio = page_folio(page);
struct buffer_head *bh = folio_detach_private(folio);
- if (!bh)
- return;
-
while (bh) {
struct buffer_head *next = bh->b_this_page;
free_buffer_head(bh);
I can submit a new vrsion, or Zi can just pick this up.
> commit d68f524234e61e6567e52a27e09b9d2546ab54af
> Author: Matthew Wilcox (Oracle) <willy@infradead.org>
>
> md: Use folio APIs in free_page()
>
> This commit converts the page to a folio, removing some of the last uses of
> a few page APIs and replacing two calls to compound_head() with one.
>
> > diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
> > index 5f1637f974c15..7b42db87d536d 100644
> > --- a/drivers/md/md-bitmap.c
> > +++ b/drivers/md/md-bitmap.c
> > @@ -533,19 +533,18 @@ static void write_file_page(struct bitmap *bitmap, struct page *page, int wait)
> >
> > static void free_buffers(struct page *page)
> > {
> > - struct buffer_head *bh;
> > + struct folio *folio = page_folio(page);
> > + struct buffer_head *bh = folio_detach_private(folio);
> >
> > - if (!PagePrivate(page))
> > + if (!bh)
> > return;
>
> [Severity: High]
> This is a pre-existing issue, but this early return skips the folio_put()
> required to drop the base allocation reference for pages that do not have
> buffers attached.
>
> For internal bitmaps, pages are allocated via alloc_page() with a refcount
> of 1 in md_bitmap_storage_alloc():
>
> drivers/md/md-bitmap.c:md_bitmap_storage_alloc() {
> ...
> store->filemap[pnum] = alloc_page(GFP_KERNEL|__GFP_ZERO);
> ...
> }
>
> During MD array teardown or failure, md_bitmap_file_unmap() calls
> free_buffers() on these pages:
>
> drivers/md/md-bitmap.c:md_bitmap_file_unmap() {
> ...
> free_buffers(map[pages]);
> ...
> }
>
> Because internal bitmap pages don't have buffers attached, (!bh) evaluates
> to true, triggering the early return and completely bypassing the folio_put()
> at the end of the function.
>
> This permanently leaks the pages allocated for the internal bitmap's filemap
> and superblock.
>
> Does this early return need to be updated so that folio_put() is still
> called for folios without buffers?
>
> > - bh = page_buffers(page);
> > while (bh) {
> > struct buffer_head *next = bh->b_this_page;
> > free_buffer_head(bh);
> > bh = next;
> > }
> > - detach_page_private(page);
> > - put_page(page);
> > + folio_put(folio);
> > }
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260913-remove-pg_private-v4-0-848550f7574e@nvidia.com?part=2
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [PATCH 2/3] md: Use folio APIs in free_page()
2026-09-14 16:21 ` Matthew Wilcox
@ 2026-09-14 16:25 ` Zi Yan
0 siblings, 0 replies; 22+ messages in thread
From: Zi Yan @ 2026-09-14 16:25 UTC (permalink / raw)
To: Matthew Wilcox
Cc: sashiko-reviews, yukuai, linux-raid, David Hildenbrand, linux-mm
On 14 Sep 2026, at 12:21, Matthew Wilcox wrote:
> On Mon, Sep 14, 2026 at 04:31:29AM +0000, sashiko-bot@kernel.org wrote:
>> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>>
>> Pre-existing issues:
>> - [High] Memory leak of internal bitmap pages and uninitialized file bitmap pages during teardown or error handling due to an early return in free_buffers().
>> --
>
> Yes, I thought the early return looked weird. I just believed that I
> hadn't looked into the code enough to understand why it looked weird but
> was right. Since the AI says it's wrong, I'm happy to believe it's wrong.
> It's probably not really a high seveirty problem because most RAIDs are
> set up once and then never removed, so the leak doesn't matter.
>
> The other thing that looks weird is that this code believes the b_this_page
> list is NULL terminated. Most loops over "all BHs attached to a folio"
> have a circular list. However, that is established by link_dev_buffers()
> which is not called by md-bitmap. So it's correct, even though weird.
>
> The good news is this is an easy fix:
>
> @@ -536,9 +536,6 @@ static void free_buffers(struct page *page)
> struct folio *folio = page_folio(page);
> struct buffer_head *bh = folio_detach_private(folio);
>
> - if (!bh)
> - return;
> -
> while (bh) {
> struct buffer_head *next = bh->b_this_page;
> free_buffer_head(bh);
>
> I can submit a new vrsion, or Zi can just pick this up.
I can fold this into your patch. Or should this be sent separately
as a fix and maybe a backport?
>
>> commit d68f524234e61e6567e52a27e09b9d2546ab54af
>> Author: Matthew Wilcox (Oracle) <willy@infradead.org>
>>
>> md: Use folio APIs in free_page()
>>
>> This commit converts the page to a folio, removing some of the last uses of
>> a few page APIs and replacing two calls to compound_head() with one.
>>
>>> diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
>>> index 5f1637f974c15..7b42db87d536d 100644
>>> --- a/drivers/md/md-bitmap.c
>>> +++ b/drivers/md/md-bitmap.c
>>> @@ -533,19 +533,18 @@ static void write_file_page(struct bitmap *bitmap, struct page *page, int wait)
>>>
>>> static void free_buffers(struct page *page)
>>> {
>>> - struct buffer_head *bh;
>>> + struct folio *folio = page_folio(page);
>>> + struct buffer_head *bh = folio_detach_private(folio);
>>>
>>> - if (!PagePrivate(page))
>>> + if (!bh)
>>> return;
>>
>> [Severity: High]
>> This is a pre-existing issue, but this early return skips the folio_put()
>> required to drop the base allocation reference for pages that do not have
>> buffers attached.
>>
>> For internal bitmaps, pages are allocated via alloc_page() with a refcount
>> of 1 in md_bitmap_storage_alloc():
>>
>> drivers/md/md-bitmap.c:md_bitmap_storage_alloc() {
>> ...
>> store->filemap[pnum] = alloc_page(GFP_KERNEL|__GFP_ZERO);
>> ...
>> }
>>
>> During MD array teardown or failure, md_bitmap_file_unmap() calls
>> free_buffers() on these pages:
>>
>> drivers/md/md-bitmap.c:md_bitmap_file_unmap() {
>> ...
>> free_buffers(map[pages]);
>> ...
>> }
>>
>> Because internal bitmap pages don't have buffers attached, (!bh) evaluates
>> to true, triggering the early return and completely bypassing the folio_put()
>> at the end of the function.
>>
>> This permanently leaks the pages allocated for the internal bitmap's filemap
>> and superblock.
>>
>> Does this early return need to be updated so that folio_put() is still
>> called for folios without buffers?
>>
>>> - bh = page_buffers(page);
>>> while (bh) {
>>> struct buffer_head *next = bh->b_this_page;
>>> free_buffer_head(bh);
>>> bh = next;
>>> }
>>> - detach_page_private(page);
>>> - put_page(page);
>>> + folio_put(folio);
>>> }
>>
>> --
>> Sashiko AI review · https://sashiko.dev/#/patchset/20260913-remove-pg_private-v4-0-848550f7574e@nvidia.com?part=2
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 2/3] md: Use folio APIs in free_page()
2026-09-14 4:18 ` [PATCH 2/3] md: Use folio APIs in free_page() Matthew Wilcox (Oracle)
2026-09-14 4:31 ` sashiko-bot
@ 2026-09-14 13:13 ` David Hildenbrand (Arm)
1 sibling, 0 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-09-14 13:13 UTC (permalink / raw)
To: Matthew Wilcox (Oracle), Zi Yan; +Cc: linux-raid, linux-mm
On 9/14/26 06:18, Matthew Wilcox (Oracle) wrote:
> Convert the page to a folio. This removes some of the last uses of a
> few page APIs (detach_page_private(), page_buffers()). Replaces two
> calls to compound_head() with one.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 3/3] md: Remove the last use of page_buffers()
2026-09-14 2:23 [PATCH v4 00/16] Remove PG_private by using page/folio->private checks instead Zi Yan
` (4 preceding siblings ...)
2026-09-14 4:18 ` [PATCH 2/3] md: Use folio APIs in free_page() Matthew Wilcox (Oracle)
@ 2026-09-14 4:18 ` Matthew Wilcox (Oracle)
2026-09-14 4:29 ` sashiko-bot
2026-09-14 13:14 ` David Hildenbrand (Arm)
2026-09-14 4:21 ` [PATCH v4 00/16] Remove PG_private by using page/folio->private checks instead Matthew Wilcox
2026-09-14 15:30 ` [f2fs-dev] " patchwork-bot+f2fs
7 siblings, 2 replies; 22+ messages in thread
From: Matthew Wilcox (Oracle) @ 2026-09-14 4:18 UTC (permalink / raw)
To: Zi Yan; +Cc: Matthew Wilcox (Oracle), linux-raid, linux-mm
Convert the page to a folio and use folio_buffers() instead. This
does introduce one extra call to compound_head(), but will simplify a
later conversion of md-bitmap to use folios instead of pages.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
drivers/md/md-bitmap.c | 3 ++-
include/linux/buffer_head.h | 7 +------
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 7b42db87d536..c2528220c406 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -516,7 +516,8 @@ static void end_bitmap_write(struct bio *bio)
static void write_file_page(struct bitmap *bitmap, struct page *page, int wait)
{
- struct buffer_head *bh = page_buffers(page);
+ struct folio *folio = page_folio(page);
+ struct buffer_head *bh = folio_buffers(folio);
while (bh && bh->b_blocknr) {
atomic_inc(&bitmap->pending_writes);
diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
index c9918176adaa..1d5eb6ba4576 100644
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -175,12 +175,7 @@ static inline unsigned long bh_offset(const struct buffer_head *bh)
return (unsigned long)(bh)->b_data & (page_size(bh->b_page) - 1);
}
-/* If we *know* page->private refers to buffer_heads */
-#define page_buffers(page) \
- ({ \
- BUG_ON(!PagePrivate(page)); \
- ((struct buffer_head *)page_private(page)); \
- })
+/* If we *know* folio->private refers to buffer_heads */
#define folio_buffers(folio) folio_get_private(folio)
void buffer_check_dirty_writeback(struct folio *folio,
--
2.47.3
^ permalink raw reply related [flat|nested] 22+ messages in thread* Re: [PATCH 3/3] md: Remove the last use of page_buffers()
2026-09-14 4:18 ` [PATCH 3/3] md: Remove the last use of page_buffers() Matthew Wilcox (Oracle)
@ 2026-09-14 4:29 ` sashiko-bot
2026-09-14 13:14 ` David Hildenbrand (Arm)
1 sibling, 0 replies; 22+ messages in thread
From: sashiko-bot @ 2026-09-14 4:29 UTC (permalink / raw)
To: Matthew Wilcox (Oracle); +Cc: yukuai, linux-raid
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Memory leak of bitmap pages in `free_buffers()` when unmapping an internal block-device bitmap or on error paths for file-backed bitmaps.
--
commit 5c27b3beb1da589c8d8b3b4113d43873e56ed7da
Author: Matthew Wilcox (Oracle) <willy@infradead.org>
md: Remove the last use of page_buffers()
This commit converts the page to a folio in write_file_page() and uses
folio_buffers() instead of page_buffers(). This change prepares the
md-bitmap codebase for a later conversion from pages to folios.
> diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
> index 7b42db87d536d..c2528220c406d 100644
> --- a/drivers/md/md-bitmap.c
> +++ b/drivers/md/md-bitmap.c
> @@ -516,7 +516,8 @@ static void end_bitmap_write(struct bio *bio)
>
> static void write_file_page(struct bitmap *bitmap, struct page *page, int wait)
> {
> - struct buffer_head *bh = page_buffers(page);
> + struct folio *folio = page_folio(page);
> + struct buffer_head *bh = folio_buffers(folio);
[Severity: High]
This is a pre-existing issue, but since this code is being converted to use
folios, does free_buffers() leak the folio when unmapping an internal
block-device bitmap or on error paths for file-backed bitmaps?
In md_bitmap_storage_alloc(), memory for store->filemap is allocated using
alloc_page(), which sets the baseline refcount to 1. For internal
block-device bitmaps, the pages are read using read_sb_page() which does
not attach buffer_head structures or set the folio private flag.
During array teardown, md_bitmap_file_unmap() iterates over store->filemap
and calls free_buffers():
static void free_buffers(struct page *page)
{
struct folio *folio = page_folio(page);
struct buffer_head *bh = folio_detach_private(folio);
if (!bh)
return;
...
folio_put(folio);
}
Since folio_detach_private() returns NULL here, the early return skips the
final folio_put(). Over time, this could accumulate to megabytes of leaked
memory if an administrator repeatedly starts and stops md arrays with
internal bitmaps.
Could this early return be updated to ensure the folio reference is properly
dropped even when there are no buffers attached?
>
> while (bh && bh->b_blocknr) {
> atomic_inc(&bitmap->pending_writes);
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260913-remove-pg_private-v4-0-848550f7574e@nvidia.com?part=3
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [PATCH 3/3] md: Remove the last use of page_buffers()
2026-09-14 4:18 ` [PATCH 3/3] md: Remove the last use of page_buffers() Matthew Wilcox (Oracle)
2026-09-14 4:29 ` sashiko-bot
@ 2026-09-14 13:14 ` David Hildenbrand (Arm)
1 sibling, 0 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-09-14 13:14 UTC (permalink / raw)
To: Matthew Wilcox (Oracle), Zi Yan; +Cc: linux-raid, linux-mm
On 9/14/26 06:18, Matthew Wilcox (Oracle) wrote:
> Convert the page to a folio and use folio_buffers() instead. This
> does introduce one extra call to compound_head(), but will simplify a
> later conversion of md-bitmap to use folios instead of pages.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v4 00/16] Remove PG_private by using page/folio->private checks instead
2026-09-14 2:23 [PATCH v4 00/16] Remove PG_private by using page/folio->private checks instead Zi Yan
` (5 preceding siblings ...)
2026-09-14 4:18 ` [PATCH 3/3] md: Remove the last use of page_buffers() Matthew Wilcox (Oracle)
@ 2026-09-14 4:21 ` Matthew Wilcox
2026-09-14 13:10 ` David Hildenbrand (Arm)
2026-09-14 15:30 ` [f2fs-dev] " patchwork-bot+f2fs
7 siblings, 1 reply; 22+ messages in thread
From: Matthew Wilcox @ 2026-09-14 4:21 UTC (permalink / raw)
To: Zi Yan
Cc: David Hildenbrand, Andrew Morton, Muchun Song, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Baolin Wang, Nico Pache,
Ryan Roberts, Dev Jain, Barry Song, Lance Yang, Usama Arif,
Gregory Price, Ying Huang, Alistair Popple, Johannes Weiner,
Qi Zheng, Shakeel Butt, Kairui Song, linux-mm, linux-kernel,
Minchan Kim, Sergey Senozhatsky, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Thomas Gleixner,
Borislav Petkov, Dave Hansen, x86, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
James Clark, H. Peter Anvin, linux-perf-users, Juergen Gross,
Stefano Stabellini, Oleksandr Tyshchenko, xen-devel, Eric Biggers,
Theodore Y. Ts'o, Jaegeuk Kim, linux-fscrypt, Oscar Salvador,
Chao Yu, linux-f2fs-devel, Tal Zussman, Gao Xiang, Jan Kara,
Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li, Chunhai Guo,
linux-erofs, linux-fsdevel, Steven Rostedt, Masami Hiramatsu,
Mathieu Desnoyers, Matthew Brost, Joshua Hahn, Rakie Kim,
Byungchul Park, Axel Rasmussen, Yuanchu Xie, Wei Xu,
linux-trace-kernel, Trond Myklebust, Anna Schumaker, linux-nfs,
Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko, ceph-devel,
Song Liu, Yu Kuai, Li Nan, Xiao Ni, linux-raid,
Richard Weinberger, Zhihao Cheng, linux-mtd, Baoquan He,
Pasha Tatashin, Pratyush Yadav, Jonathan Corbet, Dave Young,
Shuah Khan, kexec, linux-doc
On Sun, Sep 13, 2026 at 10:23:58PM -0400, Zi Yan wrote:
> md/md-bitmap: replace PagePrivate() with page_private()
> buffer: replace page_buffer() with page_private() and delete it
Sorry, looks like I screwed up git send-email usage. I'm proposing
replacing these two patches wth the three I sent.
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [PATCH v4 00/16] Remove PG_private by using page/folio->private checks instead
2026-09-14 4:21 ` [PATCH v4 00/16] Remove PG_private by using page/folio->private checks instead Matthew Wilcox
@ 2026-09-14 13:10 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-09-14 13:10 UTC (permalink / raw)
To: Matthew Wilcox, Zi Yan
Cc: Andrew Morton, Muchun Song, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, Usama Arif, Gregory Price, Ying Huang,
Alistair Popple, Johannes Weiner, Qi Zheng, Shakeel Butt,
Kairui Song, linux-mm, linux-kernel, Minchan Kim,
Sergey Senozhatsky, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Thomas Gleixner,
Borislav Petkov, Dave Hansen, x86, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
James Clark, H. Peter Anvin, linux-perf-users, Juergen Gross,
Stefano Stabellini, Oleksandr Tyshchenko, xen-devel, Eric Biggers,
Theodore Y. Ts'o, Jaegeuk Kim, linux-fscrypt, Oscar Salvador,
Chao Yu, linux-f2fs-devel, Tal Zussman, Gao Xiang, Jan Kara,
Yue Hu, Jeffle Xu, Sandeep Dhavale, Hongbo Li, Chunhai Guo,
linux-erofs, linux-fsdevel, Steven Rostedt, Masami Hiramatsu,
Mathieu Desnoyers, Matthew Brost, Joshua Hahn, Rakie Kim,
Byungchul Park, Axel Rasmussen, Yuanchu Xie, Wei Xu,
linux-trace-kernel, Trond Myklebust, Anna Schumaker, linux-nfs,
Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko, ceph-devel,
Song Liu, Yu Kuai, Li Nan, Xiao Ni, linux-raid,
Richard Weinberger, Zhihao Cheng, linux-mtd, Baoquan He,
Pasha Tatashin, Pratyush Yadav, Jonathan Corbet, Dave Young,
Shuah Khan, kexec, linux-doc
On 9/14/26 06:21, Matthew Wilcox wrote:
> On Sun, Sep 13, 2026 at 10:23:58PM -0400, Zi Yan wrote:
>> md/md-bitmap: replace PagePrivate() with page_private()
>> buffer: replace page_buffer() with page_private() and delete it
>
> Sorry, looks like I screwed up git send-email usage. I'm proposing
> replacing these two patches wth the three I sent.
For everybody CCed wondering "which patches":
https://lore.kernel.org/r/20260914041830.2072626-1-willy@infradead.org
https://lore.kernel.org/r/20260914041830.2072626-2-willy@infradead.org
https://lore.kernel.org/r/20260914041830.2072626-3-willy@infradead.org
--
Cheers,
David
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [f2fs-dev] [PATCH v4 00/16] Remove PG_private by using page/folio->private checks instead
2026-09-14 2:23 [PATCH v4 00/16] Remove PG_private by using page/folio->private checks instead Zi Yan
` (6 preceding siblings ...)
2026-09-14 4:21 ` [PATCH v4 00/16] Remove PG_private by using page/folio->private checks instead Matthew Wilcox
@ 2026-09-14 15:30 ` patchwork-bot+f2fs
7 siblings, 0 replies; 22+ messages in thread
From: patchwork-bot+f2fs @ 2026-09-14 15:30 UTC (permalink / raw)
To: Zi Yan
Cc: david, willy, akpm, muchun.song, ljs, liam, vbabka, rppt, surenb,
mhocko, baolin.wang, nico.pache, ryan.roberts, dev.jain, baohua,
lance.yang, usama.arif, gourry, ying.huang, apopple, hannes,
qi.zheng, shakeel.butt, kasong, mark.rutland, irogers, jack,
linux-doc, amarkuze, peterz, kexec, dave.hansen, ruirui.yang,
adrian.hunter, linux-mm, hongbohbli, hpa, guochunhai, skhan,
tz2294, baoquan.he, matthew.brost, anna, sstabellini, zbestahu,
rakie.kim, minchan, richard, x86, ceph-devel, ebiggers,
alexander.shishkin, mingo, slava, weixugc, yukuai, xen-devel,
xiang, magiclinan, mhiramat, joshua.hahnjy, xiao, byungchul,
james.clark, acme, linux-raid, linux-fscrypt, bp, rostedt,
linux-mtd, axelrasmussen, jefflexu, namhyung, jaegeuk, yuanchu,
idryomov, osalvador, jgross, pratyush, linux-nfs, tytso,
oleksandr_tyshchenko, song, corbet, pasha.tatashin, linux-kernel,
linux-f2fs-devel, linux-perf-users, senozhatsky, tglx, jolsa,
linux-fsdevel, mathieu.desnoyers, linux-trace-kernel, linux-erofs,
trondmy
Hello:
This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:
On Sun, 13 Sep 2026 22:23:58 -0400 you wrote:
> Hi all,
>
> This patchset removes PG_private to make space for upcoming PG_folio for
> identifying pages from a folio (more details in Note below). Instead of
> checking PG_private, all code is changed to check page/folio->private !=
> NULL instead.
>
> [...]
Here is the summary with links:
- [f2fs-dev,v4,06/16] f2fs: stop using PG_private
https://git.kernel.org/jaegeuk/f2fs/c/60105162524e
- [f2fs-dev,v4,07/16] f2fs: convert the ->private flag helpers to folio-only
(no matching commit)
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 22+ messages in thread