From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org, zokeefe@google.com,
yuzhao@google.com, willy@infradead.org, shy828301@gmail.com,
ryan.roberts@arm.com, roman.gushchin@linux.dev, mkoutny@suse.com,
kirill.shutemov@linux.intel.com, ziy@nvidia.com,
akpm@linux-foundation.org
Subject: [to-be-updated] mm-huge_memory-enable-debugfs-to-split-huge-pages-to-any-order.patch removed from -mm tree
Date: Sun, 16 Apr 2023 11:46:45 -0700 [thread overview]
Message-ID: <20230416184646.20F80C433D2@smtp.kernel.org> (raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 11586 bytes --]
The quilt patch titled
Subject: mm: huge_memory: enable debugfs to split huge pages to any order
has been removed from the -mm tree. Its filename was
mm-huge_memory-enable-debugfs-to-split-huge-pages-to-any-order.patch
This patch was dropped because an updated version will be merged
------------------------------------------------------
From: Zi Yan <ziy@nvidia.com>
Subject: mm: huge_memory: enable debugfs to split huge pages to any order
Date: Mon, 3 Apr 2023 16:18:39 -0400
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,
truncating a file, and punching holes in a file.
Link: https://lkml.kernel.org/r/20230403201839.4097845-8-zi.yan@sent.com
Signed-off-by: Zi Yan <ziy@nvidia.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Michal Koutný <mkoutny@suse.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Yang Shi <shy828301@gmail.com>
Cc: Yu Zhao <yuzhao@google.com>
Cc: Zach O'Keefe <zokeefe@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
mm/huge_memory.c | 34 +
tools/testing/selftests/mm/split_huge_page_test.c | 225 +++++++++++-
2 files changed, 242 insertions(+), 17 deletions(-)
--- a/mm/huge_memory.c~mm-huge_memory-enable-debugfs-to-split-huge-pages-to-any-order
+++ a/mm/huge_memory.c
@@ -3032,7 +3032,7 @@ static inline bool vma_not_suitable_for_
}
static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
- unsigned long vaddr_end)
+ unsigned long vaddr_end, unsigned int new_order)
{
int ret = 0;
struct task_struct *task;
@@ -3094,13 +3094,19 @@ static int split_huge_pages_pid(int pid,
goto next;
total++;
- if (!can_split_folio(page_folio(page), NULL))
+ /*
+ * For folios with private, split_huge_page_to_list_to_order()
+ * will try to drop it before split and then check if the folio
+ * can be split or not. So skip the check here.
+ */
+ if (!folio_test_private(page_folio(page)) &&
+ !can_split_folio(page_folio(page), NULL))
goto next;
if (!trylock_page(page))
goto next;
- if (!split_huge_page(page))
+ if (!split_huge_page_to_list_to_order(page, NULL, new_order))
split++;
unlock_page(page);
@@ -3118,7 +3124,7 @@ out:
}
static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start,
- pgoff_t off_end)
+ pgoff_t off_end, unsigned int new_order)
{
struct filename *file;
struct file *candidate;
@@ -3157,7 +3163,7 @@ static int split_huge_pages_in_file(cons
if (!folio_trylock(folio))
goto next;
- if (!split_folio(folio))
+ if (!split_huge_page_to_list_to_order(&folio->page, NULL, new_order))
split++;
folio_unlock(folio);
@@ -3182,10 +3188,14 @@ static ssize_t split_huge_pages_write(st
{
static DEFINE_MUTEX(split_debug_mutex);
ssize_t ret;
- /* hold pid, start_vaddr, end_vaddr or file_path, off_start, off_end */
+ /*
+ * hold pid, start_vaddr, end_vaddr, new_order or
+ * file_path, off_start, off_end, new_order
+ */
char input_buf[MAX_INPUT_BUF_SZ];
int pid;
unsigned long vaddr_start, vaddr_end;
+ unsigned int new_order = 0;
ret = mutex_lock_interruptible(&split_debug_mutex);
if (ret)
@@ -3214,29 +3224,29 @@ static ssize_t split_huge_pages_write(st
goto out;
}
- ret = sscanf(buf, "0x%lx,0x%lx", &off_start, &off_end);
- if (ret != 2) {
+ ret = sscanf(buf, "0x%lx,0x%lx,%d", &off_start, &off_end, &new_order);
+ if (ret != 2 && ret != 3) {
ret = -EINVAL;
goto out;
}
- ret = split_huge_pages_in_file(file_path, off_start, off_end);
+ ret = split_huge_pages_in_file(file_path, off_start, off_end, new_order);
if (!ret)
ret = input_len;
goto out;
}
- ret = sscanf(input_buf, "%d,0x%lx,0x%lx", &pid, &vaddr_start, &vaddr_end);
+ ret = sscanf(input_buf, "%d,0x%lx,0x%lx,%d", &pid, &vaddr_start, &vaddr_end, &new_order);
if (ret == 1 && pid == 1) {
split_huge_pages_all();
ret = strlen(input_buf);
goto out;
- } else if (ret != 3) {
+ } else if (ret != 3 && ret != 4) {
ret = -EINVAL;
goto out;
}
- ret = split_huge_pages_pid(pid, vaddr_start, vaddr_end);
+ ret = split_huge_pages_pid(pid, vaddr_start, vaddr_end, new_order);
if (!ret)
ret = strlen(input_buf);
out:
--- a/tools/testing/selftests/mm/split_huge_page_test.c~mm-huge_memory-enable-debugfs-to-split-huge-pages-to-any-order
+++ a/tools/testing/selftests/mm/split_huge_page_test.c
@@ -16,6 +16,7 @@
#include <sys/mount.h>
#include <malloc.h>
#include <stdbool.h>
+#include <time.h>
#include "vm_util.h"
uint64_t pagesize;
@@ -23,10 +24,12 @@ unsigned int pageshift;
uint64_t pmd_pagesize;
#define SPLIT_DEBUGFS "/sys/kernel/debug/split_huge_pages"
+#define SMAP_PATH "/proc/self/smaps"
+#define THP_FS_PATH "/mnt/thp_fs"
#define INPUT_MAX 80
-#define PID_FMT "%d,0x%lx,0x%lx"
-#define PATH_FMT "%s,0x%lx,0x%lx"
+#define PID_FMT "%d,0x%lx,0x%lx,%d"
+#define PATH_FMT "%s,0x%lx,0x%lx,%d"
#define PFN_MASK ((1UL<<55)-1)
#define KPF_THP (1UL<<22)
@@ -113,7 +116,7 @@ void split_pmd_thp(void)
/* split all THPs */
write_debugfs(PID_FMT, getpid(), (uint64_t)one_page,
- (uint64_t)one_page + len);
+ (uint64_t)one_page + len, 0);
for (i = 0; i < len; i++)
if (one_page[i] != (char)i) {
@@ -203,7 +206,7 @@ void split_pte_mapped_thp(void)
/* split all remapped THPs */
write_debugfs(PID_FMT, getpid(), (uint64_t)pte_mapped,
- (uint64_t)pte_mapped + pagesize * 4);
+ (uint64_t)pte_mapped + pagesize * 4, 0);
/* smap does not show THPs after mremap, use kpageflags instead */
thp_size = 0;
@@ -269,7 +272,7 @@ void split_file_backed_thp(void)
}
/* split the file-backed THP */
- write_debugfs(PATH_FMT, testfile, pgoff_start, pgoff_end);
+ write_debugfs(PATH_FMT, testfile, pgoff_start, pgoff_end, 0);
status = unlink(testfile);
if (status)
@@ -290,20 +293,232 @@ cleanup:
printf("file-backed THP split test done, please check dmesg for more information\n");
}
+void create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd, char **addr)
+{
+ size_t i;
+ int dummy;
+
+ srand(time(NULL));
+
+ *fd = open(testfile, O_CREAT | O_RDWR, 0664);
+ if (*fd == -1) {
+ perror("Failed to create a file at "THP_FS_PATH);
+ exit(EXIT_FAILURE);
+ }
+
+ for (i = 0; i < fd_size; i++) {
+ unsigned char byte = (unsigned char)i;
+
+ write(*fd, &byte, sizeof(byte));
+ }
+ close(*fd);
+ sync();
+ *fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
+ if (*fd == -1) {
+ perror("open drop_caches");
+ goto err_out_unlink;
+ }
+ if (write(*fd, "3", 1) != 1) {
+ perror("write to drop_caches");
+ goto err_out_unlink;
+ }
+ close(*fd);
+
+ *fd = open(testfile, O_RDWR);
+ if (*fd == -1) {
+ perror("Failed to open a file at "THP_FS_PATH);
+ goto err_out_unlink;
+ }
+
+ *addr = mmap(NULL, fd_size, PROT_READ|PROT_WRITE, MAP_SHARED, *fd, 0);
+ if (*addr == (char *)-1) {
+ perror("cannot mmap");
+ goto err_out_close;
+ }
+ madvise(*addr, fd_size, MADV_HUGEPAGE);
+
+ for (size_t i = 0; i < fd_size; i++)
+ dummy += *(*addr + i);
+
+ if (!check_huge_file(*addr, fd_size / pmd_pagesize, pmd_pagesize)) {
+ printf("No pagecache THP generated, please mount a filesystem supporting pagecache THP at "THP_FS_PATH"\n");
+ goto err_out_close;
+ }
+ return;
+err_out_close:
+ close(*fd);
+err_out_unlink:
+ unlink(testfile);
+ exit(EXIT_FAILURE);
+}
+
+void split_thp_in_pagecache_to_order(size_t fd_size, int order)
+{
+ int fd;
+ char *addr;
+ size_t i;
+ const char testfile[] = THP_FS_PATH "/test";
+ int err = 0;
+
+ create_pagecache_thp_and_fd(testfile, fd_size, &fd, &addr);
+
+ printf("split %ld kB PMD-mapped pagecache page to order %d ... ", fd_size >> 10, order);
+ write_debugfs(PID_FMT, getpid(), (uint64_t)addr, (uint64_t)addr + fd_size, order);
+
+ for (i = 0; i < fd_size; i++)
+ if (*(addr + i) != (char)i) {
+ printf("%lu byte corrupted in the file\n", i);
+ err = EXIT_FAILURE;
+ goto out;
+ }
+
+ if (!check_huge_file(addr, 0, pmd_pagesize)) {
+ printf("Still FilePmdMapped not split\n");
+ err = EXIT_FAILURE;
+ goto out;
+ }
+
+ printf("done\n");
+out:
+ close(fd);
+ unlink(testfile);
+ if (err)
+ exit(err);
+}
+
+void truncate_thp_in_pagecache_to_order(size_t fd_size, int order)
+{
+ int fd;
+ char *addr;
+ size_t i;
+ const char testfile[] = THP_FS_PATH "/test";
+ int err = 0;
+
+ create_pagecache_thp_and_fd(testfile, fd_size, &fd, &addr);
+
+ printf("truncate %ld kB PMD-mapped pagecache page to size %lu kB ... ",
+ fd_size >> 10, 4UL << order);
+ ftruncate(fd, pagesize << order);
+
+ for (i = 0; i < (pagesize << order); i++)
+ if (*(addr + i) != (char)i) {
+ printf("%lu byte corrupted in the file\n", i);
+ err = EXIT_FAILURE;
+ goto out;
+ }
+
+ if (!check_huge_file(addr, 0, pmd_pagesize)) {
+ printf("Still FilePmdMapped not split after truncate\n");
+ err = EXIT_FAILURE;
+ goto out;
+ }
+
+ printf("done\n");
+out:
+ close(fd);
+ unlink(testfile);
+ if (err)
+ exit(err);
+}
+
+void punch_hole_in_pagecache_thp(size_t fd_size, off_t offset[], off_t len[],
+ int n, int num_left_thps)
+{
+ int fd, j;
+ char *addr;
+ size_t i;
+ const char testfile[] = THP_FS_PATH "/test";
+ int err = 0;
+
+ create_pagecache_thp_and_fd(testfile, fd_size, &fd, &addr);
+
+ for (j = 0; j < n; j++) {
+ printf("punch a hole to %ld kB PMD-mapped pagecache page at addr: %lx, offset %ld, and len %ld ...\n",
+ fd_size >> 10, (unsigned long)addr, offset[j], len[j]);
+ fallocate(fd, FALLOC_FL_PUNCH_HOLE|FALLOC_FL_KEEP_SIZE, offset[j], len[j]);
+ }
+
+ for (i = 0; i < fd_size; i++) {
+ int in_hole = 0;
+
+ for (j = 0; j < n; j++)
+ if (i >= offset[j] && i < (offset[j] + len[j])) {
+ in_hole = 1;
+ break;
+ }
+
+ if (in_hole) {
+ if (*(addr + i)) {
+ printf("%lu byte non-zero after punch\n", i);
+ err = EXIT_FAILURE;
+ goto out;
+ }
+ continue;
+ }
+ if (*(addr + i) != (char)i) {
+ printf("%lu byte corrupted in the file\n", i);
+ err = EXIT_FAILURE;
+ goto out;
+ }
+ }
+
+ if (!check_huge_file(addr, num_left_thps, pmd_pagesize)) {
+ printf("Still FilePmdMapped not split after punch\n");
+ goto out;
+ }
+ printf("done\n");
+out:
+ close(fd);
+ unlink(testfile);
+ if (err)
+ exit(err);
+}
+
int main(int argc, char **argv)
{
+ int i;
+ size_t fd_size;
+ off_t offset[2], len[2];
+
if (geteuid() != 0) {
printf("Please run the benchmark as root\n");
exit(EXIT_FAILURE);
}
+ setbuf(stdout, NULL);
+
pagesize = getpagesize();
pageshift = ffs(pagesize) - 1;
pmd_pagesize = read_pmd_pagesize();
+ fd_size = 2 * pmd_pagesize;
split_pmd_thp();
split_pte_mapped_thp();
split_file_backed_thp();
+ for (i = 8; i >= 0; i--)
+ if (i != 1)
+ split_thp_in_pagecache_to_order(fd_size, i);
+
+ /*
+ * for i is 1, truncate code in the kernel should create order-0 pages
+ * instead of order-1 THPs, since order-1 THP is not supported. No error
+ * is expected.
+ */
+ for (i = 8; i >= 0; i--)
+ truncate_thp_in_pagecache_to_order(fd_size, i);
+
+ offset[0] = 123;
+ offset[1] = 4 * pagesize;
+ len[0] = 200 * pagesize;
+ len[1] = 16 * pagesize;
+ punch_hole_in_pagecache_thp(fd_size, offset, len, 2, 1);
+
+ offset[0] = 259 * pagesize + pagesize / 2;
+ offset[1] = 33 * pagesize;
+ len[0] = 129 * pagesize;
+ len[1] = 16 * pagesize;
+ punch_hole_in_pagecache_thp(fd_size, offset, len, 2, 1);
+
return 0;
}
_
Patches currently in -mm which might be from ziy@nvidia.com are
reply other threads:[~2023-04-16 18:46 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230416184646.20F80C433D2@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mkoutny@suse.com \
--cc=mm-commits@vger.kernel.org \
--cc=roman.gushchin@linux.dev \
--cc=ryan.roberts@arm.com \
--cc=shy828301@gmail.com \
--cc=willy@infradead.org \
--cc=yuzhao@google.com \
--cc=ziy@nvidia.com \
--cc=zokeefe@google.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 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.