* [PATCH v8 0/4] kselftest: mm: fix some failure of split_huge_page_test
@ 2026-09-24 19:11 Yeoreum Yun
2026-09-24 19:11 ` [PATCH v8 1/4] kselftest: mm: prevent random failure of huge page split for khugepaged Yeoreum Yun
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Yeoreum Yun @ 2026-09-24 19:11 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Shuah Khan,
Kevin Brodsky
Cc: linux-mm, linux-kselftest, linux-kernel, Yeoreum Yun
split_huge_page_test can fail for the following reasons:
1. During the test, khugepaged may collapse previously split pages again,
causing intermittent failures.
2. Since glibc commit 321e1fc73f (“malloc: Enable 2MB THP by default on AArch64”),
glibc may call madvise(MADV_HUGEPAGE) for sufficiently large allocations
made by memalign(). The underlying VMA may start at a different address
from the aligned address returned by memalign(). Moreover, a subsequent
madvise(MADV_HUGEPAGE) call does not split the VMA because it already
has the same advice.
This causes the test to fail because the check_huge_xxx() helpers
incorrectly require the address returned by memalign() to match the
VMA start address reported in /proc/self/smaps.
Address these issues by applying MADV_NOHUGEPAGE after faulting in the
huge page, preventing khugepaged from collapsing it again, and instead of
relying on /proc/self/smaps, use /proc/self/pagemap and
/proc/kpageflags to detect huge-page mappings and large folios:
1. If hpage_size == pmd_pagesize, check PAGE_IS_HUGE instead of
using check_large_folios(), since only the mapping type matters.
This identifies PMD-mapped huge pages.
2. Otherwise, use check_large_folios() to detect large folios. This
covers mTHP cases.
3. Check the folio flags according to the type of huge page.
Since check_huge_shmem() was required to distinguish shmem huge pages
because /proc/self/smaps reports them using a dedicated “ShmemPmdMapped”
entry, as opposed to “FilePmdMapped” for file-backed huge pages.
Now that /proc/self/smaps is no longer used to detect huge pages and
/proc/kpageflags is used instead, it is sufficient to distinguish
between file-backed and anonymous pages since the ShmemPmdMapped is also
kind of file-backed.
Therefore, remove check_huge_shmem() and use check_huge_file() instead.
This patch based on mm-unstable
---
Changes in v8:
- add intermediate patch for __check_pmd_huge().
- add r-b, a-b tags.
- Link to v7: https://lore.kernel.org/r/20260921-fix_split-v7-0-d25ec991159f@arm.com
Changes in v7:
- change khugepaged's check_huge() callback.
- Link to v6: https://lore.kernel.org/r/20260914-fix_split-v6-0-16ed7123800b@arm.com
Changes in v6:
- drop alloc_isolated_mem() patch.
- remove check_huge_shmem().
- Link to v5: https://lore.kernel.org/r/20260907-fix_split-v5-0-822b810458bc@arm.com
Changes in v5:
- rename madv_nohuge() to disable_khugepaged().
- Link to v4: https://lore.kernel.org/r/20260902-fix_split-v4-0-85f03905f7b1@arm.com
Changes in v4:
- reparse commit message.
- introduce alloc_isolated_mem().
- make madv_nohuge() helper according to suggestion.
- Link to v3: https://lore.kernel.org/r/20260828-fix_split-v3-0-374022586a4b@arm.com
Changes in v3:
- change message in case of failure of madvise() with MADV_NOHUGEPAGE.
- fix collapse_single_mthp (mthp_khugepaged:anon) test case failure.
- Link to v2: https://lore.kernel.org/all/20260826-fix_split-v2-0-71153c7f579a@arm.com/
Changes in v2:
- rebase to mm-unstable.
- add message in case of failure of madvise() with MADV_NOHUGEPAGE.
- fix wrong setup expected_huge in check_huge_shmem().
- Link to v1: https://lore.kernel.org/r/20260820-fix_split-v1-0-ab430c58c7cf@arm.com
---
Yeoreum Yun (4):
kselftest: mm: prevent random failure of huge page split for khugepaged
kselftest: mm: replace usage of /proc/self/smaps for __check_pmd_huge()
kselftest: mm: integrate huge page checks
kselftest: mm: remove check_huge_shmem()
tools/testing/selftests/mm/folio_split_race_test.c | 2 +-
tools/testing/selftests/mm/khugepaged.c | 38 +-----
tools/testing/selftests/mm/split_huge_page_test.c | 19 +++
tools/testing/selftests/mm/uffd-common.c | 4 +-
tools/testing/selftests/mm/vm_util.c | 127 ++++++++++++---------
tools/testing/selftests/mm/vm_util.h | 1 -
6 files changed, 102 insertions(+), 89 deletions(-)
---
base-commit: fff9c87241bb46aa09ed3a91d6002cba966d7776
change-id: 20260820-fix_split-f44939ec44b8
Best regards,
--
Sincerely,
Yeoreum Yun
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v8 1/4] kselftest: mm: prevent random failure of huge page split for khugepaged
2026-09-24 19:11 [PATCH v8 0/4] kselftest: mm: fix some failure of split_huge_page_test Yeoreum Yun
@ 2026-09-24 19:11 ` Yeoreum Yun
2026-09-24 19:11 ` [PATCH v8 2/4] kselftest: mm: replace usage of /proc/self/smaps for __check_pmd_huge() Yeoreum Yun
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Yeoreum Yun @ 2026-09-24 19:11 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Shuah Khan,
Kevin Brodsky
Cc: linux-mm, linux-kselftest, linux-kernel, Yeoreum Yun
There're some random failure for split_huge_page_test when khugepaged
collapses pages into pmd again which had split by the test.
Prevent the khugepaged's collapses for split page by setting the
mapped pmd-huge-page with MADV_NOHUGEPAGE before split.
Suggested-by: Kevin Brodsky <kevin.brodsky@arm.com>
Suggested-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
tools/testing/selftests/mm/split_huge_page_test.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
index c5d96a4b1db3..ef4058662b91 100644
--- a/tools/testing/selftests/mm/split_huge_page_test.c
+++ b/tools/testing/selftests/mm/split_huge_page_test.c
@@ -108,6 +108,18 @@ static char *allocate_zero_filled_hugepage(size_t len)
return result;
}
+static void disable_khugepaged(void *addr, size_t len)
+{
+ /*
+ * Disables khugepaged from collapsing THPs in range, existing THP
+ * pages remain.
+ */
+ if (!madvise(addr, len, MADV_NOHUGEPAGE))
+ return;
+
+ ksft_exit_fail_msg("MADV_NOHUGEPAGE failed, err=%d\n", errno);
+}
+
static void verify_rss_anon_split_huge_page_all_zeroes(char *one_page, int nr_hpages, size_t len)
{
unsigned long rss_anon_before, rss_anon_after;
@@ -120,6 +132,8 @@ static void verify_rss_anon_split_huge_page_all_zeroes(char *one_page, int nr_hp
if (!rss_anon_before)
ksft_exit_fail_msg("No RssAnon is allocated before split\n");
+ disable_khugepaged(one_page, len);
+
/* split all THPs */
write_debugfs(PID_FMT, getpid(), (uint64_t)one_page,
(uint64_t)one_page + len, 0);
@@ -167,6 +181,8 @@ static void split_pmd_thp_to_order(int order)
if (!check_huge_anon(one_page, 4 * pmd_pagesize, 4, pmd_pagesize))
ksft_exit_fail_msg("No THP is allocated\n");
+ disable_khugepaged(one_page, len);
+
/* split all THPs */
write_debugfs(PID_FMT, getpid(), (uint64_t)one_page,
(uint64_t)one_page + len, order);
@@ -215,6 +231,8 @@ static void split_pte_mapped_thp(void)
goto out;
}
+ disable_khugepaged(thp_area, thp_area_size);
+
/*
* To challenge spitting code, we will mremap a single page of each
* THP (page[i] of thp[i]) in the thp_area into page_area. This will
@@ -482,6 +500,7 @@ static int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size,
ksft_test_result_skip("Pagecache folio split skipped\n");
return -2;
}
+ disable_khugepaged(*addr, fd_size);
return 0;
err_out_close:
close(*fd);
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v8 2/4] kselftest: mm: replace usage of /proc/self/smaps for __check_pmd_huge()
2026-09-24 19:11 [PATCH v8 0/4] kselftest: mm: fix some failure of split_huge_page_test Yeoreum Yun
2026-09-24 19:11 ` [PATCH v8 1/4] kselftest: mm: prevent random failure of huge page split for khugepaged Yeoreum Yun
@ 2026-09-24 19:11 ` Yeoreum Yun
2026-09-24 19:11 ` [PATCH v8 3/4] kselftest: mm: integrate huge page checks Yeoreum Yun
2026-09-24 19:11 ` [PATCH v8 4/4] kselftest: mm: remove check_huge_shmem() Yeoreum Yun
3 siblings, 0 replies; 5+ messages in thread
From: Yeoreum Yun @ 2026-09-24 19:11 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Shuah Khan,
Kevin Brodsky
Cc: linux-mm, linux-kselftest, linux-kernel, Yeoreum Yun
Since glibc commit 321e1fc73f (“malloc: Enable 2MB THP by default on AArch64”),
glibc may call madvise(MADV_HUGEPAGE) for sufficiently large allocations
made by memalign().
The underlying VMA may start at a different address from the aligned
address returned by memalign(). Furthermore, a subsequent
madvise(MADV_HUGEPAGE) call does not split the VMA because the flag is
already set.
This causes split_huge_page_test to fail because the check_pmd_huge()
helpers incorrectly require the address returned by memalign() to
match the VMA start address reported in /proc/self/smaps.
Instead of relying on /proc/self/smaps, use /proc/self/pagemap and
/proc/kpageflags to detect huge-page mappings checking PAGE_IS_HUGE
and PAGE_IS_FILE accroding to type of huge page.
Since shmem pages are also file-backed, simply check whether the page
is file-backed.
Fixes: 642bc52aed9 ("selftests: vm: bring common functions to a new file")
Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
tools/testing/selftests/mm/vm_util.c | 78 ++++++++++++++++++++++--------------
1 file changed, 49 insertions(+), 29 deletions(-)
diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c
index a0ab78ceedb1..969d7202500c 100644
--- a/tools/testing/selftests/mm/vm_util.c
+++ b/tools/testing/selftests/mm/vm_util.c
@@ -351,24 +351,6 @@ char *__get_smap_entry(void *addr, const char *pattern, char *buf, size_t len)
return entry;
}
-static bool __check_pmd_huge(void *addr, char *pattern, int nr_hpages,
- uint64_t hpage_size)
-{
- char buffer[MAX_LINE_LENGTH];
- uint64_t thp = -1;
- char *entry;
-
- entry = __get_smap_entry(addr, pattern, buffer, sizeof(buffer));
- if (!entry)
- goto err_out;
-
- if (sscanf(entry, "%9" SCNu64 " kB", &thp) != 1)
- ksft_exit_fail_msg("Reading smap error\n");
-
-err_out:
- return thp == (nr_hpages * (hpage_size >> 10));
-}
-
static bool check_large_folios(void *addr, size_t len, int nr_hpages,
uint64_t hpage_size)
{
@@ -410,20 +392,51 @@ static bool check_large_folios(void *addr, size_t len, int nr_hpages,
return ret;
}
-bool check_huge_anon(void *addr, size_t len, int nr_hpages, uint64_t hpage_size)
+enum check_huge_type {
+ CHECK_HUGE_ANON,
+ CHECK_HUGE_FILE,
+};
+
+static bool check_huge_type(uint64_t categories, enum check_huge_type type)
{
- uint64_t pmd_pagesize = read_pmd_pagesize();
+ const bool file = categories & PAGE_IS_FILE;
- if (!pmd_pagesize)
- ksft_exit_fail_msg("reading PMD pagesize failed\n");
+ switch (type) {
+ case CHECK_HUGE_ANON:
+ return !file;
+ case CHECK_HUGE_FILE:
+ return file;
+ }
- if (hpage_size == pmd_pagesize)
- return __check_pmd_huge(addr, "AnonHugePages: ", nr_hpages, hpage_size);
+ return false;
+}
- return check_large_folios(addr, len, nr_hpages, hpage_size);
+static bool __check_pmd_huge(void *addr, size_t len, int nr_hpages,
+ uint64_t hpage_size, enum check_huge_type type)
+{
+ int pagemap_fd;
+ int nr_pmd_mappings = 0;
+ uint64_t categories;
+ char *start = addr;
+ char *end = start + len;
+
+ pagemap_fd = open(PAGEMAP_PATH, O_RDONLY);
+ if (pagemap_fd < 0)
+ ksft_exit_fail_msg("open pagemap fail\n");
+
+ for (; start < end; start += hpage_size) {
+ categories = pagemap_scan_get_categories(pagemap_fd, start);
+ if (!(categories & PAGE_IS_HUGE))
+ continue;
+ if (check_huge_type(categories, type))
+ nr_pmd_mappings++;
+ }
+ close(pagemap_fd);
+
+ return nr_hpages == nr_pmd_mappings;
}
-bool check_huge_file(void *addr, size_t len, int nr_hpages, uint64_t hpage_size)
+bool check_huge_anon(void *addr, size_t len, int nr_hpages, uint64_t hpage_size)
{
uint64_t pmd_pagesize = read_pmd_pagesize();
@@ -431,12 +444,13 @@ bool check_huge_file(void *addr, size_t len, int nr_hpages, uint64_t hpage_size)
ksft_exit_fail_msg("reading PMD pagesize failed\n");
if (hpage_size == pmd_pagesize)
- return __check_pmd_huge(addr, "FilePmdMapped:", nr_hpages, hpage_size);
+ return __check_pmd_huge(addr, len, nr_hpages, hpage_size,
+ CHECK_HUGE_ANON);
return check_large_folios(addr, len, nr_hpages, hpage_size);
}
-bool check_huge_shmem(void *addr, size_t len, int nr_hpages, uint64_t hpage_size)
+bool check_huge_file(void *addr, size_t len, int nr_hpages, uint64_t hpage_size)
{
uint64_t pmd_pagesize = read_pmd_pagesize();
@@ -444,11 +458,17 @@ bool check_huge_shmem(void *addr, size_t len, int nr_hpages, uint64_t hpage_size
ksft_exit_fail_msg("reading PMD pagesize failed\n");
if (hpage_size == pmd_pagesize)
- return __check_pmd_huge(addr, "ShmemPmdMapped:", nr_hpages, hpage_size);
+ return __check_pmd_huge(addr, len, nr_hpages, hpage_size,
+ CHECK_HUGE_FILE);
return check_large_folios(addr, len, nr_hpages, hpage_size);
}
+bool check_huge_shmem(void *addr, size_t len, int nr_hpages, uint64_t hpage_size)
+{
+ return check_huge_file(addr, len, nr_hpages, hpage_size);
+}
+
int64_t allocate_transhuge(void *ptr, int pagemap_fd)
{
uint64_t ent[2];
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v8 3/4] kselftest: mm: integrate huge page checks
2026-09-24 19:11 [PATCH v8 0/4] kselftest: mm: fix some failure of split_huge_page_test Yeoreum Yun
2026-09-24 19:11 ` [PATCH v8 1/4] kselftest: mm: prevent random failure of huge page split for khugepaged Yeoreum Yun
2026-09-24 19:11 ` [PATCH v8 2/4] kselftest: mm: replace usage of /proc/self/smaps for __check_pmd_huge() Yeoreum Yun
@ 2026-09-24 19:11 ` Yeoreum Yun
2026-09-24 19:11 ` [PATCH v8 4/4] kselftest: mm: remove check_huge_shmem() Yeoreum Yun
3 siblings, 0 replies; 5+ messages in thread
From: Yeoreum Yun @ 2026-09-24 19:11 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Shuah Khan,
Kevin Brodsky
Cc: linux-mm, linux-kselftest, linux-kernel, Yeoreum Yun
check_large_folios() only checks for large folios without distinguishing
between anonymous and file-backed huge pages.
To add huge page type checking, integrate the huge page checks into
__check_huge():
1. If hpage_size == pmd_pagesize, check PAGE_IS_HUGE instead of using
check_large_folios(), since only the mapping type matters. This
identifies PMD-mapped huge pages.
2. Otherwise, use check_large_folios() to detect large folios. This
covers mTHP cases.
3. Check the folio flags according to the huge page type.
Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
Suggested-by: Zi Yan <ziy@nvidia.com>
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
tools/testing/selftests/mm/vm_util.c | 90 +++++++++++++++++++-----------------
1 file changed, 48 insertions(+), 42 deletions(-)
diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c
index 969d7202500c..7d23038af1df 100644
--- a/tools/testing/selftests/mm/vm_util.c
+++ b/tools/testing/selftests/mm/vm_util.c
@@ -351,13 +351,13 @@ char *__get_smap_entry(void *addr, const char *pattern, char *buf, size_t len)
return entry;
}
-static bool check_large_folios(void *addr, size_t len, int nr_hpages,
+static bool check_large_folios(int pagemap_fd, int kpageflags_fd,
+ void *addr, size_t len, int nr_hpages,
uint64_t hpage_size)
{
int order = 0, pagesize = getpagesize();
unsigned int nr_pages = hpage_size / pagesize;
int orders[MAX_NR_ORDERS], status;
- int pagemap_fd, kpageflags_fd;
bool ret = false;
if (!nr_pages)
@@ -368,15 +368,6 @@ static bool check_large_folios(void *addr, size_t len, int nr_hpages,
ksft_exit_fail_msg("invalid order\n");
memset(orders, 0, sizeof(int) * MAX_NR_ORDERS);
- pagemap_fd = open(PAGEMAP_PATH, O_RDONLY);
- if (pagemap_fd == -1)
- ksft_exit_fail_msg("read pagemap fail\n");
-
- kpageflags_fd = open(KPAGEFLAGS_PATH, O_RDONLY);
- if (kpageflags_fd == -1) {
- close(pagemap_fd);
- ksft_exit_fail_msg("read kpageflags fail\n");
- }
status = gather_folio_orders(addr, len, pagemap_fd,
kpageflags_fd, orders, MAX_NR_ORDERS);
@@ -387,8 +378,6 @@ static bool check_large_folios(void *addr, size_t len, int nr_hpages,
ret = true;
out:
- close(pagemap_fd);
- close(kpageflags_fd);
return ret;
}
@@ -411,57 +400,74 @@ static bool check_huge_type(uint64_t categories, enum check_huge_type type)
return false;
}
-static bool __check_pmd_huge(void *addr, size_t len, int nr_hpages,
- uint64_t hpage_size, enum check_huge_type type)
+static bool __check_huge(void *addr, size_t len, int nr_hpages,
+ uint64_t hpage_size, enum check_huge_type type)
{
- int pagemap_fd;
+ bool ret = false;
+ int pagemap_fd, kpageflags_fd;
int nr_pmd_mappings = 0;
+ uint64_t pmd_pagesize, scan_mapping_size;
uint64_t categories;
+ unsigned long pfn;
+ bool check_pmd_mapping, allow_nonpresent;
char *start = addr;
char *end = start + len;
+ pmd_pagesize = read_pmd_pagesize();
+ if (!pmd_pagesize)
+ ksft_exit_fail_msg("reading PMD pagesize failed\n");
+
+ check_pmd_mapping = hpage_size == pmd_pagesize;
+ scan_mapping_size = (nr_hpages > 0) ? hpage_size : psize();
+ /* Some mTHP tests check a partially populated PMD-sized range. */
+ allow_nonpresent = (uint64_t)nr_hpages * hpage_size < len;
+
pagemap_fd = open(PAGEMAP_PATH, O_RDONLY);
if (pagemap_fd < 0)
ksft_exit_fail_msg("open pagemap fail\n");
- for (; start < end; start += hpage_size) {
+ kpageflags_fd = open(KPAGEFLAGS_PATH, O_RDONLY);
+ if (kpageflags_fd < 0)
+ ksft_exit_fail_msg("open kpageflags fail\n");
+
+ if (!check_pmd_mapping &&
+ !check_large_folios(pagemap_fd, kpageflags_fd,
+ addr, len, nr_hpages, hpage_size))
+ goto out;
+
+ for (; start < end; start += scan_mapping_size) {
categories = pagemap_scan_get_categories(pagemap_fd, start);
- if (!(categories & PAGE_IS_HUGE))
- continue;
- if (check_huge_type(categories, type))
+ pfn = pagemap_get_pfn(pagemap_fd, start);
+ if (pfn == -1UL) {
+ if (!allow_nonpresent)
+ goto out;
+ else
+ continue;
+ }
+ if (check_pmd_mapping && (categories & PAGE_IS_HUGE))
nr_pmd_mappings++;
+ if (!check_huge_type(categories, type))
+ goto out;
}
- close(pagemap_fd);
- return nr_hpages == nr_pmd_mappings;
+ if (check_pmd_mapping && (nr_pmd_mappings != nr_hpages))
+ goto out;
+ ret = true;
+
+out:
+ close(pagemap_fd);
+ close(kpageflags_fd);
+ return ret;
}
bool check_huge_anon(void *addr, size_t len, int nr_hpages, uint64_t hpage_size)
{
- uint64_t pmd_pagesize = read_pmd_pagesize();
-
- if (!pmd_pagesize)
- ksft_exit_fail_msg("reading PMD pagesize failed\n");
-
- if (hpage_size == pmd_pagesize)
- return __check_pmd_huge(addr, len, nr_hpages, hpage_size,
- CHECK_HUGE_ANON);
-
- return check_large_folios(addr, len, nr_hpages, hpage_size);
+ return __check_huge(addr, len, nr_hpages, hpage_size, CHECK_HUGE_ANON);
}
bool check_huge_file(void *addr, size_t len, int nr_hpages, uint64_t hpage_size)
{
- uint64_t pmd_pagesize = read_pmd_pagesize();
-
- if (!pmd_pagesize)
- ksft_exit_fail_msg("reading PMD pagesize failed\n");
-
- if (hpage_size == pmd_pagesize)
- return __check_pmd_huge(addr, len, nr_hpages, hpage_size,
- CHECK_HUGE_FILE);
-
- return check_large_folios(addr, len, nr_hpages, hpage_size);
+ return __check_huge(addr, len, nr_hpages, hpage_size, CHECK_HUGE_FILE);
}
bool check_huge_shmem(void *addr, size_t len, int nr_hpages, uint64_t hpage_size)
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v8 4/4] kselftest: mm: remove check_huge_shmem()
2026-09-24 19:11 [PATCH v8 0/4] kselftest: mm: fix some failure of split_huge_page_test Yeoreum Yun
` (2 preceding siblings ...)
2026-09-24 19:11 ` [PATCH v8 3/4] kselftest: mm: integrate huge page checks Yeoreum Yun
@ 2026-09-24 19:11 ` Yeoreum Yun
3 siblings, 0 replies; 5+ messages in thread
From: Yeoreum Yun @ 2026-09-24 19:11 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Shuah Khan,
Kevin Brodsky
Cc: linux-mm, linux-kselftest, linux-kernel, Yeoreum Yun
check_huge_shmem() was required to distinguish shmem huge pages because
/proc/self/smaps reports them using a dedicated “ShmemPmdMapped” entry,
as opposed to “FilePmdMapped” for file-backed huge pages.
Now that /proc/self/smaps is no longer used to detect huge pages and
/proc/kpageflags is used instead, it is sufficient to distinguish
between file-backed and anonymous pages since the ShmemPmdMapped is also
kind of file-backed.
Therefore, remove check_huge_shmem() and use check_huge_file() instead
and cleanup khugepaged's check_huge operation in mem_ops.
Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Acked-by: Zi Yan <ziy@nvidia.com>
Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
tools/testing/selftests/mm/folio_split_race_test.c | 2 +-
tools/testing/selftests/mm/khugepaged.c | 38 ++++------------------
tools/testing/selftests/mm/uffd-common.c | 4 +--
tools/testing/selftests/mm/vm_util.c | 5 ---
tools/testing/selftests/mm/vm_util.h | 1 -
5 files changed, 9 insertions(+), 41 deletions(-)
diff --git a/tools/testing/selftests/mm/folio_split_race_test.c b/tools/testing/selftests/mm/folio_split_race_test.c
index e4660bf89b62..1a9840b73e61 100644
--- a/tools/testing/selftests/mm/folio_split_race_test.c
+++ b/tools/testing/selftests/mm/folio_split_race_test.c
@@ -181,7 +181,7 @@ static uint64_t run_iteration(void)
for (i = 0; i < TOTAL_PAGES; i++)
fill_page(mmap_base, i);
- if (!check_huge_shmem(mmap_base, FILE_SIZE, NR_PMD_PAGE, pmd_pagesize))
+ if (!check_huge_file(mmap_base, FILE_SIZE, NR_PMD_PAGE, pmd_pagesize))
ksft_exit_fail_msg("No shmem THP is allocated\n");
if (pthread_barrier_init(&ctl.barrier, NULL, NUM_READER_THREADS + 1) != 0)
diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c
index bdc0c7c117d9..73d6ab404430 100644
--- a/tools/testing/selftests/mm/khugepaged.c
+++ b/tools/testing/selftests/mm/khugepaged.c
@@ -57,7 +57,7 @@ struct mem_ops {
void *(*setup_area)(int nr_hpages);
void (*cleanup_area)(void *p, unsigned long size);
void (*fault)(void *p, unsigned long start, unsigned long end);
- bool (*check_huge)(void *addr, size_t len, int nr_hpages, unsigned long hpage_size);
+ bool (*check_huge)(void *addr, size_t len, int nr_hpages, uint64_t hpage_size);
const char *name;
};
@@ -343,12 +343,6 @@ static void anon_fault(void *p, unsigned long start, unsigned long end)
fill_memory(p, start, end);
}
-static bool anon_check_huge(void *addr, size_t len, int nr_hpages,
- unsigned long hpage_size)
-{
- return check_huge_anon(addr, len, nr_hpages, hpage_size);
-}
-
static void *file_setup_area_common(int nr_hpages, enum file_setup_ops setup)
{
const int open_opt = setup == FILE_SETUP_READ_ONLY_FS ? O_RDONLY : O_RDWR;
@@ -444,20 +438,6 @@ static void file_fault_write(void *p, unsigned long start, unsigned long end)
ksft_exit_fail_perror("madvise(MADV_POPULATE_WRITE)");
}
-static bool file_check_huge(void *addr, size_t len, int nr_hpages,
- unsigned long hpage_size)
-{
- switch (finfo.type) {
- case VMA_FILE:
- return check_huge_file(addr, len, nr_hpages, hpage_size);
- case VMA_SHMEM:
- return check_huge_shmem(addr, len, nr_hpages, hpage_size);
- default:
- ksft_exit_fail_msg("Unknown VMA type\n");
- return false;
- }
-}
-
static void *shmem_setup_area(int nr_hpages)
{
void *p;
@@ -481,17 +461,11 @@ static void shmem_cleanup_area(void *p, unsigned long size)
close(finfo.fd);
}
-static bool shmem_check_huge(void *addr, size_t len, int nr_hpages,
- unsigned long hpage_size)
-{
- return check_huge_shmem(addr, len, nr_hpages, hpage_size);
-}
-
static struct mem_ops __anon_ops = {
.setup_area = &anon_setup_area,
.cleanup_area = &anon_cleanup_area,
.fault = &anon_fault,
- .check_huge = &anon_check_huge,
+ .check_huge = &check_huge_anon,
.name = "anon",
};
@@ -499,7 +473,7 @@ static struct mem_ops __read_only_file_ops = {
.setup_area = &file_setup_read_only_area,
.cleanup_area = &file_cleanup_area,
.fault = &file_fault_read,
- .check_huge = &file_check_huge,
+ .check_huge = &check_huge_file,
.name = "file",
};
@@ -507,7 +481,7 @@ static struct mem_ops __read_write_file_read_ops = {
.setup_area = &file_setup_read_write_fs_read_area,
.cleanup_area = &file_cleanup_area,
.fault = &file_fault_read_and_flush,
- .check_huge = &file_check_huge,
+ .check_huge = &check_huge_file,
.name = "file",
};
@@ -515,7 +489,7 @@ static struct mem_ops __read_write_file_write_ops = {
.setup_area = &file_setup_read_write_fs_write_area,
.cleanup_area = &file_cleanup_area,
.fault = &file_fault_write,
- .check_huge = &file_check_huge,
+ .check_huge = &check_huge_file,
.name = "file",
};
@@ -523,7 +497,7 @@ static struct mem_ops __shmem_ops = {
.setup_area = &shmem_setup_area,
.cleanup_area = &shmem_cleanup_area,
.fault = &anon_fault,
- .check_huge = &shmem_check_huge,
+ .check_huge = &check_huge_file,
.name = "shmem",
};
diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c
index 1fb967ef4985..a76851aced4d 100644
--- a/tools/testing/selftests/mm/uffd-common.c
+++ b/tools/testing/selftests/mm/uffd-common.c
@@ -196,8 +196,8 @@ static void shmem_check_pmd_mapping(uffd_global_test_opts_t *gopts, void *p, int
{
size_t len = expect_nr_hpages * read_pmd_pagesize();
- if (!check_huge_shmem(gopts->area_dst_alias, len, expect_nr_hpages,
- read_pmd_pagesize()))
+ if (!check_huge_file(gopts->area_dst_alias, len, expect_nr_hpages,
+ read_pmd_pagesize()))
err("Did not find expected %d number of hugepages",
expect_nr_hpages);
}
diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c
index 7d23038af1df..65bc4761d1c9 100644
--- a/tools/testing/selftests/mm/vm_util.c
+++ b/tools/testing/selftests/mm/vm_util.c
@@ -470,11 +470,6 @@ bool check_huge_file(void *addr, size_t len, int nr_hpages, uint64_t hpage_size)
return __check_huge(addr, len, nr_hpages, hpage_size, CHECK_HUGE_FILE);
}
-bool check_huge_shmem(void *addr, size_t len, int nr_hpages, uint64_t hpage_size)
-{
- return check_huge_file(addr, len, nr_hpages, hpage_size);
-}
-
int64_t allocate_transhuge(void *ptr, int pagemap_fd)
{
uint64_t ent[2];
diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h
index 072a6c756c51..b5d59729d432 100644
--- a/tools/testing/selftests/mm/vm_util.h
+++ b/tools/testing/selftests/mm/vm_util.h
@@ -96,7 +96,6 @@ uint64_t read_pmd_pagesize(void);
unsigned long rss_anon(void);
bool check_huge_anon(void *addr, size_t len, int nr_hpages, uint64_t hpage_size);
bool check_huge_file(void *addr, size_t len, int nr_hpages, uint64_t hpage_size);
-bool check_huge_shmem(void *addr, size_t len, int nr_hpages, uint64_t hpage_size);
int64_t allocate_transhuge(void *ptr, int pagemap_fd);
int pageflags_get(unsigned long pfn, int kpageflags_fd, uint64_t *flags);
int gather_folio_orders(char *vaddr_start, size_t len,
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-09-24 19:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-24 19:11 [PATCH v8 0/4] kselftest: mm: fix some failure of split_huge_page_test Yeoreum Yun
2026-09-24 19:11 ` [PATCH v8 1/4] kselftest: mm: prevent random failure of huge page split for khugepaged Yeoreum Yun
2026-09-24 19:11 ` [PATCH v8 2/4] kselftest: mm: replace usage of /proc/self/smaps for __check_pmd_huge() Yeoreum Yun
2026-09-24 19:11 ` [PATCH v8 3/4] kselftest: mm: integrate huge page checks Yeoreum Yun
2026-09-24 19:11 ` [PATCH v8 4/4] kselftest: mm: remove check_huge_shmem() Yeoreum Yun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®