summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChenghao Duan <duanchenghao@kylinos.cn>2026-03-26 16:47:21 +0800
committerAndrew Morton <akpm@linux-foundation.org>2026-04-18 00:10:52 -0700
commited2a29dc6dcf4630ef19d588704c2ca7b46607bb (patch)
tree36d9e1c76fcd9d1ca8aaa600ce68dfc912285f36
parent7cf6d940f4032d87d9cfe6b27c0e49e309818e5d (diff)
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>
-rw-r--r--mm/memfd_luo.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c
index 9130e6ce396d..ec4c3e1e2891 100644
--- a/mm/memfd_luo.c
+++ b/mm/memfd_luo.c
@@ -410,6 +410,7 @@ static int memfd_luo_retrieve_folios(struct file *file,
struct inode *inode = file_inode(file);
struct address_space *mapping = inode->i_mapping;
struct folio *folio;
+ long npages;
int err = -EIO;
long i;
@@ -456,14 +457,15 @@ 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);
+ npages = folio_nr_pages(folio);
+ err = shmem_inode_acct_blocks(inode, npages);
if (err) {
- pr_err("shmem: failed to account folio index %ld: %d\n",
- i, err);
+ pr_err("shmem: failed to account folio index %ld(%ld pages): %d\n",
+ i, npages, err);
goto unlock_folio;
}
- shmem_recalc_inode(inode, 1, 0);
+ shmem_recalc_inode(inode, npages, 0);
folio_add_lru(folio);
folio_unlock(folio);
folio_put(folio);