Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/memfd: use folio_nr_pages() for shmem inode accounting

I found several modifiable points while reading the code.


This patch (of 6):

Patch series "Modify memfd_luo code", v3.

memfd_luo_retrieve_folios() called shmem_inode_acct_blocks() and
shmem_recalc_inode() with hardcoded 1 instead of the actual folio page
count. memfd may use large folios (THP/hugepages), causing quota/limit
under-accounting and incorrect stat output.

Fix by using folio_nr_pages(folio) for both functions.

Issue found by AI review and suggested by Pratyush Yadav <pratyush@kernel.org>.
https://sashiko.dev/#/patchset/20260319012845.29570-1-duanchenghao%40kylinos.cn

Link: https://lore.kernel.org/20260326084727.118437-1-duanchenghao@kylinos.cn
Link: https://lore.kernel.org/20260326084727.118437-2-duanchenghao@kylinos.cn
Signed-off-by: Chenghao Duan <duanchenghao@kylinos.cn>
Suggested-by: Pratyush Yadav <pratyush@kernel.org>
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
Cc: Haoran Jiang <jianghaoran@kylinos.cn>
Cc: Mike Rapoport <rppt@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Chenghao Duan and committed by
Andrew Morton
ed2a29dc 7cf6d940

+6 -4
+6 -4
mm/memfd_luo.c
··· 410 410 struct inode *inode = file_inode(file); 411 411 struct address_space *mapping = inode->i_mapping; 412 412 struct folio *folio; 413 + long npages; 413 414 int err = -EIO; 414 415 long i; 415 416 ··· 457 456 if (flags & MEMFD_LUO_FOLIO_DIRTY) 458 457 folio_mark_dirty(folio); 459 458 460 - err = shmem_inode_acct_blocks(inode, 1); 459 + npages = folio_nr_pages(folio); 460 + err = shmem_inode_acct_blocks(inode, npages); 461 461 if (err) { 462 - pr_err("shmem: failed to account folio index %ld: %d\n", 463 - i, err); 462 + pr_err("shmem: failed to account folio index %ld(%ld pages): %d\n", 463 + i, npages, err); 464 464 goto unlock_folio; 465 465 } 466 466 467 - shmem_recalc_inode(inode, 1, 0); 467 + shmem_recalc_inode(inode, npages, 0); 468 468 folio_add_lru(folio); 469 469 folio_unlock(folio); 470 470 folio_put(folio);