* [PATCH v2 0/5] selftests/mm: skip several tests when thp is not available
@ 2026-03-16 4:43 Chunyu Hu
2026-03-16 4:43 ` [PATCH v2 1/5] selftests/mm/guard-regions: skip collapse test when thp not enabled Chunyu Hu
` (4 more replies)
0 siblings, 5 replies; 15+ messages in thread
From: Chunyu Hu @ 2026-03-16 4:43 UTC (permalink / raw)
To: akpm, david, shuah, linux-mm, ljs
Cc: linux-kselftest, linux-kernel, lorenzo.stoakes, Liam.Howlett,
vbabka, rppt, surenb, mhocko, ziy, baolin.wang, npache,
ryan.roberts, dev.jain, baohua, lance.yang, chuhu
There are several tests requires transprarent hugepages, when run on thp
disabled kernel such as realtime kernel, there will be false negative.
Mark those tests as skip when thp is not available.
Changes in v2:
- replace 'false postive' with 'false negative' in cover letter
- patch 1 and patch 2 add reviewed-by/acked-by
- new patch 3 to add write_file() in vm_util as a common helper
- patch 4 removed the {} in if block, removed the write_file helper
rename chunk in v1. Add reviewed-by
- patch 5 move the exit chunk to the front of ksft_print_headers() as
suggested by David. Add review by.
Chunyu Hu (5):
selftests/mm/guard-regions: skip collapse test when thp not enabled
selftests/mm: soft-dirty: skip two tests when thp is not available
selftests/mm: move write_file helper to vm_util
selftests/mm: split_huge_page_test: skip the test when thp is not
available
selftests/mm: transhuge_stress: skip the test when thp not available
tools/testing/selftests/mm/guard-regions.c | 4 ++++
tools/testing/selftests/mm/soft-dirty.c | 4 +++-
.../selftests/mm/split_huge_page_test.c | 19 ++++-----------
tools/testing/selftests/mm/thp_settings.c | 24 +------------------
tools/testing/selftests/mm/thp_settings.h | 1 -
tools/testing/selftests/mm/transhuge-stress.c | 4 ++++
tools/testing/selftests/mm/vm_util.c | 16 +++++++++++++
tools/testing/selftests/mm/vm_util.h | 2 ++
8 files changed, 34 insertions(+), 40 deletions(-)
base-commit: f338e77383789c0cae23ca3d48adcc5e9e137e3c
--
2.53.0
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 1/5] selftests/mm/guard-regions: skip collapse test when thp not enabled
2026-03-16 4:43 [PATCH v2 0/5] selftests/mm: skip several tests when thp is not available Chunyu Hu
@ 2026-03-16 4:43 ` Chunyu Hu
2026-03-16 6:18 ` Mike Rapoport
2026-03-16 4:43 ` [PATCH v2 2/5] selftests/mm: soft-dirty: skip two tests when thp is not available Chunyu Hu
` (3 subsequent siblings)
4 siblings, 1 reply; 15+ messages in thread
From: Chunyu Hu @ 2026-03-16 4:43 UTC (permalink / raw)
To: akpm, david, shuah, linux-mm, ljs
Cc: linux-kselftest, linux-kernel, lorenzo.stoakes, Liam.Howlett,
vbabka, rppt, surenb, mhocko, ziy, baolin.wang, npache,
ryan.roberts, dev.jain, baohua, lance.yang, chuhu, Li Wang
When thp is not available, just skip the collape tests to avoid the false
positive.
Without the change, run with a thp disabled kernel:
./run_vmtests.sh -t madv_guard
<snip/>
# # RUN guard_regions.file.multi_vma ...
# # OK guard_regions.file.multi_vma
# ok 89 guard_regions.file.multi_vma
# # RUN guard_regions.file.basic ...
# # OK guard_regions.file.basic
# ok 90 guard_regions.file.basic
# # FAILED: 87 / 90 tests passed.
# # 17 skipped test(s) detected. Consider enabling relevant config options to improve coverage.
# # Totals: pass:70 fail:3 xfail:0 xpass:0 skip:17 error:0
# [FAIL]
not ok 1 guard-regions # exit=1
hwpoison_inject
# SUMMARY: PASS=0 SKIP=0 FAIL=1
With this change, run with thp disabled kernel:
./run_vmtests.sh -t madv_guard
<snip/>
# ok 90 guard_regions.file.basic
# # PASSED: 90 / 90 tests passed.
# # 20 skipped test(s) detected. Consider enabling relevant config options to improve coverage.
# # Totals: pass:70 fail:0 xfail:0 xpass:0 skip:20 error:0
# [PASS]
ok 1 guard-regions
hwpoison_inject
# SUMMARY: PASS=1 SKIP=0 FAIL=0
1..1
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Zi Yan <ziy@nvidia.com>
CC: Li Wang <liwang@redhat.com>
Signed-off-by: Chunyu Hu <chuhu@redhat.com>
---
Changes in v2:
- add reviewed by from Zi and Lorenzo
- add acked-by from David
---
tools/testing/selftests/mm/guard-regions.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/testing/selftests/mm/guard-regions.c b/tools/testing/selftests/mm/guard-regions.c
index dbd21d66d383..897af9c512f9 100644
--- a/tools/testing/selftests/mm/guard-regions.c
+++ b/tools/testing/selftests/mm/guard-regions.c
@@ -21,6 +21,7 @@
#include <sys/uio.h>
#include <unistd.h>
#include "vm_util.h"
+#include "thp_settings.h"
#include "../pidfd/pidfd.h"
@@ -2195,6 +2196,9 @@ TEST_F(guard_regions, collapse)
char *ptr;
int i;
+ if (!thp_is_enabled())
+ SKIP(return, "Transparent Hugepages not available\n");
+
/* Need file to be correct size for tests for non-anon. */
if (variant->backing != ANON_BACKED)
ASSERT_EQ(ftruncate(self->fd, size), 0);
base-commit: f338e77383789c0cae23ca3d48adcc5e9e137e3c
--
2.53.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 2/5] selftests/mm: soft-dirty: skip two tests when thp is not available
2026-03-16 4:43 [PATCH v2 0/5] selftests/mm: skip several tests when thp is not available Chunyu Hu
2026-03-16 4:43 ` [PATCH v2 1/5] selftests/mm/guard-regions: skip collapse test when thp not enabled Chunyu Hu
@ 2026-03-16 4:43 ` Chunyu Hu
2026-03-16 6:25 ` Mike Rapoport
2026-03-16 4:43 ` [PATCH v2 3/5] selftests/mm: move write_file helper to vm_util Chunyu Hu
` (2 subsequent siblings)
4 siblings, 1 reply; 15+ messages in thread
From: Chunyu Hu @ 2026-03-16 4:43 UTC (permalink / raw)
To: akpm, david, shuah, linux-mm, ljs
Cc: linux-kselftest, linux-kernel, lorenzo.stoakes, Liam.Howlett,
vbabka, rppt, surenb, mhocko, ziy, baolin.wang, npache,
ryan.roberts, dev.jain, baohua, lance.yang, chuhu, Li Wang
The test_hugepage test contain two sub tests. If just reporting one skip
when thp not available, there will be error in the log because the test
count don't match the test plan. Change to skip two tests by running the
ksft_test_result_skip twice in this case.
Without the fix (run test on thp disabled kernel):
./run_vmtests.sh -t soft_dirty
# --------------------
# running ./soft-dirty
# --------------------
# TAP version 13
# 1..19
# ok 1 Test test_simple
# ok 2 Test test_vma_reuse dirty bit of allocated page
# ok 3 Test test_vma_reuse dirty bit of reused address page
# ok 4 # SKIP Transparent Hugepages not available
# ok 5 Test test_mprotect-anon dirty bit of new written page
# ok 6 Test test_mprotect-anon soft-dirty clear after clear_refs
# ok 7 Test test_mprotect-anon soft-dirty clear after marking RO
# ok 8 Test test_mprotect-anon soft-dirty clear after marking RW
# ok 9 Test test_mprotect-anon soft-dirty after rewritten
# ok 10 Test test_mprotect-file dirty bit of new written page
# ok 11 Test test_mprotect-file soft-dirty clear after clear_refs
# ok 12 Test test_mprotect-file soft-dirty clear after marking RO
# ok 13 Test test_mprotect-file soft-dirty clear after marking RW
# ok 14 Test test_mprotect-file soft-dirty after rewritten
# ok 15 Test test_merge-anon soft-dirty after remap merge 1st pg
# ok 16 Test test_merge-anon soft-dirty after remap merge 2nd pg
# ok 17 Test test_merge-anon soft-dirty after mprotect merge 1st pg
# ok 18 Test test_merge-anon soft-dirty after mprotect merge 2nd pg
# # 1 skipped test(s) detected. Consider enabling relevant config options to improve coverage.
# # Planned tests != run tests (19 != 18)
# # Totals: pass:17 fail:0 xfail:0 xpass:0 skip:1 error:0
# [FAIL]
not ok 52 soft-dirty # exit=1
With the fix (run test on thp disabled kernel):
./run_vmtests.sh -t soft_dirty
# --------------------
# running ./soft-dirty
# TAP version 13
# --------------------
# running ./soft-dirty
# --------------------
# TAP version 13
# 1..19
# ok 1 Test test_simple
# ok 2 Test test_vma_reuse dirty bit of allocated page
# ok 3 Test test_vma_reuse dirty bit of reused address page
# # Transparent Hugepages not available
# ok 4 # SKIP Test test_hugepage huge page allocation
# ok 5 # SKIP Test test_hugepage huge page dirty bit
# ok 6 Test test_mprotect-anon dirty bit of new written page
# ok 7 Test test_mprotect-anon soft-dirty clear after clear_refs
# ok 8 Test test_mprotect-anon soft-dirty clear after marking RO
# ok 9 Test test_mprotect-anon soft-dirty clear after marking RW
# ok 10 Test test_mprotect-anon soft-dirty after rewritten
# ok 11 Test test_mprotect-file dirty bit of new written page
# ok 12 Test test_mprotect-file soft-dirty clear after clear_refs
# ok 13 Test test_mprotect-file soft-dirty clear after marking RO
# ok 14 Test test_mprotect-file soft-dirty clear after marking RW
# ok 15 Test test_mprotect-file soft-dirty after rewritten
# ok 16 Test test_merge-anon soft-dirty after remap merge 1st pg
# ok 17 Test test_merge-anon soft-dirty after remap merge 2nd pg
# ok 18 Test test_merge-anon soft-dirty after mprotect merge 1st pg
# ok 19 Test test_merge-anon soft-dirty after mprotect merge 2nd pg
# # 2 skipped test(s) detected. Consider enabling relevant config options to improve coverage.
# # Totals: pass:17 fail:0 xfail:0 xpass:0 skip:2 error:0
# [PASS]
ok 1 soft-dirty
hwpoison_inject
# SUMMARY: PASS=1 SKIP=0 FAIL=0
1..1
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Zi Yan <ziy@nvidia.com>
CC: Li Wang <liwang@redhat.com>
Signed-off-by: Chunyu Hu <chuhu@redhat.com>
---
Changes in v2:
- add reviewed by from Lorenzo and Zi
- add acked-by from David
---
tools/testing/selftests/mm/soft-dirty.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/soft-dirty.c b/tools/testing/selftests/mm/soft-dirty.c
index 59c0dbe99a9b..bcfcac99b436 100644
--- a/tools/testing/selftests/mm/soft-dirty.c
+++ b/tools/testing/selftests/mm/soft-dirty.c
@@ -82,7 +82,9 @@ static void test_hugepage(int pagemap_fd, int pagesize)
int i, ret;
if (!thp_is_enabled()) {
- ksft_test_result_skip("Transparent Hugepages not available\n");
+ ksft_print_msg("Transparent Hugepages not available\n");
+ ksft_test_result_skip("Test %s huge page allocation\n", __func__);
+ ksft_test_result_skip("Test %s huge page dirty bit\n", __func__);
return;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 3/5] selftests/mm: move write_file helper to vm_util
2026-03-16 4:43 [PATCH v2 0/5] selftests/mm: skip several tests when thp is not available Chunyu Hu
2026-03-16 4:43 ` [PATCH v2 1/5] selftests/mm/guard-regions: skip collapse test when thp not enabled Chunyu Hu
2026-03-16 4:43 ` [PATCH v2 2/5] selftests/mm: soft-dirty: skip two tests when thp is not available Chunyu Hu
@ 2026-03-16 4:43 ` Chunyu Hu
2026-03-16 6:35 ` Mike Rapoport
2026-03-16 4:43 ` [PATCH v2 4/5] selftests/mm: split_huge_page_test: skip the test when thp is not available Chunyu Hu
2026-03-16 4:43 ` [PATCH v2 5/5] selftests/mm: transhuge_stress: skip the test when thp " Chunyu Hu
4 siblings, 1 reply; 15+ messages in thread
From: Chunyu Hu @ 2026-03-16 4:43 UTC (permalink / raw)
To: akpm, david, shuah, linux-mm, ljs
Cc: linux-kselftest, linux-kernel, lorenzo.stoakes, Liam.Howlett,
vbabka, rppt, surenb, mhocko, ziy, baolin.wang, npache,
ryan.roberts, dev.jain, baohua, lance.yang, chuhu
thp_settings provides write_file() helper for safely writing to a file and
exit when write failure happens. It's a very low level helper and many sub
tests need such a helper, not only thp tests.
split_huge_page_test also defines a write_file locally. The two have minior
differences in return type and used exit api. And there would be conflicts
if split_huge_page_test wanted to include thp_settings.h because of
different prototype, making it less convenient.
It's possisble to merge the two, although some tests don't use the
kselftest infrastrucutre for testing. It would also work when using the
ksft_exit_msg() to exit in my test, as the counters are all zero. Output
will be like:
TAP version 13
1..62
Bail out! /proc/sys/vm/drop_caches1 open failed: No such file or directory
# Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
So here just leave one version of write_file, and move it into the vm_util.
This make it easy to maitain and user could just include one vm_util.h when
then don't need thp setting helpers. Keep the prototype of returning the
written bytes num.
Suggested-by: Mike Rapoport <rppt@kernel.org>
Signed-off-by: Chunyu Hu <chuhu@redhat.com>
---
Changes in v2:
new patch from v2
---
.../selftests/mm/split_huge_page_test.c | 15 ------------
tools/testing/selftests/mm/thp_settings.c | 24 +------------------
tools/testing/selftests/mm/thp_settings.h | 1 -
tools/testing/selftests/mm/vm_util.c | 16 +++++++++++++
tools/testing/selftests/mm/vm_util.h | 2 ++
5 files changed, 19 insertions(+), 39 deletions(-)
diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
index e0167111bdd1..93f205327b84 100644
--- a/tools/testing/selftests/mm/split_huge_page_test.c
+++ b/tools/testing/selftests/mm/split_huge_page_test.c
@@ -255,21 +255,6 @@ static int check_after_split_folio_orders(char *vaddr_start, size_t len,
return status;
}
-static void write_file(const char *path, const char *buf, size_t buflen)
-{
- int fd;
- ssize_t numwritten;
-
- fd = open(path, O_WRONLY);
- if (fd == -1)
- ksft_exit_fail_msg("%s open failed: %s\n", path, strerror(errno));
-
- numwritten = write(fd, buf, buflen - 1);
- close(fd);
- if (numwritten < 1)
- ksft_exit_fail_msg("Write failed\n");
-}
-
static void write_debugfs(const char *fmt, ...)
{
char input[INPUT_MAX];
diff --git a/tools/testing/selftests/mm/thp_settings.c b/tools/testing/selftests/mm/thp_settings.c
index 574bd0f8ae48..02de28ecf31a 100644
--- a/tools/testing/selftests/mm/thp_settings.c
+++ b/tools/testing/selftests/mm/thp_settings.c
@@ -6,6 +6,7 @@
#include <string.h>
#include <unistd.h>
+#include "vm_util.h"
#include "thp_settings.h"
#define THP_SYSFS "/sys/kernel/mm/transparent_hugepage/"
@@ -64,29 +65,6 @@ int read_file(const char *path, char *buf, size_t buflen)
return (unsigned int) numread;
}
-int write_file(const char *path, const char *buf, size_t buflen)
-{
- int fd;
- ssize_t numwritten;
-
- fd = open(path, O_WRONLY);
- if (fd == -1) {
- printf("open(%s)\n", path);
- exit(EXIT_FAILURE);
- return 0;
- }
-
- numwritten = write(fd, buf, buflen - 1);
- close(fd);
- if (numwritten < 1) {
- printf("write(%s)\n", buf);
- exit(EXIT_FAILURE);
- return 0;
- }
-
- return (unsigned int) numwritten;
-}
-
unsigned long read_num(const char *path)
{
char buf[21];
diff --git a/tools/testing/selftests/mm/thp_settings.h b/tools/testing/selftests/mm/thp_settings.h
index 76eeb712e5f1..7748a9009191 100644
--- a/tools/testing/selftests/mm/thp_settings.h
+++ b/tools/testing/selftests/mm/thp_settings.h
@@ -63,7 +63,6 @@ struct thp_settings {
};
int read_file(const char *path, char *buf, size_t buflen);
-int write_file(const char *path, const char *buf, size_t buflen);
unsigned long read_num(const char *path);
void write_num(const char *path, unsigned long num);
diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c
index a6d4ff7dfdc0..b4b3b48f8dc9 100644
--- a/tools/testing/selftests/mm/vm_util.c
+++ b/tools/testing/selftests/mm/vm_util.c
@@ -764,3 +764,19 @@ int unpoison_memory(unsigned long pfn)
return ret > 0 ? 0 : -errno;
}
+
+unsigned int write_file(const char *path, const char *buf, size_t buflen)
+{
+ int fd;
+ ssize_t numwritten;
+
+ fd = open(path, O_WRONLY);
+ if (fd == -1)
+ ksft_exit_fail_msg("%s open failed: %s\n", path, strerror(errno));
+
+ numwritten = write(fd, buf, buflen - 1);
+ close(fd);
+ if (numwritten < 1)
+ ksft_exit_fail_msg("Write failed\n");
+ return (unsigned int) numwritten;
+}
diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h
index e9c4e24769c1..22c8805e0d7a 100644
--- a/tools/testing/selftests/mm/vm_util.h
+++ b/tools/testing/selftests/mm/vm_util.h
@@ -166,3 +166,5 @@ int unpoison_memory(unsigned long pfn);
#define PAGEMAP_PRESENT(ent) (((ent) & (1ull << 63)) != 0)
#define PAGEMAP_PFN(ent) ((ent) & ((1ull << 55) - 1))
+
+unsigned int write_file(const char *path, const char *buf, size_t buflen);
--
2.53.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 4/5] selftests/mm: split_huge_page_test: skip the test when thp is not available
2026-03-16 4:43 [PATCH v2 0/5] selftests/mm: skip several tests when thp is not available Chunyu Hu
` (2 preceding siblings ...)
2026-03-16 4:43 ` [PATCH v2 3/5] selftests/mm: move write_file helper to vm_util Chunyu Hu
@ 2026-03-16 4:43 ` Chunyu Hu
2026-03-16 6:29 ` Mike Rapoport
2026-03-16 14:10 ` David Hildenbrand (Arm)
2026-03-16 4:43 ` [PATCH v2 5/5] selftests/mm: transhuge_stress: skip the test when thp " Chunyu Hu
4 siblings, 2 replies; 15+ messages in thread
From: Chunyu Hu @ 2026-03-16 4:43 UTC (permalink / raw)
To: akpm, david, shuah, linux-mm, ljs
Cc: linux-kselftest, linux-kernel, lorenzo.stoakes, Liam.Howlett,
vbabka, rppt, surenb, mhocko, ziy, baolin.wang, npache,
ryan.roberts, dev.jain, baohua, lance.yang, chuhu, Li Wang
When thp is not enabled on some kernel config such as realtime kernel, the
test will report failure. Fix the false positive by skipping the test
directly when thp is not enabled.
Tested with thp disabled kernel:
Before The fix:
# --------------------------------------------------
# running ./split_huge_page_test /tmp/xfs_dir_Ywup9p
# --------------------------------------------------
# TAP version 13
# Bail out! Reading PMD pagesize failed
# # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
# [FAIL]
not ok 61 split_huge_page_test /tmp/xfs_dir_Ywup9p # exit=1
After the fix:
# --------------------------------------------------
# running ./split_huge_page_test /tmp/xfs_dir_YHPUPl
# --------------------------------------------------
# TAP version 13
# 1..0 # SKIP Transparent Hugepages not available
# [SKIP]
ok 6 split_huge_page_test /tmp/xfs_dir_YHPUPl # SKIP
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Reviewed-by: Zi Yan <ziy@nvidia.com>
CC: Li Wang <liwang@redhat.com>
Signed-off-by: Chunyu Hu <chuhu@redhat.com>
---
V2 changes:
- removed the {} in if block
- removed the write_file helper rename chunk, as there's a new patch 3 to
resolve the conflict with thp_settings.h by moving it to vm_util.
- Add reviewed by from Zi and Lorenzo
---
tools/testing/selftests/mm/split_huge_page_test.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
index 93f205327b84..500d07c4938b 100644
--- a/tools/testing/selftests/mm/split_huge_page_test.c
+++ b/tools/testing/selftests/mm/split_huge_page_test.c
@@ -21,6 +21,7 @@
#include <time.h>
#include "vm_util.h"
#include "kselftest.h"
+#include "thp_settings.h"
uint64_t pagesize;
unsigned int pageshift;
@@ -757,6 +758,9 @@ int main(int argc, char **argv)
ksft_finished();
}
+ if (!thp_is_enabled())
+ ksft_exit_skip("Transparent Hugepages not available\n");
+
if (argc > 1)
optional_xfs_path = argv[1];
--
2.53.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 5/5] selftests/mm: transhuge_stress: skip the test when thp not available
2026-03-16 4:43 [PATCH v2 0/5] selftests/mm: skip several tests when thp is not available Chunyu Hu
` (3 preceding siblings ...)
2026-03-16 4:43 ` [PATCH v2 4/5] selftests/mm: split_huge_page_test: skip the test when thp is not available Chunyu Hu
@ 2026-03-16 4:43 ` Chunyu Hu
2026-03-16 6:30 ` Mike Rapoport
2026-03-16 14:11 ` David Hildenbrand (Arm)
4 siblings, 2 replies; 15+ messages in thread
From: Chunyu Hu @ 2026-03-16 4:43 UTC (permalink / raw)
To: akpm, david, shuah, linux-mm, ljs
Cc: linux-kselftest, linux-kernel, lorenzo.stoakes, Liam.Howlett,
vbabka, rppt, surenb, mhocko, ziy, baolin.wang, npache,
ryan.roberts, dev.jain, baohua, lance.yang, chuhu, Li Wang
The test requires thp, skip the test when thp is not available to avoid
false positive.
Tested with thp disabled kernel.
Before the fix:
# --------------------------------
# running ./transhuge-stress -d 20
# --------------------------------
# TAP version 13
# 1..1
# transhuge-stress: allocate 1453 transhuge pages, using 2907 MiB virtual memory and 11 MiB of ram
# Bail out! MADV_HUGEPAGE# Planned tests != run tests (1 != 0)
# # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
# [FAIL]
not ok 60 transhuge-stress -d 20 # exit=1
After the fix:
# --------------------------------
# running ./transhuge-stress -d 20
# --------------------------------
# TAP version 13
# 1..0 # SKIP Transparent Hugepages not available
# [SKIP]
ok 5 transhuge-stress -d 20 # SKIP
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Reviewed-by: Zi Yan <ziy@nvidia.com>
CC: Li Wang <liwang@redhat.com>
Signed-off-by: Chunyu Hu <chuhu@redhat.com>
---
V2 changes:
- Move the exit chunk to the front of ksft_print_headers() as suggested
by David.
- Add reviewed by from Zi and Lorenzo
---
tools/testing/selftests/mm/transhuge-stress.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/testing/selftests/mm/transhuge-stress.c b/tools/testing/selftests/mm/transhuge-stress.c
index bcad47c09518..7a9f1035099b 100644
--- a/tools/testing/selftests/mm/transhuge-stress.c
+++ b/tools/testing/selftests/mm/transhuge-stress.c
@@ -17,6 +17,7 @@
#include <sys/mman.h>
#include "vm_util.h"
#include "kselftest.h"
+#include "thp_settings.h"
int backing_fd = -1;
int mmap_flags = MAP_ANONYMOUS | MAP_NORESERVE | MAP_PRIVATE;
@@ -37,6 +38,9 @@ int main(int argc, char **argv)
ksft_print_header();
+ if (!thp_is_enabled())
+ ksft_exit_skip("Transparent Hugepages not available\n");
+
ram = sysconf(_SC_PHYS_PAGES);
if (ram > SIZE_MAX / psize() / 4)
ram = SIZE_MAX / 4;
--
2.53.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/5] selftests/mm/guard-regions: skip collapse test when thp not enabled
2026-03-16 4:43 ` [PATCH v2 1/5] selftests/mm/guard-regions: skip collapse test when thp not enabled Chunyu Hu
@ 2026-03-16 6:18 ` Mike Rapoport
2026-03-17 6:51 ` Chunyu Hu
0 siblings, 1 reply; 15+ messages in thread
From: Mike Rapoport @ 2026-03-16 6:18 UTC (permalink / raw)
To: Chunyu Hu
Cc: akpm, david, shuah, linux-mm, ljs, linux-kselftest, linux-kernel,
lorenzo.stoakes, Liam.Howlett, vbabka, surenb, mhocko, ziy,
baolin.wang, npache, ryan.roberts, dev.jain, baohua, lance.yang,
Li Wang
On Mon, Mar 16, 2026 at 12:43:31PM +0800, Chunyu Hu wrote:
> When thp is not available, just skip the collape tests to avoid the false
> positive.
... to avoid the false negative
> Without the change, run with a thp disabled kernel:
> ./run_vmtests.sh -t madv_guard
> <snip/>
> # # RUN guard_regions.file.multi_vma ...
> # # OK guard_regions.file.multi_vma
> # ok 89 guard_regions.file.multi_vma
> # # RUN guard_regions.file.basic ...
> # # OK guard_regions.file.basic
> # ok 90 guard_regions.file.basic
It would be useful to include output of two failing THP tests rather
then just the output of the last two test.
You can also add '-n' option to run_vmtest.sh to reduce amount of leading
#, but for that I don't feel strongly.
With that updated
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 2/5] selftests/mm: soft-dirty: skip two tests when thp is not available
2026-03-16 4:43 ` [PATCH v2 2/5] selftests/mm: soft-dirty: skip two tests when thp is not available Chunyu Hu
@ 2026-03-16 6:25 ` Mike Rapoport
0 siblings, 0 replies; 15+ messages in thread
From: Mike Rapoport @ 2026-03-16 6:25 UTC (permalink / raw)
To: Chunyu Hu
Cc: akpm, david, shuah, linux-mm, ljs, linux-kselftest, linux-kernel,
lorenzo.stoakes, Liam.Howlett, vbabka, surenb, mhocko, ziy,
baolin.wang, npache, ryan.roberts, dev.jain, baohua, lance.yang,
Li Wang
On Mon, Mar 16, 2026 at 12:43:32PM +0800, Chunyu Hu wrote:
> The test_hugepage test contain two sub tests. If just reporting one skip
> when thp not available, there will be error in the log because the test
> count don't match the test plan. Change to skip two tests by running the
> ksft_test_result_skip twice in this case.
...
> Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
> Reviewed-by: Zi Yan <ziy@nvidia.com>
> CC: Li Wang <liwang@redhat.com>
> Signed-off-by: Chunyu Hu <chuhu@redhat.com>
> ---
> Changes in v2:
> - add reviewed by from Lorenzo and Zi
> - add acked-by from David
> ---
> tools/testing/selftests/mm/soft-dirty.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/mm/soft-dirty.c b/tools/testing/selftests/mm/soft-dirty.c
> index 59c0dbe99a9b..bcfcac99b436 100644
> --- a/tools/testing/selftests/mm/soft-dirty.c
> +++ b/tools/testing/selftests/mm/soft-dirty.c
> @@ -82,7 +82,9 @@ static void test_hugepage(int pagemap_fd, int pagesize)
> int i, ret;
>
> if (!thp_is_enabled()) {
> - ksft_test_result_skip("Transparent Hugepages not available\n");
> + ksft_print_msg("Transparent Hugepages not available\n");
> + ksft_test_result_skip("Test %s huge page allocation\n", __func__);
> + ksft_test_result_skip("Test %s huge page dirty bit\n", __func__);
There's already similar block when the page is not collapsed, but reworking
the test flow can be done on top as a separate commit.
Feel free to add
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 4/5] selftests/mm: split_huge_page_test: skip the test when thp is not available
2026-03-16 4:43 ` [PATCH v2 4/5] selftests/mm: split_huge_page_test: skip the test when thp is not available Chunyu Hu
@ 2026-03-16 6:29 ` Mike Rapoport
2026-03-16 14:10 ` David Hildenbrand (Arm)
1 sibling, 0 replies; 15+ messages in thread
From: Mike Rapoport @ 2026-03-16 6:29 UTC (permalink / raw)
To: Chunyu Hu
Cc: akpm, david, shuah, linux-mm, ljs, linux-kselftest, linux-kernel,
lorenzo.stoakes, Liam.Howlett, vbabka, surenb, mhocko, ziy,
baolin.wang, npache, ryan.roberts, dev.jain, baohua, lance.yang,
Li Wang
On Mon, Mar 16, 2026 at 12:43:34PM +0800, Chunyu Hu wrote:
> When thp is not enabled on some kernel config such as realtime kernel, the
> test will report failure. Fix the false positive by skipping the test
> directly when thp is not enabled.
>
> Tested with thp disabled kernel:
> Before The fix:
> # --------------------------------------------------
> # running ./split_huge_page_test /tmp/xfs_dir_Ywup9p
> # --------------------------------------------------
> # TAP version 13
> # Bail out! Reading PMD pagesize failed
> # # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
> # [FAIL]
> not ok 61 split_huge_page_test /tmp/xfs_dir_Ywup9p # exit=1
>
> After the fix:
> # --------------------------------------------------
> # running ./split_huge_page_test /tmp/xfs_dir_YHPUPl
> # --------------------------------------------------
> # TAP version 13
> # 1..0 # SKIP Transparent Hugepages not available
> # [SKIP]
> ok 6 split_huge_page_test /tmp/xfs_dir_YHPUPl # SKIP
>
> Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
> Reviewed-by: Zi Yan <ziy@nvidia.com>
> CC: Li Wang <liwang@redhat.com>
> Signed-off-by: Chunyu Hu <chuhu@redhat.com>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 5/5] selftests/mm: transhuge_stress: skip the test when thp not available
2026-03-16 4:43 ` [PATCH v2 5/5] selftests/mm: transhuge_stress: skip the test when thp " Chunyu Hu
@ 2026-03-16 6:30 ` Mike Rapoport
2026-03-16 14:11 ` David Hildenbrand (Arm)
1 sibling, 0 replies; 15+ messages in thread
From: Mike Rapoport @ 2026-03-16 6:30 UTC (permalink / raw)
To: Chunyu Hu
Cc: akpm, david, shuah, linux-mm, ljs, linux-kselftest, linux-kernel,
lorenzo.stoakes, Liam.Howlett, vbabka, surenb, mhocko, ziy,
baolin.wang, npache, ryan.roberts, dev.jain, baohua, lance.yang,
Li Wang
On Mon, Mar 16, 2026 at 12:43:35PM +0800, Chunyu Hu wrote:
> The test requires thp, skip the test when thp is not available to avoid
> false positive.
>
> Tested with thp disabled kernel.
> Before the fix:
> # --------------------------------
> # running ./transhuge-stress -d 20
> # --------------------------------
> # TAP version 13
> # 1..1
> # transhuge-stress: allocate 1453 transhuge pages, using 2907 MiB virtual memory and 11 MiB of ram
> # Bail out! MADV_HUGEPAGE# Planned tests != run tests (1 != 0)
> # # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
> # [FAIL]
> not ok 60 transhuge-stress -d 20 # exit=1
>
> After the fix:
> # --------------------------------
> # running ./transhuge-stress -d 20
> # --------------------------------
> # TAP version 13
> # 1..0 # SKIP Transparent Hugepages not available
> # [SKIP]
> ok 5 transhuge-stress -d 20 # SKIP
>
> Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
> Reviewed-by: Zi Yan <ziy@nvidia.com>
> CC: Li Wang <liwang@redhat.com>
> Signed-off-by: Chunyu Hu <chuhu@redhat.com>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 3/5] selftests/mm: move write_file helper to vm_util
2026-03-16 4:43 ` [PATCH v2 3/5] selftests/mm: move write_file helper to vm_util Chunyu Hu
@ 2026-03-16 6:35 ` Mike Rapoport
2026-03-17 9:00 ` Chunyu Hu
0 siblings, 1 reply; 15+ messages in thread
From: Mike Rapoport @ 2026-03-16 6:35 UTC (permalink / raw)
To: Chunyu Hu
Cc: akpm, david, shuah, linux-mm, ljs, linux-kselftest, linux-kernel,
lorenzo.stoakes, Liam.Howlett, vbabka, surenb, mhocko, ziy,
baolin.wang, npache, ryan.roberts, dev.jain, baohua, lance.yang
On Mon, Mar 16, 2026 at 12:43:33PM +0800, Chunyu Hu wrote:
> thp_settings provides write_file() helper for safely writing to a file and
> exit when write failure happens. It's a very low level helper and many sub
> tests need such a helper, not only thp tests.
>
> split_huge_page_test also defines a write_file locally. The two have minior
> differences in return type and used exit api. And there would be conflicts
> if split_huge_page_test wanted to include thp_settings.h because of
> different prototype, making it less convenient.
>
> It's possisble to merge the two, although some tests don't use the
> kselftest infrastrucutre for testing. It would also work when using the
> ksft_exit_msg() to exit in my test, as the counters are all zero. Output
> will be like:
>
> TAP version 13
> 1..62
> Bail out! /proc/sys/vm/drop_caches1 open failed: No such file or directory
> # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
>
> So here just leave one version of write_file, and move it into the vm_util.
> This make it easy to maitain and user could just include one vm_util.h when
> then don't need thp setting helpers. Keep the prototype of returning the
> written bytes num.
>
> Suggested-by: Mike Rapoport <rppt@kernel.org>
> Signed-off-by: Chunyu Hu <chuhu@redhat.com>
> ---
> Changes in v2:
> new patch from v2
> ---
> .../selftests/mm/split_huge_page_test.c | 15 ------------
> tools/testing/selftests/mm/thp_settings.c | 24 +------------------
> tools/testing/selftests/mm/thp_settings.h | 1 -
> tools/testing/selftests/mm/vm_util.c | 16 +++++++++++++
> tools/testing/selftests/mm/vm_util.h | 2 ++
> 5 files changed, 19 insertions(+), 39 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
> index e0167111bdd1..93f205327b84 100644
> --- a/tools/testing/selftests/mm/split_huge_page_test.c
> +++ b/tools/testing/selftests/mm/split_huge_page_test.c
> @@ -255,21 +255,6 @@ static int check_after_split_folio_orders(char *vaddr_start, size_t len,
> return status;
> }
>
> -static void write_file(const char *path, const char *buf, size_t buflen)
> -{
> - int fd;
> - ssize_t numwritten;
> -
> - fd = open(path, O_WRONLY);
> - if (fd == -1)
> - ksft_exit_fail_msg("%s open failed: %s\n", path, strerror(errno));
> -
> - numwritten = write(fd, buf, buflen - 1);
> - close(fd);
> - if (numwritten < 1)
> - ksft_exit_fail_msg("Write failed\n");
> -}
> -
> static void write_debugfs(const char *fmt, ...)
> {
> char input[INPUT_MAX];
> diff --git a/tools/testing/selftests/mm/thp_settings.c b/tools/testing/selftests/mm/thp_settings.c
> index 574bd0f8ae48..02de28ecf31a 100644
> --- a/tools/testing/selftests/mm/thp_settings.c
> +++ b/tools/testing/selftests/mm/thp_settings.c
> @@ -6,6 +6,7 @@
> #include <string.h>
> #include <unistd.h>
>
> +#include "vm_util.h"
> #include "thp_settings.h"
>
> #define THP_SYSFS "/sys/kernel/mm/transparent_hugepage/"
> @@ -64,29 +65,6 @@ int read_file(const char *path, char *buf, size_t buflen)
> return (unsigned int) numread;
> }
>
> -int write_file(const char *path, const char *buf, size_t buflen)
> -{
> - int fd;
> - ssize_t numwritten;
> -
> - fd = open(path, O_WRONLY);
> - if (fd == -1) {
> - printf("open(%s)\n", path);
> - exit(EXIT_FAILURE);
> - return 0;
> - }
> -
> - numwritten = write(fd, buf, buflen - 1);
> - close(fd);
> - if (numwritten < 1) {
> - printf("write(%s)\n", buf);
> - exit(EXIT_FAILURE);
> - return 0;
> - }
> -
> - return (unsigned int) numwritten;
> -}
> -
> unsigned long read_num(const char *path)
> {
> char buf[21];
> diff --git a/tools/testing/selftests/mm/thp_settings.h b/tools/testing/selftests/mm/thp_settings.h
> index 76eeb712e5f1..7748a9009191 100644
> --- a/tools/testing/selftests/mm/thp_settings.h
> +++ b/tools/testing/selftests/mm/thp_settings.h
> @@ -63,7 +63,6 @@ struct thp_settings {
> };
>
> int read_file(const char *path, char *buf, size_t buflen);
> -int write_file(const char *path, const char *buf, size_t buflen);
> unsigned long read_num(const char *path);
> void write_num(const char *path, unsigned long num);
>
> diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c
> index a6d4ff7dfdc0..b4b3b48f8dc9 100644
> --- a/tools/testing/selftests/mm/vm_util.c
> +++ b/tools/testing/selftests/mm/vm_util.c
> @@ -764,3 +764,19 @@ int unpoison_memory(unsigned long pfn)
>
> return ret > 0 ? 0 : -errno;
> }
> +
> +unsigned int write_file(const char *path, const char *buf, size_t buflen)
> +{
> + int fd;
> + ssize_t numwritten;
> +
> + fd = open(path, O_WRONLY);
> + if (fd == -1)
> + ksft_exit_fail_msg("%s open failed: %s\n", path, strerror(errno));
> +
> + numwritten = write(fd, buf, buflen - 1);
> + close(fd);
> + if (numwritten < 1)
> + ksft_exit_fail_msg("Write failed\n");
> + return (unsigned int) numwritten;
If we exit on any failure, the function can be void just like in
split_huge_page_test.c. This will also simplify write_num() and read_num()
in thp_settigns.c
> +}
> diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h
> index e9c4e24769c1..22c8805e0d7a 100644
> --- a/tools/testing/selftests/mm/vm_util.h
> +++ b/tools/testing/selftests/mm/vm_util.h
> @@ -166,3 +166,5 @@ int unpoison_memory(unsigned long pfn);
>
> #define PAGEMAP_PRESENT(ent) (((ent) & (1ull << 63)) != 0)
> #define PAGEMAP_PFN(ent) ((ent) & ((1ull << 55) - 1))
> +
> +unsigned int write_file(const char *path, const char *buf, size_t buflen);
> --
> 2.53.0
>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 4/5] selftests/mm: split_huge_page_test: skip the test when thp is not available
2026-03-16 4:43 ` [PATCH v2 4/5] selftests/mm: split_huge_page_test: skip the test when thp is not available Chunyu Hu
2026-03-16 6:29 ` Mike Rapoport
@ 2026-03-16 14:10 ` David Hildenbrand (Arm)
1 sibling, 0 replies; 15+ messages in thread
From: David Hildenbrand (Arm) @ 2026-03-16 14:10 UTC (permalink / raw)
To: Chunyu Hu, akpm, shuah, linux-mm, ljs
Cc: linux-kselftest, linux-kernel, lorenzo.stoakes, Liam.Howlett,
vbabka, rppt, surenb, mhocko, ziy, baolin.wang, npache,
ryan.roberts, dev.jain, baohua, lance.yang, Li Wang
On 3/16/26 05:43, Chunyu Hu wrote:
> When thp is not enabled on some kernel config such as realtime kernel, the
> test will report failure. Fix the false positive by skipping the test
> directly when thp is not enabled.
>
> Tested with thp disabled kernel:
> Before The fix:
> # --------------------------------------------------
> # running ./split_huge_page_test /tmp/xfs_dir_Ywup9p
> # --------------------------------------------------
> # TAP version 13
> # Bail out! Reading PMD pagesize failed
> # # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
> # [FAIL]
> not ok 61 split_huge_page_test /tmp/xfs_dir_Ywup9p # exit=1
>
> After the fix:
> # --------------------------------------------------
> # running ./split_huge_page_test /tmp/xfs_dir_YHPUPl
> # --------------------------------------------------
> # TAP version 13
> # 1..0 # SKIP Transparent Hugepages not available
> # [SKIP]
> ok 6 split_huge_page_test /tmp/xfs_dir_YHPUPl # SKIP
>
> Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
> Reviewed-by: Zi Yan <ziy@nvidia.com>
> CC: Li Wang <liwang@redhat.com>
> Signed-off-by: Chunyu Hu <chuhu@redhat.com>
> ---
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 5/5] selftests/mm: transhuge_stress: skip the test when thp not available
2026-03-16 4:43 ` [PATCH v2 5/5] selftests/mm: transhuge_stress: skip the test when thp " Chunyu Hu
2026-03-16 6:30 ` Mike Rapoport
@ 2026-03-16 14:11 ` David Hildenbrand (Arm)
1 sibling, 0 replies; 15+ messages in thread
From: David Hildenbrand (Arm) @ 2026-03-16 14:11 UTC (permalink / raw)
To: Chunyu Hu, akpm, shuah, linux-mm, ljs
Cc: linux-kselftest, linux-kernel, lorenzo.stoakes, Liam.Howlett,
vbabka, rppt, surenb, mhocko, ziy, baolin.wang, npache,
ryan.roberts, dev.jain, baohua, lance.yang, Li Wang
On 3/16/26 05:43, Chunyu Hu wrote:
> The test requires thp, skip the test when thp is not available to avoid
> false positive.
>
> Tested with thp disabled kernel.
> Before the fix:
> # --------------------------------
> # running ./transhuge-stress -d 20
> # --------------------------------
> # TAP version 13
> # 1..1
> # transhuge-stress: allocate 1453 transhuge pages, using 2907 MiB virtual memory and 11 MiB of ram
> # Bail out! MADV_HUGEPAGE# Planned tests != run tests (1 != 0)
> # # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
> # [FAIL]
> not ok 60 transhuge-stress -d 20 # exit=1
>
> After the fix:
> # --------------------------------
> # running ./transhuge-stress -d 20
> # --------------------------------
> # TAP version 13
> # 1..0 # SKIP Transparent Hugepages not available
> # [SKIP]
> ok 5 transhuge-stress -d 20 # SKIP
>
> Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
> Reviewed-by: Zi Yan <ziy@nvidia.com>
> CC: Li Wang <liwang@redhat.com>
> Signed-off-by: Chunyu Hu <chuhu@redhat.com>
> ---
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/5] selftests/mm/guard-regions: skip collapse test when thp not enabled
2026-03-16 6:18 ` Mike Rapoport
@ 2026-03-17 6:51 ` Chunyu Hu
0 siblings, 0 replies; 15+ messages in thread
From: Chunyu Hu @ 2026-03-17 6:51 UTC (permalink / raw)
To: Mike Rapoport
Cc: akpm, david, shuah, linux-mm, ljs, linux-kselftest, linux-kernel,
lorenzo.stoakes, Liam.Howlett, vbabka, surenb, mhocko, ziy,
baolin.wang, npache, ryan.roberts, dev.jain, baohua, lance.yang,
Li Wang
On Mon, Mar 16, 2026 at 08:18:40AM +0200, Mike Rapoport wrote:
> On Mon, Mar 16, 2026 at 12:43:31PM +0800, Chunyu Hu wrote:
> > When thp is not available, just skip the collape tests to avoid the false
> > positive.
>
> ... to avoid the false negative
Oops, I missed this one. Will update.
>
> > Without the change, run with a thp disabled kernel:
> > ./run_vmtests.sh -t madv_guard
> > <snip/>
> > # # RUN guard_regions.file.multi_vma ...
> > # # OK guard_regions.file.multi_vma
> > # ok 89 guard_regions.file.multi_vma
> > # # RUN guard_regions.file.basic ...
> > # # OK guard_regions.file.basic
> > # ok 90 guard_regions.file.basic
>
> It would be useful to include output of two failing THP tests rather
> then just the output of the last two test.
Will update in next version.
> You can also add '-n' option to run_vmtest.sh to reduce amount of leading
> #, but for that I don't feel strongly.
Good to know. Thanks.
>
> With that updated
>
> Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
>
> --
> Sincerely yours,
> Mike.
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 3/5] selftests/mm: move write_file helper to vm_util
2026-03-16 6:35 ` Mike Rapoport
@ 2026-03-17 9:00 ` Chunyu Hu
0 siblings, 0 replies; 15+ messages in thread
From: Chunyu Hu @ 2026-03-17 9:00 UTC (permalink / raw)
To: Mike Rapoport
Cc: akpm, david, shuah, linux-mm, ljs, linux-kselftest, linux-kernel,
lorenzo.stoakes, Liam.Howlett, vbabka, surenb, mhocko, ziy,
baolin.wang, npache, ryan.roberts, dev.jain, baohua, lance.yang
On Mon, Mar 16, 2026 at 08:35:11AM +0200, Mike Rapoport wrote:
> On Mon, Mar 16, 2026 at 12:43:33PM +0800, Chunyu Hu wrote:
> > thp_settings provides write_file() helper for safely writing to a file and
> > exit when write failure happens. It's a very low level helper and many sub
> > tests need such a helper, not only thp tests.
> >
> > split_huge_page_test also defines a write_file locally. The two have minior
> > differences in return type and used exit api. And there would be conflicts
> > if split_huge_page_test wanted to include thp_settings.h because of
> > different prototype, making it less convenient.
> >
> > It's possisble to merge the two, although some tests don't use the
> > kselftest infrastrucutre for testing. It would also work when using the
> > ksft_exit_msg() to exit in my test, as the counters are all zero. Output
> > will be like:
> >
> > TAP version 13
> > 1..62
> > Bail out! /proc/sys/vm/drop_caches1 open failed: No such file or directory
> > # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
> >
> > So here just leave one version of write_file, and move it into the vm_util.
> > This make it easy to maitain and user could just include one vm_util.h when
> > then don't need thp setting helpers. Keep the prototype of returning the
> > written bytes num.
> >
> > Suggested-by: Mike Rapoport <rppt@kernel.org>
> > Signed-off-by: Chunyu Hu <chuhu@redhat.com>
> > ---
> > Changes in v2:
> > new patch from v2
> > ---
> > .../selftests/mm/split_huge_page_test.c | 15 ------------
> > tools/testing/selftests/mm/thp_settings.c | 24 +------------------
> > tools/testing/selftests/mm/thp_settings.h | 1 -
> > tools/testing/selftests/mm/vm_util.c | 16 +++++++++++++
> > tools/testing/selftests/mm/vm_util.h | 2 ++
> > 5 files changed, 19 insertions(+), 39 deletions(-)
> >
> > diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
> > index e0167111bdd1..93f205327b84 100644
> > --- a/tools/testing/selftests/mm/split_huge_page_test.c
> > +++ b/tools/testing/selftests/mm/split_huge_page_test.c
> > @@ -255,21 +255,6 @@ static int check_after_split_folio_orders(char *vaddr_start, size_t len,
> > return status;
> > }
> >
> > -static void write_file(const char *path, const char *buf, size_t buflen)
> > -{
> > - int fd;
> > - ssize_t numwritten;
> > -
> > - fd = open(path, O_WRONLY);
> > - if (fd == -1)
> > - ksft_exit_fail_msg("%s open failed: %s\n", path, strerror(errno));
> > -
> > - numwritten = write(fd, buf, buflen - 1);
> > - close(fd);
> > - if (numwritten < 1)
> > - ksft_exit_fail_msg("Write failed\n");
> > -}
> > -
> > static void write_debugfs(const char *fmt, ...)
> > {
> > char input[INPUT_MAX];
> > diff --git a/tools/testing/selftests/mm/thp_settings.c b/tools/testing/selftests/mm/thp_settings.c
> > index 574bd0f8ae48..02de28ecf31a 100644
> > --- a/tools/testing/selftests/mm/thp_settings.c
> > +++ b/tools/testing/selftests/mm/thp_settings.c
> > @@ -6,6 +6,7 @@
> > #include <string.h>
> > #include <unistd.h>
> >
> > +#include "vm_util.h"
> > #include "thp_settings.h"
> >
> > #define THP_SYSFS "/sys/kernel/mm/transparent_hugepage/"
> > @@ -64,29 +65,6 @@ int read_file(const char *path, char *buf, size_t buflen)
> > return (unsigned int) numread;
> > }
> >
> > -int write_file(const char *path, const char *buf, size_t buflen)
> > -{
> > - int fd;
> > - ssize_t numwritten;
> > -
> > - fd = open(path, O_WRONLY);
> > - if (fd == -1) {
> > - printf("open(%s)\n", path);
> > - exit(EXIT_FAILURE);
> > - return 0;
> > - }
> > -
> > - numwritten = write(fd, buf, buflen - 1);
> > - close(fd);
> > - if (numwritten < 1) {
> > - printf("write(%s)\n", buf);
> > - exit(EXIT_FAILURE);
> > - return 0;
> > - }
> > -
> > - return (unsigned int) numwritten;
> > -}
> > -
> > unsigned long read_num(const char *path)
> > {
> > char buf[21];
> > diff --git a/tools/testing/selftests/mm/thp_settings.h b/tools/testing/selftests/mm/thp_settings.h
> > index 76eeb712e5f1..7748a9009191 100644
> > --- a/tools/testing/selftests/mm/thp_settings.h
> > +++ b/tools/testing/selftests/mm/thp_settings.h
> > @@ -63,7 +63,6 @@ struct thp_settings {
> > };
> >
> > int read_file(const char *path, char *buf, size_t buflen);
> > -int write_file(const char *path, const char *buf, size_t buflen);
> > unsigned long read_num(const char *path);
> > void write_num(const char *path, unsigned long num);
> >
> > diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c
> > index a6d4ff7dfdc0..b4b3b48f8dc9 100644
> > --- a/tools/testing/selftests/mm/vm_util.c
> > +++ b/tools/testing/selftests/mm/vm_util.c
> > @@ -764,3 +764,19 @@ int unpoison_memory(unsigned long pfn)
> >
> > return ret > 0 ? 0 : -errno;
> > }
> > +
> > +unsigned int write_file(const char *path, const char *buf, size_t buflen)
> > +{
> > + int fd;
> > + ssize_t numwritten;
> > +
> > + fd = open(path, O_WRONLY);
> > + if (fd == -1)
> > + ksft_exit_fail_msg("%s open failed: %s\n", path, strerror(errno));
> > +
> > + numwritten = write(fd, buf, buflen - 1);
> > + close(fd);
> > + if (numwritten < 1)
> > + ksft_exit_fail_msg("Write failed\n");
> > + return (unsigned int) numwritten;
>
> If we exit on any failure, the function can be void just like in
> split_huge_page_test.c. This will also simplify write_num() and read_num()
> in thp_settigns.c
Good point. I will change it to void. I wont touch read_file() here.
>
> > +}
> > diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h
> > index e9c4e24769c1..22c8805e0d7a 100644
> > --- a/tools/testing/selftests/mm/vm_util.h
> > +++ b/tools/testing/selftests/mm/vm_util.h
> > @@ -166,3 +166,5 @@ int unpoison_memory(unsigned long pfn);
> >
> > #define PAGEMAP_PRESENT(ent) (((ent) & (1ull << 63)) != 0)
> > #define PAGEMAP_PFN(ent) ((ent) & ((1ull << 55) - 1))
> > +
> > +unsigned int write_file(const char *path, const char *buf, size_t buflen);
> > --
> > 2.53.0
> >
>
> --
> Sincerely yours,
> Mike.
>
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2026-03-17 9:00 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-16 4:43 [PATCH v2 0/5] selftests/mm: skip several tests when thp is not available Chunyu Hu
2026-03-16 4:43 ` [PATCH v2 1/5] selftests/mm/guard-regions: skip collapse test when thp not enabled Chunyu Hu
2026-03-16 6:18 ` Mike Rapoport
2026-03-17 6:51 ` Chunyu Hu
2026-03-16 4:43 ` [PATCH v2 2/5] selftests/mm: soft-dirty: skip two tests when thp is not available Chunyu Hu
2026-03-16 6:25 ` Mike Rapoport
2026-03-16 4:43 ` [PATCH v2 3/5] selftests/mm: move write_file helper to vm_util Chunyu Hu
2026-03-16 6:35 ` Mike Rapoport
2026-03-17 9:00 ` Chunyu Hu
2026-03-16 4:43 ` [PATCH v2 4/5] selftests/mm: split_huge_page_test: skip the test when thp is not available Chunyu Hu
2026-03-16 6:29 ` Mike Rapoport
2026-03-16 14:10 ` David Hildenbrand (Arm)
2026-03-16 4:43 ` [PATCH v2 5/5] selftests/mm: transhuge_stress: skip the test when thp " Chunyu Hu
2026-03-16 6:30 ` Mike Rapoport
2026-03-16 14:11 ` David Hildenbrand (Arm)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox