From: Zi Yan <zi.yan@sent.com>
To: linux-mm@kvack.org, Matthew Wilcox <willy@infradead.org>
Cc: "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
Roman Gushchin <guro@fb.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
Yang Shi <shy828301@gmail.com>, Michal Hocko <mhocko@kernel.org>,
John Hubbard <jhubbard@nvidia.com>,
Ralph Campbell <rcampbell@nvidia.com>,
David Nellans <dnellans@nvidia.com>, Zi Yan <ziy@nvidia.com>
Subject: [RFC PATCH 6/6] mm: huge_memory: enable debugfs to split huge pages to any order.
Date: Wed, 11 Nov 2020 15:40:08 -0500 [thread overview]
Message-ID: <20201111204008.21332-7-zi.yan@sent.com> (raw)
In-Reply-To: <20201111204008.21332-1-zi.yan@sent.com>
From: Zi Yan <ziy@nvidia.com>
It is used to test split_huge_page_to_list_to_order for pagecache THPs.
Also add test cases for split_huge_page_to_list_to_order via both
debugfs and truncating a file.
Signed-off-by: Zi Yan <ziy@nvidia.com>
---
mm/huge_memory.c | 13 +--
.../selftests/vm/split_huge_page_test.c | 102 +++++++++++++++++-
2 files changed, 105 insertions(+), 10 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 88f50da40c9b..b7470607a08b 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2974,7 +2974,7 @@ static ssize_t split_huge_pages_in_range_pid_write(struct file *file,
static DEFINE_MUTEX(mutex);
ssize_t ret;
char input_buf[80]; /* hold pid, start_vaddr, end_vaddr */
- int pid;
+ int pid, to_order = 0;
unsigned long vaddr_start, vaddr_end, addr;
nodemask_t task_nodes;
struct mm_struct *mm;
@@ -2990,8 +2990,9 @@ static ssize_t split_huge_pages_in_range_pid_write(struct file *file,
goto out;
input_buf[80] = '\0';
- ret = sscanf(input_buf, "%d,%lx,%lx", &pid, &vaddr_start, &vaddr_end);
- if (ret != 3) {
+ ret = sscanf(input_buf, "%d,%lx,%lx,%d", &pid, &vaddr_start, &vaddr_end, &to_order);
+ /* cannot split to order-1 THP, which is not possible */
+ if ((ret != 3 && ret != 4) || to_order == 1) {
ret = -EINVAL;
goto out;
}
@@ -2999,8 +3000,8 @@ static ssize_t split_huge_pages_in_range_pid_write(struct file *file,
vaddr_end &= PAGE_MASK;
ret = strlen(input_buf);
- pr_debug("split huge pages in pid: %d, vaddr: [%lx - %lx]\n",
- pid, vaddr_start, vaddr_end);
+ pr_debug("split huge pages in pid: %d, vaddr: [%lx - %lx], to order: %d\n",
+ pid, vaddr_start, vaddr_end, to_order);
mm = find_mm_struct(pid, &task_nodes);
if (IS_ERR(mm)) {
@@ -3038,7 +3039,7 @@ static ssize_t split_huge_pages_in_range_pid_write(struct file *file,
addr += page_size(page) - PAGE_SIZE;
/* reset addr if split fails */
- if (split_huge_page(page))
+ if (split_huge_page_to_list_to_order(page, NULL, to_order))
addr -= (page_size(page) - PAGE_SIZE);
unlock_page(page);
diff --git a/tools/testing/selftests/vm/split_huge_page_test.c b/tools/testing/selftests/vm/split_huge_page_test.c
index c8a32ae9e13a..bcbc5a9d327c 100644
--- a/tools/testing/selftests/vm/split_huge_page_test.c
+++ b/tools/testing/selftests/vm/split_huge_page_test.c
@@ -16,6 +16,7 @@
#include <sys/wait.h>
#include <malloc.h>
#include <stdbool.h>
+#include <time.h>
#define PAGE_4KB (4096UL)
#define PAGE_2MB (512UL*PAGE_4KB)
@@ -31,6 +32,7 @@
#define SPLIT_DEBUGFS "/sys/kernel/debug/split_huge_pages_in_range_pid"
#define SMAP_PATH "/proc/self/smaps"
+#define THP_FS_PATH "/mnt/thp_fs"
#define INPUT_MAX 80
static int write_file(const char *path, const char *buf, size_t buflen)
@@ -50,13 +52,13 @@ static int write_file(const char *path, const char *buf, size_t buflen)
return (unsigned int) numwritten;
}
-static void write_debugfs(int pid, uint64_t vaddr_start, uint64_t vaddr_end)
+static void write_debugfs(int pid, uint64_t vaddr_start, uint64_t vaddr_end, int order)
{
char input[INPUT_MAX];
int ret;
- ret = snprintf(input, INPUT_MAX, "%d,%lx,%lx", pid, vaddr_start,
- vaddr_end);
+ ret = snprintf(input, INPUT_MAX, "%d,%lx,%lx,%d", pid, vaddr_start,
+ vaddr_end, order);
if (ret >= INPUT_MAX) {
printf("%s: Debugfs input is too long\n", __func__);
exit(EXIT_FAILURE);
@@ -139,7 +141,7 @@ void split_pmd_thp(void)
}
/* split all possible huge pages */
- write_debugfs(getpid(), (uint64_t)one_page, (uint64_t)one_page + len);
+ write_debugfs(getpid(), (uint64_t)one_page, (uint64_t)one_page + len, 0);
*one_page = 0;
@@ -153,9 +155,101 @@ void split_pmd_thp(void)
free(one_page);
}
+void create_pagecache_thp_and_fd(size_t fd_size, int *fd, char **addr)
+{
+ const char testfile[] = THP_FS_PATH "/test";
+ size_t i;
+ int dummy;
+
+ srand(time(NULL));
+
+ *fd = open(testfile, O_CREAT | O_RDWR, 0664);
+
+ for (i = 0; i < fd_size; i++) {
+ unsigned char byte = rand();
+
+ write(*fd, &byte, sizeof(byte));
+ }
+ close(*fd);
+ sync();
+ *fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
+ if (*fd == -1) {
+ perror("open drop_caches");
+ exit(EXIT_FAILURE);
+ }
+ if (write(*fd, "3", 1) != 1) {
+ perror("write to drop_caches");
+ exit(EXIT_FAILURE);
+ }
+ close(*fd);
+
+ *fd = open(testfile, O_RDWR);
+
+ *addr = mmap(NULL, fd_size, PROT_READ|PROT_WRITE, MAP_SHARED, *fd, 0);
+ if (*addr == (char *)-1) {
+ perror("cannot mmap");
+ exit(1);
+ }
+ madvise(*addr, fd_size, MADV_HUGEPAGE);
+
+ for (size_t i = 0; i < fd_size; i++)
+ dummy += *(*addr + i);
+}
+
+void split_thp_in_pagecache_to_order(int order)
+{
+ int fd;
+ char *addr;
+ size_t fd_size = 2 * PAGE_2MB, i;
+
+ create_pagecache_thp_and_fd(fd_size, &fd, &addr);
+
+ printf("split %ld kB pagecache page to order %d ... ", fd_size >> 10, order);
+ write_debugfs(getpid(), (uint64_t)addr, (uint64_t)addr + fd_size, order);
+
+ for (i = 0; i < fd_size; i++)
+ *(addr + i) = (char)i;
+
+ close(fd);
+ printf("done\n");
+}
+
+void truncate_thp_in_pagecache_to_order(int order)
+{
+ int fd;
+ char *addr;
+ size_t fd_size = 2 * PAGE_2MB, i;
+
+ create_pagecache_thp_and_fd(fd_size, &fd, &addr);
+
+ printf("truncate %ld kB pagecache page to size %lu kB ... ", fd_size >> 10, 4UL << order);
+ ftruncate(fd, PAGE_4KB << order);
+
+ for (i = 0; i < (PAGE_4KB << order); i++)
+ *(addr + i) = (char)i;
+
+ close(fd);
+ printf("done\n");
+}
+
int main(int argc, char **argv)
{
+ int i;
+
+ if (geteuid() != 0) {
+ printf("Please run the benchmark as root\n");
+ exit(EXIT_FAILURE);
+ }
+
split_pmd_thp();
+ for (i = 8; i >= 0; i--)
+ if (i != 1)
+ split_thp_in_pagecache_to_order(i);
+
+ for (i = 8; i >= 0; i--)
+ if (i != 1)
+ truncate_thp_in_pagecache_to_order(i);
+
return 0;
}
--
2.28.0
prev parent reply other threads:[~2020-11-11 20:40 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-11 20:40 [RFC PATCH 0/6] Split huge pages to any lower order pages Zi Yan
2020-11-11 20:40 ` [RFC PATCH 1/6] mm: huge_memory: add new debugfs interface to trigger split huge page on any page range Zi Yan
2020-11-12 22:22 ` Ralph Campbell
2020-11-12 22:38 ` Zi Yan
2020-11-16 16:06 ` Kirill A. Shutemov
2020-11-16 17:26 ` Zi Yan
2020-11-11 20:40 ` [RFC PATCH 2/6] mm: memcg: make memcg huge page split support any order split Zi Yan
2020-11-12 17:58 ` Ralph Campbell
2020-11-12 18:00 ` Zi Yan
2020-11-14 0:23 ` Roman Gushchin
2020-11-14 0:56 ` Zi Yan
2020-11-11 20:40 ` [RFC PATCH 3/6] mm: page_owner: add support for splitting to any order in split page_owner Zi Yan
2020-11-12 17:57 ` Ralph Campbell
2020-11-12 17:59 ` Zi Yan
2020-11-14 0:15 ` Roman Gushchin
2020-11-14 1:08 ` Zi Yan
2020-11-14 1:38 ` Roman Gushchin
2020-11-17 21:05 ` Matthew Wilcox
2020-11-17 21:12 ` Zi Yan
2020-11-17 21:22 ` Matthew Wilcox
2020-11-17 21:25 ` Zi Yan
2020-11-17 21:35 ` Roman Gushchin
2020-11-17 21:43 ` Matthew Wilcox
2020-11-16 16:25 ` Kirill A. Shutemov
2020-11-16 17:27 ` Zi Yan
2020-11-17 21:10 ` Matthew Wilcox
2020-11-17 21:13 ` Zi Yan
2020-11-11 20:40 ` [RFC PATCH 4/6] mm: thp: add support for split huge page to any lower order pages Zi Yan
2020-11-12 22:01 ` Ralph Campbell
2020-11-12 22:20 ` Zi Yan
2020-11-14 0:52 ` Roman Gushchin
2020-11-14 1:00 ` Zi Yan
2020-11-11 20:40 ` [RFC PATCH 5/6] mm: truncate: split thp to a non-zero order if possible Zi Yan
2020-11-12 22:08 ` Ralph Campbell
2020-11-12 22:37 ` Zi Yan
2020-11-11 20:40 ` Zi Yan [this message]
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=20201111204008.21332-7-zi.yan@sent.com \
--to=zi.yan@sent.com \
--cc=akpm@linux-foundation.org \
--cc=dnellans@nvidia.com \
--cc=guro@fb.com \
--cc=jhubbard@nvidia.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=rcampbell@nvidia.com \
--cc=shy828301@gmail.com \
--cc=willy@infradead.org \
--cc=ziy@nvidia.com \
/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