mm: memfd_luo: account restored large folios correctly
Subsystems (2)
PATCH 1/1 mm: memfd_luo: account restored large folios correctly
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.
--- mm/memfd_luo.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
mm/memfd_luo.c +5 -2
@@ -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);
Signature · 1 line
2.43.0
Pratyush Yadav
maintainerHi DaeMyung,
Quoted 9 lines · DaeMyung Kang
memfd_luo_retrieve_folios()always passes 1 toshmem_inode_acct_blocks()andshmem_recalc_inode(), even when the restored folio spans multiple pages.That mismatches the normal shmem path:
shmem_add_to_page_cache()accounts the folio inmapping->nrpagesusingfolio_nr_pages(folio), andshmem_alloc_and_add_folio()passes the same page count toshmem_inode_acct_blocks()andshmem_recalc_inode().
Quoted 7 lines
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 <[email protected]>
Thanks for the patch. This bug is already fixed by this patch [0].
[0] https://lore.kernel.org/linux-mm/[email protected]/
[...]
Signature · 2 lines
Regards, Pratyush Yadav