Skip to content

Commit 1370a21

Browse files
zokeefeakpm00
authored andcommitted
selftests/vm: add selftest to verify recollapse of THPs
Add selftest specific to madvise collapse context that tests MADV_COLLAPSE is "successful" if a hugepage-aligned/sized region is already pmd-mapped. This test also verifies that MADV_COLLAPSE can collapse memory into THPs even in "madvise" THP mode and the memory isn't marked VM_HUGEPAGE. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Zach O'Keefe <[email protected]> Cc: Alex Shi <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Axel Rasmussen <[email protected]> Cc: Chris Kennelly <[email protected]> Cc: Chris Zankel <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: David Rientjes <[email protected]> Cc: Helge Deller <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Ivan Kokshaysky <[email protected]> Cc: James Bottomley <[email protected]> Cc: Jens Axboe <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Matt Turner <[email protected]> Cc: Max Filippov <[email protected]> Cc: Miaohe Lin <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Pasha Tatashin <[email protected]> Cc: Pavel Begunkov <[email protected]> Cc: Peter Xu <[email protected]> Cc: Rongwei Wang <[email protected]> Cc: SeongJae Park <[email protected]> Cc: Song Liu <[email protected]> Cc: Thomas Bogendoerfer <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Yang Shi <[email protected]> Cc: Zi Yan <[email protected]> Cc: Dan Carpenter <[email protected]> Cc: "Souptick Joarder (HPE)" <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 9330694 commit 1370a21

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tools/testing/selftests/vm/khugepaged.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,36 @@ static void collapse_max_ptes_shared(struct collapse_context *c)
990990
munmap(p, hpage_pmd_size);
991991
}
992992

993+
static void madvise_collapse_existing_thps(void)
994+
{
995+
void *p;
996+
int err;
997+
998+
p = alloc_mapping();
999+
fill_memory(p, 0, hpage_pmd_size);
1000+
1001+
printf("Collapse fully populated PTE table...");
1002+
/*
1003+
* Note that we don't set MADV_HUGEPAGE here, which
1004+
* also tests that VM_HUGEPAGE isn't required for
1005+
* MADV_COLLAPSE in "madvise" mode.
1006+
*/
1007+
err = madvise(p, hpage_pmd_size, MADV_COLLAPSE);
1008+
if (err == 0 && check_huge(p)) {
1009+
success("OK");
1010+
printf("Re-collapse PMD-mapped hugepage");
1011+
err = madvise(p, hpage_pmd_size, MADV_COLLAPSE);
1012+
if (err == 0 && check_huge(p))
1013+
success("OK");
1014+
else
1015+
fail("Fail");
1016+
} else {
1017+
fail("Fail");
1018+
}
1019+
validate_memory(p, 0, hpage_pmd_size);
1020+
munmap(p, hpage_pmd_size);
1021+
}
1022+
9931023
int main(int argc, const char **argv)
9941024
{
9951025
struct collapse_context c;
@@ -1057,6 +1087,7 @@ int main(int argc, const char **argv)
10571087
collapse_fork(&c);
10581088
collapse_fork_compound(&c);
10591089
collapse_max_ptes_shared(&c);
1090+
madvise_collapse_existing_thps();
10601091
}
10611092

10621093
restore_settings(0);

0 commit comments

Comments
 (0)