* [PATCH] mm: memfd_luo: account restored large folios correctly
@ 2026-04-13 16:50 DaeMyung Kang
2026-04-14 10:48 ` Pratyush Yadav
0 siblings, 1 reply; 2+ messages in thread
From: DaeMyung Kang @ 2026-04-13 16:50 UTC (permalink / raw)
To: pasha.tatashin, rppt, akpm
Cc: pratyush, linux-mm, linux-kernel, DaeMyung Kang
memfd_luo_retrieve_folios() always passes 1 to
shmem_inode_acct_blocks() and shmem_recalc_inode(), even when the
restored folio spans multiple pages.
That mismatches the normal shmem path: shmem_add_to_page_cache()
accounts the folio in mapping->nrpages using folio_nr_pages(folio),
and shmem_alloc_and_add_folio() passes the same page count to
shmem_inode_acct_blocks() and shmem_recalc_inode().
As a result, restored large folios are under-accounted in shmem inode
and block accounting.
Use folio_nr_pages(folio) here as well.
Fixes: b3749f174d68 ("mm: memfd_luo: allow preserving memfd")
Signed-off-by: DaeMyung Kang <charsyam@gmail.com>
---
mm/memfd_luo.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c
index b8edb9f981d7..6dd0284b90c6 100644
--- a/mm/memfd_luo.c
+++ b/mm/memfd_luo.c
@@ -402,6 +402,7 @@ static int memfd_luo_retrieve_folios(struct file *file,
const struct memfd_luo_folio_ser *pfolio = &folios_ser[i];
phys_addr_t phys;
u64 index;
+ long pages;
int flags;
if (!pfolio->pfn)
@@ -441,14 +442,16 @@ static int memfd_luo_retrieve_folios(struct file *file,
if (flags & MEMFD_LUO_FOLIO_DIRTY)
folio_mark_dirty(folio);
- err = shmem_inode_acct_blocks(inode, 1);
+ pages = folio_nr_pages(folio);
+
+ err = shmem_inode_acct_blocks(inode, pages);
if (err) {
pr_err("shmem: failed to account folio index %ld: %d\n",
i, err);
goto unlock_folio;
}
- shmem_recalc_inode(inode, 1, 0);
+ shmem_recalc_inode(inode, pages, 0);
folio_add_lru(folio);
folio_unlock(folio);
folio_put(folio);
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] mm: memfd_luo: account restored large folios correctly
2026-04-13 16:50 [PATCH] mm: memfd_luo: account restored large folios correctly DaeMyung Kang
@ 2026-04-14 10:48 ` Pratyush Yadav
0 siblings, 0 replies; 2+ messages in thread
From: Pratyush Yadav @ 2026-04-14 10:48 UTC (permalink / raw)
To: DaeMyung Kang
Cc: pasha.tatashin, rppt, akpm, pratyush, linux-mm, linux-kernel
Hi DaeMyung,
On Tue, Apr 14 2026, DaeMyung Kang wrote:
> memfd_luo_retrieve_folios() always passes 1 to
> shmem_inode_acct_blocks() and shmem_recalc_inode(), even when the
> restored folio spans multiple pages.
>
> That mismatches the normal shmem path: shmem_add_to_page_cache()
> accounts the folio in mapping->nrpages using folio_nr_pages(folio),
> and shmem_alloc_and_add_folio() passes the same page count to
> shmem_inode_acct_blocks() and shmem_recalc_inode().
>
> As a result, restored large folios are under-accounted in shmem inode
> and block accounting.
>
> Use folio_nr_pages(folio) here as well.
>
> Fixes: b3749f174d68 ("mm: memfd_luo: allow preserving memfd")
> Signed-off-by: DaeMyung Kang <charsyam@gmail.com>
Thanks for the patch. This bug is already fixed by this patch [0].
[0] https://lore.kernel.org/linux-mm/20260326084727.118437-2-duanchenghao@kylinos.cn/
[...]
--
Regards,
Pratyush Yadav
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-14 10:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-13 16:50 [PATCH] mm: memfd_luo: account restored large folios correctly DaeMyung Kang
2026-04-14 10:48 ` Pratyush Yadav
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox