linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: DaeMyung Kang <charsyam@gmail.com>
To: pasha.tatashin@soleen.com, rppt@kernel.org, akpm@linux-foundation.org
Cc: pratyush@kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, DaeMyung Kang <charsyam@gmail.com>
Subject: [PATCH] mm: memfd_luo: account restored large folios correctly
Date: Tue, 14 Apr 2026 01:50:53 +0900	[thread overview]
Message-ID: <20260413165053.164338-1-charsyam@gmail.com> (raw)

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



                 reply	other threads:[~2026-04-13 16:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260413165053.164338-1-charsyam@gmail.com \
    --to=charsyam@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.org \
    --cc=rppt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox