All of lore.kernel.org
 help / color / mirror / Atom feed
* + mm-memfd-use-folio_nr_pages-for-shmem-inode-accounting.patch added to mm-new branch
@ 2026-03-23 21:09 Andrew Morton
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2026-03-23 21:09 UTC (permalink / raw)
  To: mm-commits, rppt, pratyush, pasha.tatashin, jianghaoran,
	duanchenghao, akpm


The patch titled
     Subject: mm/memfd: use folio_nr_pages() for shmem inode accounting
has been added to the -mm mm-new branch.  Its filename is
     mm-memfd-use-folio_nr_pages-for-shmem-inode-accounting.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-memfd-use-folio_nr_pages-for-shmem-inode-accounting.patch

This patch will later appear in the mm-new branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews.  Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.

The mm-new branch of mm.git is not included in linux-next

If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days

------------------------------------------------------
From: Chenghao Duan <duanchenghao@kylinos.cn>
Subject: mm/memfd: use folio_nr_pages() for shmem inode accounting
Date: Mon, 23 Mar 2026 19:07:44 +0800

Patch series "Modify memfd_luo code", v2.

Various fixes and cleanups for the memfd LUO code.


This patch (of 4):

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://lkml.kernel.org/r/20260323110747.193569-1-duanchenghao@kylinos.cn
Link: https://lkml.kernel.org/r/20260323110747.193569-2-duanchenghao@kylinos.cn
Signed-off-by: Chenghao Duan <duanchenghao@kylinos.cn>
Suggested-by: Pratyush Yadav <pratyush@kernel.org>
Cc: Haoran Jiang <jianghaoran@kylinos.cn>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Pratyush Yadav <pratyush@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/memfd_luo.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

--- a/mm/memfd_luo.c~mm-memfd-use-folio_nr_pages-for-shmem-inode-accounting
+++ a/mm/memfd_luo.c
@@ -410,6 +410,7 @@ static int memfd_luo_retrieve_folios(str
 	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(str
 		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);
_

Patches currently in -mm which might be from duanchenghao@kylinos.cn are

mm-memfd-use-folio_nr_pages-for-shmem-inode-accounting.patch
mm-memfd_luo-optimize-shmem_recalc_inode-calls-in-retrieve-path.patch
mm-memfd_luo-remove-unnecessary-memset-in-zero-size-memfd-path.patch
mm-memfd_luo-use-i_size_write-to-set-inode-size-during-retrieve.patch


^ permalink raw reply	[flat|nested] 4+ messages in thread

* + mm-memfd-use-folio_nr_pages-for-shmem-inode-accounting.patch added to mm-new branch
@ 2026-03-26 23:39 Andrew Morton
  2026-03-27 23:24 ` SeongJae Park
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2026-03-26 23:39 UTC (permalink / raw)
  To: mm-commits, rppt, pratyush, pasha.tatashin, jianghaoran,
	duanchenghao, akpm


The patch titled
     Subject: mm/memfd: use folio_nr_pages() for shmem inode accounting
has been added to the -mm mm-new branch.  Its filename is
     mm-memfd-use-folio_nr_pages-for-shmem-inode-accounting.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-memfd-use-folio_nr_pages-for-shmem-inode-accounting.patch

This patch will later appear in the mm-new branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews.  Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.

The mm-new branch of mm.git is not included in linux-next

If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days

------------------------------------------------------
From: Chenghao Duan <duanchenghao@kylinos.cn>
Subject: mm/memfd: use folio_nr_pages() for shmem inode accounting
Date: Thu, 26 Mar 2026 16:47:21 +0800

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

 mm/memfd_luo.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

--- a/mm/memfd_luo.c~mm-memfd-use-folio_nr_pages-for-shmem-inode-accounting
+++ a/mm/memfd_luo.c
@@ -410,6 +410,7 @@ static int memfd_luo_retrieve_folios(str
 	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(str
 		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);
_

Patches currently in -mm which might be from duanchenghao@kylinos.cn are

mm-memfd-use-folio_nr_pages-for-shmem-inode-accounting.patch
mm-memfd_luo-optimize-shmem_recalc_inode-calls-in-retrieve-path.patch
mm-memfd_luo-remove-unnecessary-memset-in-zero-size-memfd-path.patch
mm-memfd_luo-use-i_size_write-to-set-inode-size-during-retrieve.patch
mm-memfd_luo-fix-physical-address-conversion-in-put_folios-cleanup.patch
mm-memfd_luo-remove-folio-from-page-cache-when-accounting-fails.patch
mm-memfd_luo-fix-integer-overflow-in-memfd_luo_preserve_folios.patch


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: + mm-memfd-use-folio_nr_pages-for-shmem-inode-accounting.patch added to mm-new branch
  2026-03-26 23:39 + mm-memfd-use-folio_nr_pages-for-shmem-inode-accounting.patch added to mm-new branch Andrew Morton
@ 2026-03-27 23:24 ` SeongJae Park
  2026-03-27 23:32   ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: SeongJae Park @ 2026-03-27 23:24 UTC (permalink / raw)
  To: Andrew Morton
  Cc: SeongJae Park, mm-commits, rppt, pratyush, pasha.tatashin,
	jianghaoran, duanchenghao

Hello Andrew,

On Thu, 26 Mar 2026 16:39:11 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:

> 
> The patch titled
>      Subject: mm/memfd: use folio_nr_pages() for shmem inode accounting
> has been added to the -mm mm-new branch.  Its filename is
>      mm-memfd-use-folio_nr_pages-for-shmem-inode-accounting.patch
[...]
> ------------------------------------------------------
> From: Chenghao Duan <duanchenghao@kylinos.cn>
> Subject: mm/memfd: use folio_nr_pages() for shmem inode accounting
> Date: Thu, 26 Mar 2026 16:47:21 +0800
> 
> Patch series "Modify memfd_luo code", v3.

Seems the "This patch (of N):" line is missed.

Not an issue for me, but just wanted to let you know since it seems it is not
your real intention.


Thanks,
SJ

[...]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: + mm-memfd-use-folio_nr_pages-for-shmem-inode-accounting.patch added to mm-new branch
  2026-03-27 23:24 ` SeongJae Park
@ 2026-03-27 23:32   ` Andrew Morton
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2026-03-27 23:32 UTC (permalink / raw)
  To: SeongJae Park
  Cc: mm-commits, rppt, pratyush, pasha.tatashin, jianghaoran,
	duanchenghao

On Fri, 27 Mar 2026 16:24:39 -0700 SeongJae Park <sj@kernel.org> wrote:

> > From: Chenghao Duan <duanchenghao@kylinos.cn>
> > Subject: mm/memfd: use folio_nr_pages() for shmem inode accounting
> > Date: Thu, 26 Mar 2026 16:47:21 +0800
> > 
> > Patch series "Modify memfd_luo code", v3.
> 
> Seems the "This patch (of N):" line is missed.

grr, thanks.

	if grep -q "^Patch series" $p ; then
		if ! grep -q "^This patch " $p; then
			echo $p: "This patch"
		fi
	fi

there, plugged.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-03-27 23:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-26 23:39 + mm-memfd-use-folio_nr_pages-for-shmem-inode-accounting.patch added to mm-new branch Andrew Morton
2026-03-27 23:24 ` SeongJae Park
2026-03-27 23:32   ` Andrew Morton
  -- strict thread matches above, loose matches on Subject: below --
2026-03-23 21:09 Andrew Morton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.