@@ -969,6 +969,32 @@ static void collapse_max_ptes_shared(struct collapse_context *context)
munmap(p, hpage_pmd_size);
}
+static void madvise_collapse_existing_thps(void)
+{
+ void *p;
+ int err;
+
+ p = alloc_mapping();
+ fill_memory(p, 0, hpage_pmd_size);
+
+ printf("Collapse fully populated PTE table...");
+ madvise(p, hpage_pmd_size, MADV_HUGEPAGE);
+ err = madvise(p, hpage_pmd_size, MADV_COLLAPSE);
+ if (err == 0 && check_huge(p)) {
+ success("OK");
+ printf("Re-collapse PMD-mapped hugepage");
+ err = madvise(p, hpage_pmd_size, MADV_COLLAPSE);
+ if (err == 0 && check_huge(p))
+ success("OK");
+ else
+ fail("Fail");
+ } else {
+ fail("Fail");
+ }
+ validate_memory(p, 0, hpage_pmd_size);
+ munmap(p, hpage_pmd_size);
+}
+
static void madvise_collapse(const char *msg, char *p, bool expect)
{
int ret;
@@ -1097,6 +1123,7 @@ int main(void)
alloc_at_fault();
+ /* Shared tests */
for (i = 0; i < sizeof(contexts) / sizeof(contexts[0]); ++i) {
struct collapse_context *c = &contexts[i];
@@ -1119,5 +1146,10 @@ int main(void)
break;
}
+ /* madvise-specific tests */
+ disable_khugepaged();
+ madvise_collapse_existing_thps();
+ enable_khugepaged();
+
restore_settings(0);
}
Add selftest specific to madvise collapse context that tests MADV_COLLAPSE is "successful" if a hugepage-algined/sized region is already pmd-mapped. Signed-off-by: Zach O'Keefe <zokeefe@google.com> --- tools/testing/selftests/vm/khugepaged.c | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+)