From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Vlastimil Babka <vbabka@suse.cz>, Jann Horn <jannh@google.com>,
"Liam R . Howlett" <Liam.Howlett@oracle.com>,
Suren Baghdasaryan <surenb@google.com>,
Matthew Wilcox <willy@infradead.org>,
David Hildenbrand <david@redhat.com>,
Pedro Falcato <pfalcato@suse.de>, Rik van Riel <riel@surriel.com>,
Harry Yoo <harry.yoo@oracle.com>, Zi Yan <ziy@nvidia.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Nico Pache <npache@redhat.com>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Jakub Matena <matenajakub@gmail.com>,
Wei Yang <richard.weiyang@gmail.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH v3 09/11] tools/testing/selftests: have CoW self test use MREMAP_RELOCATE_ANON
Date: Sat, 3 May 2025 22:12:31 +0100 [thread overview]
Message-ID: <65f70e95ec7ee2980f715f625151a8fc333832b5.1746305604.git.lorenzo.stoakes@oracle.com> (raw)
In-Reply-To: <cover.1746305604.git.lorenzo.stoakes@oracle.com>
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@oracle.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
next prev parent reply other threads:[~2025-05-03 21:13 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-03 21:12 [RFC PATCH v3 00/11] mm/mremap: introduce more mergeable mremap via MREMAP_RELOCATE_ANON Lorenzo Stoakes
2025-05-03 21:12 ` [RFC PATCH v3 01/11] " Lorenzo Stoakes
2025-05-03 21:12 ` [RFC PATCH v3 02/11] mm/mremap: add MREMAP_MUST_RELOCATE_ANON Lorenzo Stoakes
2025-05-03 21:12 ` [RFC PATCH v3 03/11] mm/mremap: add MREMAP[_MUST]_RELOCATE_ANON support for large folios Lorenzo Stoakes
2025-05-03 21:12 ` [RFC PATCH v3 04/11] tools UAPI: Update copy of linux/mman.h from the kernel sources Lorenzo Stoakes
2025-05-03 21:12 ` [RFC PATCH v3 05/11] tools/testing/selftests: add sys_mremap() helper to vm_util.h Lorenzo Stoakes
2025-05-03 21:12 ` [RFC PATCH v3 06/11] tools/testing/selftests: add mremap() cases that merge normally Lorenzo Stoakes
2025-05-03 21:12 ` [RFC PATCH v3 07/11] tools/testing/selftests: add MREMAP_RELOCATE_ANON merge test cases Lorenzo Stoakes
2025-05-03 21:12 ` [RFC PATCH v3 08/11] tools/testing/selftests: expand mremap() tests for MREMAP_RELOCATE_ANON Lorenzo Stoakes
2025-05-03 21:12 ` Lorenzo Stoakes [this message]
2025-05-03 21:12 ` [RFC PATCH v3 10/11] tools/testing/selftests: test relocate anon in split huge page test Lorenzo Stoakes
2025-05-03 21:12 ` [RFC PATCH v3 11/11] tools/testing/selftests: add MREMAP_RELOCATE_ANON fork tests Lorenzo Stoakes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=65f70e95ec7ee2980f715f625151a8fc333832b5.1746305604.git.lorenzo.stoakes@oracle.com \
--to=lorenzo.stoakes@oracle.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@redhat.com \
--cc=dev.jain@arm.com \
--cc=harry.yoo@oracle.com \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=matenajakub@gmail.com \
--cc=npache@redhat.com \
--cc=pfalcato@suse.de \
--cc=richard.weiyang@gmail.com \
--cc=riel@surriel.com \
--cc=ryan.roberts@arm.com \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox