Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/vm: add file/shmem MADV_COLLAPSE selftest for cleared pmd

This test tests that MADV_COLLAPSE acting on file/shmem memory for which
(1) the file extent mapping by the memory is already a huge page in the
page cache, and (2) the pmd mapping this memory in the target process is
none.

In practice, (1)+(2) is the state left over after khugepaged has
successfully collapsed file/shmem memory for a target VMA, but the memory
has not yet been refaulted. So, this test in-effect tests MADV_COLLAPSE
racing with khugepaged to collapse the memory first.

Link: https://lkml.kernel.org/r/20220907144521.3115321-10-zokeefe@google.com
Link: https://lkml.kernel.org/r/20220922224046.1143204-10-zokeefe@google.com
Signed-off-by: Zach O'Keefe <zokeefe@google.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Chris Kennelly <ckennelly@google.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: James Houghton <jthoughton@google.com>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Rongwei Wang <rongwei.wang@linux.alibaba.com>
Cc: SeongJae Park <sj@kernel.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Yang Shi <shy828301@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Zach O'Keefe and committed by
Andrew Morton
69d9428c d0d35b60

+30
+30
tools/testing/selftests/vm/khugepaged.c
··· 1353 1353 ops->cleanup_area(p, hpage_pmd_size); 1354 1354 } 1355 1355 1356 + /* 1357 + * Test race with khugepaged where page tables have been retracted and 1358 + * pmd cleared. 1359 + */ 1360 + static void madvise_retracted_page_tables(struct collapse_context *c, 1361 + struct mem_ops *ops) 1362 + { 1363 + void *p; 1364 + int nr_hpages = 1; 1365 + unsigned long size = nr_hpages * hpage_pmd_size; 1366 + 1367 + p = ops->setup_area(nr_hpages); 1368 + ops->fault(p, 0, size); 1369 + 1370 + /* Let khugepaged collapse and leave pmd cleared */ 1371 + if (wait_for_scan("Collapse and leave PMD cleared", p, nr_hpages, 1372 + ops)) { 1373 + fail("Timeout"); 1374 + return; 1375 + } 1376 + success("OK"); 1377 + c->collapse("Install huge PMD from page cache", p, nr_hpages, ops, 1378 + true); 1379 + validate_memory(p, 0, size); 1380 + ops->cleanup_area(p, size); 1381 + } 1382 + 1356 1383 static void usage(void) 1357 1384 { 1358 1385 fprintf(stderr, "\nUsage: ./khugepaged <test type> [dir]\n\n"); ··· 1550 1523 TEST(madvise_collapse_existing_thps, madvise_context, anon_ops); 1551 1524 TEST(madvise_collapse_existing_thps, madvise_context, file_ops); 1552 1525 TEST(madvise_collapse_existing_thps, madvise_context, shmem_ops); 1526 + 1527 + TEST(madvise_retracted_page_tables, madvise_context, file_ops); 1528 + TEST(madvise_retracted_page_tables, madvise_context, shmem_ops); 1553 1529 1554 1530 restore_settings(0); 1555 1531 }