[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250729134942.900517-1-zhangqilong3@huawei.com>
Date: Tue, 29 Jul 2025 21:49:41 +0800
From: Zhang Qilong <zhangqilong3@...wei.com>
To: <arnd@...db.de>, <gregkh@...uxfoundation.org>
CC: <linux-kernel@...r.kernel.org>, <linux-mm@...ck.org>,
<wangkefeng.wang@...wei.com>, <zhangqilong3@...wei.com>,
<sunnanyong@...wei.com>
Subject: [PATCH] /dev/zero: try to align PMD_SIZE for private mapping
By default, THP are usually enabled. 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@...wei.com>
---
drivers/char/mem.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 48839958b0b1..c57327ca9dd6 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -515,10 +515,12 @@ static int mmap_zero(struct file *file, struct vm_area_struct *vma)
static unsigned long get_unmapped_area_zero(struct file *file,
unsigned long addr, unsigned long len,
unsigned long pgoff, unsigned long flags)
{
#ifdef CONFIG_MMU
+ unsigned long ret;
+
if (flags & MAP_SHARED) {
/*
* mmap_zero() will call shmem_zero_setup() to create a file,
* so use shmem's get_unmapped_area in case it can be huge;
* and pass NULL for file as in mmap.c's get_unmapped_area(),
@@ -526,10 +528,13 @@ static unsigned long get_unmapped_area_zero(struct file *file,
*/
return shmem_get_unmapped_area(NULL, addr, len, pgoff, flags);
}
/* Otherwise flags & MAP_PRIVATE: with no shmem object beneath it */
+ ret = thp_get_unmapped_area(file, addr, len, pgoff, flags);
+ if (ret)
+ return ret;
return mm_get_unmapped_area(current->mm, file, addr, len, pgoff, flags);
#else
return -ENOSYS;
#endif
}
--
2.43.0
Powered by blists - more mailing lists