Commit 1370a21f authored by Zach O'Keefe's avatar Zach O'Keefe Committed by Andrew Morton

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/20220706235936.2197195-18-zokeefe@google.comSigned-off-by: default avatarZach O'Keefe <zokeefe@google.com>
Cc: Alex Shi <alex.shi@linux.alibaba.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Chris Kennelly <ckennelly@google.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Hugh Dickins <hughd@google.com>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Pavel Begunkov <asml.silence@gmail.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: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Yang Shi <shy828301@gmail.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Cc: "Souptick Joarder (HPE)" <jrdr.linux@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 9330694d
......@@ -990,6 +990,36 @@ static void collapse_max_ptes_shared(struct collapse_context *c)
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...");
/*
* Note that we don't set MADV_HUGEPAGE here, which
* also tests that VM_HUGEPAGE isn't required for
* MADV_COLLAPSE in "madvise" mode.
*/
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);
}
int main(int argc, const char **argv)
{
struct collapse_context c;
......@@ -1057,6 +1087,7 @@ int main(int argc, const char **argv)
collapse_fork(&c);
collapse_fork_compound(&c);
collapse_max_ptes_shared(&c);
madvise_collapse_existing_thps();
}
restore_settings(0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment