[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <65f70e95ec7ee2980f715f625151a8fc333832b5.1746305604.git.lorenzo.stoakes@oracle.com>
Date: Sat, 3 May 2025 22:12:31 +0100
From: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: Vlastimil Babka <vbabka@...e.cz>, Jann Horn <jannh@...gle.com>,
"Liam R . Howlett" <Liam.Howlett@...cle.com>,
Suren Baghdasaryan <surenb@...gle.com>,
Matthew Wilcox <willy@...radead.org>,
David Hildenbrand <david@...hat.com>, Pedro Falcato <pfalcato@...e.de>,
Rik van Riel <riel@...riel.com>, Harry Yoo <harry.yoo@...cle.com>,
Zi Yan <ziy@...dia.com>, Baolin Wang <baolin.wang@...ux.alibaba.com>,
Nico Pache <npache@...hat.com>, Ryan Roberts <ryan.roberts@....com>,
Dev Jain <dev.jain@....com>, Jakub Matena <matenajakub@...il.com>,
Wei Yang <richard.weiyang@...il.com>, linux-mm@...ck.org,
linux-kernel@...r.kernel.org
Subject: [RFC PATCH v3 09/11] tools/testing/selftests: have CoW self test use MREMAP_RELOCATE_ANON
It is useful to have the CoW self-test invoke MREMAP_RELOCATE_ANON on
partial THP mappings, as this triggers folio split code paths and asserts
that this behaves correctly.
Add an additional set of tests to explicitly do so.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
---
tools/testing/selftests/mm/cow.c | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c
index b6cfe0a4b7df..1770ebc3aa13 100644
--- a/tools/testing/selftests/mm/cow.c
+++ b/tools/testing/selftests/mm/cow.c
@@ -793,13 +793,14 @@ enum thp_run {
THP_RUN_SINGLE_PTE,
THP_RUN_SINGLE_PTE_SWAPOUT,
THP_RUN_PARTIAL_MREMAP,
+ THP_RUN_PARTIAL_MREMAP_RELOCATE_ANON,
THP_RUN_PARTIAL_SHARED,
};
static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize)
{
char *mem, *mmap_mem, *tmp, *mremap_mem = MAP_FAILED;
- size_t size, mmap_size, mremap_size;
+ size_t size, mmap_size, mremap_size, mremap_flags;
int ret;
/* For alignment purposes, we need twice the thp size. */
@@ -869,6 +870,7 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize)
size = pagesize;
break;
case THP_RUN_PARTIAL_MREMAP:
+ case THP_RUN_PARTIAL_MREMAP_RELOCATE_ANON:
/*
* Remap half of the THP. We need some new memory location
* for that.
@@ -880,8 +882,13 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize)
ksft_test_result_fail("mmap() failed\n");
goto munmap;
}
- tmp = mremap(mem + mremap_size, mremap_size, mremap_size,
- MREMAP_MAYMOVE | MREMAP_FIXED, mremap_mem);
+
+ mremap_flags = MREMAP_MAYMOVE | MREMAP_FIXED;
+ if (thp_run == THP_RUN_PARTIAL_MREMAP_RELOCATE_ANON)
+ mremap_flags |= MREMAP_RELOCATE_ANON;
+
+ tmp = sys_mremap(mem + mremap_size, mremap_size, mremap_size,
+ mremap_flags, mremap_mem);
if (tmp != mremap_mem) {
ksft_test_result_fail("mremap() failed\n");
goto munmap;
@@ -988,6 +995,13 @@ static void run_with_partial_mremap_thp(test_fn fn, const char *desc, size_t siz
do_run_with_thp(fn, THP_RUN_PARTIAL_MREMAP, size);
}
+static void run_with_partial_mremap_relocate_anon_thp(test_fn fn, const char *desc, size_t size)
+{
+ ksft_print_msg("[RUN] %s ... with partially mremap(MREMAP_RELOCATE_ANON)'ed THP (%zu kB)\n",
+ desc, size / 1024);
+ do_run_with_thp(fn, THP_RUN_PARTIAL_MREMAP_RELOCATE_ANON, size);
+}
+
static void run_with_partial_shared_thp(test_fn fn, const char *desc, size_t size)
{
ksft_print_msg("[RUN] %s ... with partially shared THP (%zu kB)\n",
@@ -1181,6 +1195,7 @@ static void run_anon_test_case(struct test_case const *test_case)
run_with_single_pte_of_thp(test_case->fn, test_case->desc, size);
run_with_single_pte_of_thp_swap(test_case->fn, test_case->desc, size);
run_with_partial_mremap_thp(test_case->fn, test_case->desc, size);
+ run_with_partial_mremap_relocate_anon_thp(test_case->fn, test_case->desc, size);
run_with_partial_shared_thp(test_case->fn, test_case->desc, size);
thp_pop_settings();
@@ -1204,7 +1219,7 @@ static int tests_per_anon_test_case(void)
{
int tests = 2 + nr_hugetlbsizes;
- tests += 6 * nr_thpsizes;
+ tests += 7 * nr_thpsizes;
if (pmdsize)
tests += 2;
return tests;
--
2.49.0
Powered by blists - more mailing lists