The patch titled Subject: mm-huge_memory-enable-debugfs-to-split-huge-pages-to-any-order-fix has been added to the -mm mm-unstable branch. Its filename is mm-huge_memory-enable-debugfs-to-split-huge-pages-to-any-order-fix.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-huge_memory-enable-debugfs-to-split-huge-pages-to-any-order-fix.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Zi Yan <ziy@xxxxxxxxxx> Subject: mm-huge_memory-enable-debugfs-to-split-huge-pages-to-any-order-fix Date: Mon, 04 Mar 2024 10:57:25 -0500 The error comes from that the opened test files are not munmapped and their file descriptors are not closed in the skip path. NFS creates .nfsXXX files for them, making the temp folder not empty. The attached patch cleans up properly and works on a NFS folder. Link: https://lkml.kernel.org/r/262E4DAA-4A78-4328-B745-1355AE356A07@xxxxxxxxxx Signed-off-by: Zi Yan <ziy@xxxxxxxxxx> Reported-by: Aishwarya TCV <aishwarya.tcv@xxxxxxx> Tested-by: Aishwarya TCV <aishwarya.tcv@xxxxxxx> Cc: David Hildenbrand <david@xxxxxxxxxx> Cc: Hugh Dickins <hughd@xxxxxxxxxx> Cc: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx> Cc: Luis Chamberlain <mcgrof@xxxxxxxxxx> Cc: "Matthew Wilcox (Oracle)" <willy@xxxxxxxxxxxxx> Cc: Michal Koutny <mkoutny@xxxxxxxx> Cc: Roman Gushchin <roman.gushchin@xxxxxxxxx> Cc: Ryan Roberts <ryan.roberts@xxxxxxx> Cc: Yang Shi <shy828301@xxxxxxxxx> Cc: Yu Zhao <yuzhao@xxxxxxxxxx> Cc: Zach O'Keefe <zokeefe@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- tools/testing/selftests/mm/run_vmtests.sh | 22 +++ tools/testing/selftests/mm/split_huge_page_test.c | 75 ++++++++++-- 2 files changed, 85 insertions(+), 12 deletions(-) --- a/tools/testing/selftests/mm/run_vmtests.sh~mm-huge_memory-enable-debugfs-to-split-huge-pages-to-any-order-fix +++ a/tools/testing/selftests/mm/run_vmtests.sh @@ -399,7 +399,27 @@ CATEGORY="thp" run_test ./khugepaged -s CATEGORY="thp" run_test ./transhuge-stress -d 20 -CATEGORY="thp" run_test ./split_huge_page_test +# Try to create XFS if not provided +if [ -z "${SPLIT_HUGE_PAGE_TEST_XFS_PATH}" ]; then + if test_selected "thp"; then + if grep xfs /proc/filesystems &>/dev/null; then + XFS_IMG=$(mktemp /tmp/xfs_img_XXXXXX) + SPLIT_HUGE_PAGE_TEST_XFS_PATH=$(mktemp -d /tmp/xfs_dir_XXXXXX) + truncate -s 314572800 ${XFS_IMG} + mkfs.xfs -q ${XFS_IMG} + mount -o loop ${XFS_IMG} ${SPLIT_HUGE_PAGE_TEST_XFS_PATH} + MOUNTED_XFS=1 + fi + fi +fi + +CATEGORY="thp" run_test ./split_huge_page_test ${SPLIT_HUGE_PAGE_TEST_XFS_PATH} + +if [ -n "${MOUNTED_XFS}" ]; then + umount ${SPLIT_HUGE_PAGE_TEST_XFS_PATH} + rmdir ${SPLIT_HUGE_PAGE_TEST_XFS_PATH} + rm -f ${XFS_IMG} +fi CATEGORY="migration" run_test ./migration --- a/tools/testing/selftests/mm/split_huge_page_test.c~mm-huge_memory-enable-debugfs-to-split-huge-pages-to-any-order-fix +++ a/tools/testing/selftests/mm/split_huge_page_test.c @@ -26,7 +26,6 @@ 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,%d" @@ -268,7 +267,37 @@ cleanup: ksft_exit_fail_msg("Error occurred\n"); } -void create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd, char **addr) +bool prepare_thp_fs(const char *xfs_path, char *thp_fs_template, + const char **thp_fs_loc) +{ + if (xfs_path) { + *thp_fs_loc = xfs_path; + return false; + } + + *thp_fs_loc = mkdtemp(thp_fs_template); + + if (!*thp_fs_loc) + ksft_exit_fail_msg("cannot create temp folder\n"); + + return true; +} + +void cleanup_thp_fs(const char *thp_fs_loc, bool created_tmp) +{ + int status; + + if (!created_tmp) + return; + + status = rmdir(thp_fs_loc); + if (status) + ksft_exit_fail_msg("cannot remove tmp dir: %s\n", + strerror(errno)); +} + +int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd, + char **addr) { size_t i; int dummy; @@ -277,7 +306,7 @@ void create_pagecache_thp_and_fd(const c *fd = open(testfile, O_CREAT | O_RDWR, 0664); if (*fd == -1) - ksft_exit_fail_msg("Failed to create a file at "THP_FS_PATH); + ksft_exit_fail_msg("Failed to create a file at %s\n", testfile); for (i = 0; i < fd_size; i++) { unsigned char byte = (unsigned char)i; @@ -299,7 +328,7 @@ void create_pagecache_thp_and_fd(const c *fd = open(testfile, O_RDWR); if (*fd == -1) { - ksft_perror("Failed to open a file at "THP_FS_PATH); + ksft_perror("Failed to open testfile\n"); goto err_out_unlink; } @@ -314,26 +343,39 @@ void create_pagecache_thp_and_fd(const c dummy += *(*addr + i); if (!check_huge_file(*addr, fd_size / pmd_pagesize, pmd_pagesize)) { - ksft_print_msg("No large pagecache folio generated, please mount a filesystem supporting large folio at "THP_FS_PATH"\n"); - goto err_out_close; + ksft_print_msg("No large pagecache folio generated, please provide a filesystem supporting large folio\n"); + munmap(*addr, fd_size); + close(*fd); + unlink(testfile); + ksft_test_result_skip("Pagecache folio split skipped\n"); + return -2; } - return; + return 0; err_out_close: close(*fd); err_out_unlink: unlink(testfile); ksft_exit_fail_msg("Failed to create large pagecache folios\n"); + return -1; } -void split_thp_in_pagecache_to_order(size_t fd_size, int order) +void split_thp_in_pagecache_to_order(size_t fd_size, int order, const char *fs_loc) { int fd; char *addr; size_t i; - const char testfile[] = THP_FS_PATH "/test"; + char testfile[INPUT_MAX]; int err = 0; - create_pagecache_thp_and_fd(testfile, fd_size, &fd, &addr); + err = snprintf(testfile, INPUT_MAX, "%s/test", fs_loc); + + if (err < 0) + ksft_exit_fail_msg("cannot generate right test file name\n"); + + err = create_pagecache_thp_and_fd(testfile, fd_size, &fd, &addr); + if (err) + return; + err = 0; write_debugfs(PID_FMT, getpid(), (uint64_t)addr, (uint64_t)addr + fd_size, order); @@ -351,6 +393,7 @@ void split_thp_in_pagecache_to_order(siz } out: + munmap(addr, fd_size); close(fd); unlink(testfile); if (err) @@ -362,6 +405,10 @@ int main(int argc, char **argv) { int i; size_t fd_size; + char *optional_xfs_path = NULL; + char fs_loc_template[] = "/tmp/thp_fs_XXXXXX"; + const char *fs_loc; + bool created_tmp; ksft_print_header(); @@ -370,6 +417,9 @@ int main(int argc, char **argv) ksft_finished(); } + if (argc > 1) + optional_xfs_path = argv[1]; + ksft_set_plan(3+9); pagesize = getpagesize(); @@ -384,8 +434,11 @@ int main(int argc, char **argv) split_pte_mapped_thp(); split_file_backed_thp(); + created_tmp = prepare_thp_fs(optional_xfs_path, fs_loc_template, + &fs_loc); for (i = 8; i >= 0; i--) - split_thp_in_pagecache_to_order(fd_size, i); + split_thp_in_pagecache_to_order(fd_size, i, fs_loc); + cleanup_thp_fs(fs_loc, created_tmp); ksft_finished(); _ Patches currently in -mm which might be from ziy@xxxxxxxxxx are mm-huge_memory-only-split-pmd-mapping-when-necessary-in-unmap_folio.patch mm-memcg-use-order-instead-of-nr-in-split_page_memcg.patch mm-page_owner-use-order-instead-of-nr-in-split_page_owner.patch mm-memcg-make-memcg-huge-page-split-support-any-order-split.patch mm-page_owner-add-support-for-splitting-to-any-order-in-split-page_owner.patch mm-thp-split-huge-page-to-any-lower-order-pages.patch mm-thp-split-huge-page-to-any-lower-order-pages-fix.patch mm-huge_memory-enable-debugfs-to-split-huge-pages-to-any-order.patch mm-huge_memory-enable-debugfs-to-split-huge-pages-to-any-order-fix.patch