linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mm: fault in complete folios instead of individual pages for tmpfs
@ 2025-07-04  3:19 Baolin Wang
  2025-07-04  9:38 ` David Hildenbrand
                   ` (5 more replies)
  0 siblings, 6 replies; 17+ messages in thread
From: Baolin Wang @ 2025-07-04  3:19 UTC (permalink / raw)
  To: akpm, hughd, david
  Cc: ziy, lorenzo.stoakes, Liam.Howlett, npache, ryan.roberts,
	dev.jain, baohua, vbabka, rppt, surenb, mhocko, baolin.wang,
	linux-mm, linux-kernel

After commit acd7ccb284b8 ("mm: shmem: add large folio support for tmpfs"),
tmpfs can also support large folio allocation (not just PMD-sized large
folios).

However, when accessing tmpfs via mmap(), although tmpfs supports large folios,
we still establish mappings at the base page granularity, which is unreasonable.

We can map multiple consecutive pages of a tmpfs folios at once according to
the size of the large folio. On one hand, this can reduce the overhead of page
faults; on the other hand, it can leverage hardware architecture optimizations
to reduce TLB misses, such as contiguous PTEs on the ARM architecture.

Moreover, tmpfs mount will use the 'huge=' option to control large folio
allocation explicitly. So it can be understood that the process's RSS statistics
might increase, and I think this will not cause any obvious effects for users.

Performance test:
I created a 1G tmpfs file, populated with 64K large folios, and write-accessed it
sequentially via mmap(). I observed a significant performance improvement:

Before the patch:
real	0m0.158s
user	0m0.008s
sys	0m0.150s

After the patch:
real	0m0.021s
user	0m0.004s
sys	0m0.017s

Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
Changes from v1:
 - Drop the unnecessary IS_ALIGNED() check, per David.
 - Update the commit message, per David.
---
 mm/memory.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index 0f9b32a20e5b..9944380e947d 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -5383,10 +5383,10 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
 
 	/*
 	 * Using per-page fault to maintain the uffd semantics, and same
-	 * approach also applies to non-anonymous-shmem faults to avoid
+	 * approach also applies to non shmem/tmpfs faults to avoid
 	 * inflating the RSS of the process.
 	 */
-	if (!vma_is_anon_shmem(vma) || unlikely(userfaultfd_armed(vma)) ||
+	if (!vma_is_shmem(vma) || unlikely(userfaultfd_armed(vma)) ||
 	    unlikely(needs_fallback)) {
 		nr_pages = 1;
 	} else if (nr_pages > 1) {
-- 
2.43.5


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

end of thread, other threads:[~2025-07-17  9:25 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-04  3:19 [PATCH v2] mm: fault in complete folios instead of individual pages for tmpfs Baolin Wang
2025-07-04  9:38 ` David Hildenbrand
2025-07-04 22:18 ` Andrew Morton
2025-07-06  2:02   ` Baolin Wang
2025-07-07 13:33     ` Lorenzo Stoakes
2025-07-08  7:53       ` Baolin Wang
2025-07-09 13:13         ` Lorenzo Stoakes
2025-07-15 20:03           ` Hugh Dickins
2025-07-17  8:01             ` Baolin Wang
2025-07-17  8:22               ` David Hildenbrand
2025-07-17  9:20                 ` Lorenzo Stoakes
2025-07-17  9:25                   ` David Hildenbrand
2025-07-17  9:19             ` Lorenzo Stoakes
2025-07-04 22:31 ` Zi Yan
2025-07-07 13:31 ` Lorenzo Stoakes
2025-07-07 15:47 ` Barry Song
2025-07-07 16:18 ` Vishal Moola (Oracle)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).