linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] /dev/zero: try to align PMD_SIZE for private mapping
@ 2025-07-30  2:22 Zhang Qilong
  2025-07-30  4:28 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Zhang Qilong @ 2025-07-30  2:22 UTC (permalink / raw)
  To: arnd, gregkh
  Cc: linux-kernel, linux-mm, lorenzo.stoakes, wangkefeng.wang,
	zhangqilong3, sunnanyong

If THP is enable, mapping /dev/zero with a size larger than 2MB could
achieve performance gains by allocating aligned address. The mprot_tw4m
in libMicro average execution time on arm64:
  - Test case:        mprot_tw4m
  - Before the patch:   22 us
  - After the patch:    17 us

Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
---
 drivers/char/mem.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 48839958b0b1..3699e716b84e 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -525,12 +525,20 @@ static unsigned long get_unmapped_area_zero(struct file *file,
 		 * so as not to confuse shmem with our handle on "/dev/zero".
 		 */
 		return shmem_get_unmapped_area(NULL, addr, len, pgoff, flags);
 	}
 
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+	/*
+	 * Attempt to map aligned to huge page size if possible, otherwise we
+	 * fall back to system page size mappings in thp_get_unmapped_area.
+	 */
+	return thp_get_unmapped_area(file, addr, len, pgoff, flags);
+#else
 	/* Otherwise flags & MAP_PRIVATE: with no shmem object beneath it */
 	return mm_get_unmapped_area(current->mm, file, addr, len, pgoff, flags);
+#endif
 #else
 	return -ENOSYS;
 #endif
 }
 
-- 
2.43.0



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

end of thread, other threads:[~2025-07-30  4:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-30  2:22 [PATCH v2] /dev/zero: try to align PMD_SIZE for private mapping Zhang Qilong
2025-07-30  4:28 ` Greg KH

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).