* selftests/mm/rmap: verify correct RMAP handling of COW pages after fork()
@ 2025-10-15 8:43 Itamar Dalal
2025-10-15 8:49 ` David Hildenbrand
0 siblings, 1 reply; 5+ messages in thread
From: Itamar Dalal @ 2025-10-15 8:43 UTC (permalink / raw)
To: linux-mm, linux-kselftest, linux-kernel, akpm, david,
lorenzo.stoakes, riel, Liam.Howlett, vbabka, harry.yoo, jannh,
rppt, surenb, mhocko, shuah
Add a new test `migrate.cow_after_fork` that verifies correct RMAP handling
of Copy-On-Write (COW) pages after fork().
Before a write, the parent and child share the same PFN. After a write, the
child’s PFN differs. This confirms that proper COW duplication occurred and
that RMAP correctly tracks page ownership transitions during COW events.
Signed-off-by: Itamar-Dalal <dalalitamar@gmail.com>
---
tools/testing/selftests/mm/rmap.c | 45 ++++++++++++++++++++++++++++++-
1 file changed, 44 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/rmap.c b/tools/testing/selftests/mm/rmap.c
index 13f7bccfd0a9..2ba3361fecf0 100644
--- a/tools/testing/selftests/mm/rmap.c
+++ b/tools/testing/selftests/mm/rmap.c
@@ -430,4 +430,47 @@ TEST_F(migrate, ksm)
propagate_children(_metadata, data);
}
-TEST_HARNESS_MAIN
+TEST_F(migrate, cow_after_fork)
+{
+ struct global_data *data = &self->data;
+ int status;
+ pid_t pid;
+ unsigned long parent_pfn, child_pfn;
+ int pagemap_fd;
+ char *region;
+
+ /* Map private anonymous memory and fault it in */
+ region = mmap(NULL, data->mapsize, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ ASSERT_NE(region, MAP_FAILED);
+ memset(region, 0xaa, data->mapsize);
+
+ pagemap_fd = open("/proc/self/pagemap", O_RDONLY);
+ ASSERT_NE(pagemap_fd, -1);
+ parent_pfn = pagemap_get_pfn(pagemap_fd, region);
+ close(pagemap_fd);
+
+ pid = fork();
+ ASSERT_NE(pid, -1);
+
+ if (pid == 0) {
+ /* Child: write to trigger COW */
+ region[0] = 0xbb;
+
+ pagemap_fd = open("/proc/self/pagemap", O_RDONLY);
+ ASSERT_NE(pagemap_fd, -1);
+ child_pfn = pagemap_get_pfn(pagemap_fd, region);
+ close(pagemap_fd);
+
+ /* Expect PFN to differ after write (COW happened) */
+ if (child_pfn == parent_pfn)
+ _exit(FAIL_ON_CHECK);
+ _exit(0);
+ }
+
+ waitpid(pid, &status, 0);
+ ASSERT_EQ(WEXITSTATUS(status), 0);
+ munmap(region, data->mapsize);
+}
+
+TEST_HARNESS_MAIN
\ No newline at end of file
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: selftests/mm/rmap: verify correct RMAP handling of COW pages after fork()
2025-10-15 8:43 selftests/mm/rmap: verify correct RMAP handling of COW pages after fork() Itamar Dalal
@ 2025-10-15 8:49 ` David Hildenbrand
2025-10-15 9:02 ` Mike Rapoport
0 siblings, 1 reply; 5+ messages in thread
From: David Hildenbrand @ 2025-10-15 8:49 UTC (permalink / raw)
To: Itamar Dalal, linux-mm, linux-kselftest, linux-kernel, akpm,
lorenzo.stoakes, riel, Liam.Howlett, vbabka, harry.yoo, jannh,
rppt, surenb, mhocko, shuah
On 15.10.25 10:43, Itamar Dalal wrote:
> Add a new test `migrate.cow_after_fork` that verifies correct RMAP handling
> of Copy-On-Write (COW) pages after fork().
>
> Before a write, the parent and child share the same PFN. After a write, the
> child’s PFN differs. This confirms that proper COW duplication occurred and
> that RMAP correctly tracks page ownership transitions during COW events.
>
> Signed-off-by: Itamar-Dalal <dalalitamar@gmail.com>
> ---
Se my reply to your other patch.
For the next time
a) Use git-format-patch that will automatically add [PATCH]
b) Use versioning, e.g., [PATCH v1], explain changes since the last
version under the "---" the
c) Use RESEND for resends, e.g., [PATCH v1 RESEND]
d) Use git-send-email to send mails out
The b4 tool might help as well.
--
Cheers
David / dhildenb
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: selftests/mm/rmap: verify correct RMAP handling of COW pages after fork()
2025-10-15 8:49 ` David Hildenbrand
@ 2025-10-15 9:02 ` Mike Rapoport
0 siblings, 0 replies; 5+ messages in thread
From: Mike Rapoport @ 2025-10-15 9:02 UTC (permalink / raw)
To: David Hildenbrand
Cc: Itamar Dalal, linux-mm, linux-kselftest, linux-kernel, akpm,
lorenzo.stoakes, riel, Liam.Howlett, vbabka, harry.yoo, jannh,
surenb, mhocko, shuah
On Wed, Oct 15, 2025 at 10:49:48AM +0200, David Hildenbrand wrote:
> On 15.10.25 10:43, Itamar Dalal wrote:
> > Add a new test `migrate.cow_after_fork` that verifies correct RMAP handling
> > of Copy-On-Write (COW) pages after fork().
> >
> > Before a write, the parent and child share the same PFN. After a write, the
> > child’s PFN differs. This confirms that proper COW duplication occurred and
> > that RMAP correctly tracks page ownership transitions during COW events.
> >
> > Signed-off-by: Itamar-Dalal <dalalitamar@gmail.com>
> > ---
>
> Se my reply to your other patch.
>
> For the next time
>
> a) Use git-format-patch that will automatically add [PATCH]
>
> b) Use versioning, e.g., [PATCH v1], explain changes since the last version
> under the "---" the
>
> c) Use RESEND for resends, e.g., [PATCH v1 RESEND]
>
> d) Use git-send-email to send mails out
>
> The b4 tool might help as well.
And
e) please don't respin new version as soon as you get a single feedback.
https://docs.kernel.org/process/submitting-patches.html#don-t-get-discouraged-or-impatient
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: selftests/mm/rmap: verify correct RMAP handling of COW pages after fork()
2025-10-15 8:33 Itamar Dalal
@ 2025-10-15 8:47 ` David Hildenbrand
0 siblings, 0 replies; 5+ messages in thread
From: David Hildenbrand @ 2025-10-15 8:47 UTC (permalink / raw)
To: Itamar Dalal, linux-mm, linux-kselftest, linux-kernel, akpm,
lorenzo.stoakes, riel, Liam.Howlett, vbabka, harry.yoo, jannh,
rppt, surenb, mhocko, shuah
On 15.10.25 10:33, Itamar Dalal wrote:
> Add a new test `migrate.cow_after_fork` that verifies correct RMAP handling
> of Copy-On-Write (COW) pages after fork().
>
> Before a write, the parent and child share the same PFN. After a write, the
> child’s PFN differs. This confirms that proper COW duplication occurred and
> that RMAP correctly tracks page ownership transitions during COW events.
>
> Signed-off-by: Itamar-Dalal <dalalitamar@gmail.com
> <mailto:dalalitamar@gmail.com>>
> ---
> tools/testing/selftests/mm/rmap.c | 45 ++++++++++++++++++++++++++++++-
> 1 file changed, 44 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/mm/rmap.c b/tools/testing/
> selftests/mm/rmap.c
> index 13f7bccfd0a9..2ba3361fecf0 100644
> --- a/tools/testing/selftests/mm/rmap.c
> +++ b/tools/testing/selftests/mm/rmap.c
> @@ -430,4 +430,47 @@ TEST_F(migrate, ksm)
> propagate_children(_metadata, data);
> }
>
> -TEST_HARNESS_MAIN
> +TEST_F(migrate, cow_after_fork)
> +{
> + struct global_data *data = &self->data;
> + int status;
> + pid_t pid;
> + unsigned long parent_pfn, child_pfn;
> + int pagemap_fd;
> + char *region;
> +
> + /* Map private anonymous memory and fault it in */
> + region = mmap(NULL, data->mapsize, PROT_READ | PROT_WRITE,
> + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> + ASSERT_NE(region, MAP_FAILED);
> + memset(region, 0xaa, data->mapsize);
> +
> + pagemap_fd = open("/proc/self/pagemap", O_RDONLY);
> + ASSERT_NE(pagemap_fd, -1);
> + parent_pfn = pagemap_get_pfn(pagemap_fd, region);
> + close(pagemap_fd);
> +
> + pid = fork();
> + ASSERT_NE(pid, -1);
> +
> + if (pid == 0) {
> + /* Child: write to trigger COW */
> + region[0] = 0xbb;
> +
> + pagemap_fd = open("/proc/self/pagemap", O_RDONLY);
> + ASSERT_NE(pagemap_fd, -1);
> + child_pfn = pagemap_get_pfn(pagemap_fd, region);
> + close(pagemap_fd);
> +
> + /* Expect PFN to differ after write (COW happened) */
> + if (child_pfn == parent_pfn)
> + _exit(FAIL_ON_CHECK);
> + _exit(0);
> + }
> +
> + waitpid(pid, &status, 0);
> + ASSERT_EQ(WEXITSTATUS(status), 0);
> + munmap(region, data->mapsize);
> +}
We have excessive cow tests in cow.c, that are independent of any PFN
checks.
So I don't think we need this.
BTW, I never received a mail that shows up right-aligned in my mail client.
Seems to be because of
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"rtl"
The whole attachment should be dropped. Did you send this with
git-send-email? :)
--
Cheers
David / dhildenb
^ permalink raw reply [flat|nested] 5+ messages in thread
* selftests/mm/rmap: verify correct RMAP handling of COW pages after fork()
@ 2025-10-15 8:33 Itamar Dalal
2025-10-15 8:47 ` David Hildenbrand
0 siblings, 1 reply; 5+ messages in thread
From: Itamar Dalal @ 2025-10-15 8:33 UTC (permalink / raw)
To: linux-mm, linux-kselftest, linux-kernel, akpm, david,
lorenzo.stoakes, riel, Liam.Howlett, vbabka, harry.yoo, jannh,
rppt, surenb, mhocko, shuah
[-- Attachment #1: Type: text/plain, Size: 2322 bytes --]
Add a new test `migrate.cow_after_fork` that verifies correct RMAP handling
of Copy-On-Write (COW) pages after fork().
Before a write, the parent and child share the same PFN. After a write, the
child’s PFN differs. This confirms that proper COW duplication occurred and
that RMAP correctly tracks page ownership transitions during COW events.
Signed-off-by: Itamar-Dalal <dalalitamar@gmail.com>
---
tools/testing/selftests/mm/rmap.c | 45 ++++++++++++++++++++++++++++++-
1 file changed, 44 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/rmap.c
b/tools/testing/selftests/mm/rmap.c
index 13f7bccfd0a9..2ba3361fecf0 100644
--- a/tools/testing/selftests/mm/rmap.c
+++ b/tools/testing/selftests/mm/rmap.c
@@ -430,4 +430,47 @@ TEST_F(migrate, ksm)
propagate_children(_metadata, data);
}
-TEST_HARNESS_MAIN
+TEST_F(migrate, cow_after_fork)
+{
+ struct global_data *data = &self->data;
+ int status;
+ pid_t pid;
+ unsigned long parent_pfn, child_pfn;
+ int pagemap_fd;
+ char *region;
+
+ /* Map private anonymous memory and fault it in */
+ region = mmap(NULL, data->mapsize, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ ASSERT_NE(region, MAP_FAILED);
+ memset(region, 0xaa, data->mapsize);
+
+ pagemap_fd = open("/proc/self/pagemap", O_RDONLY);
+ ASSERT_NE(pagemap_fd, -1);
+ parent_pfn = pagemap_get_pfn(pagemap_fd, region);
+ close(pagemap_fd);
+
+ pid = fork();
+ ASSERT_NE(pid, -1);
+
+ if (pid == 0) {
+ /* Child: write to trigger COW */
+ region[0] = 0xbb;
+
+ pagemap_fd = open("/proc/self/pagemap", O_RDONLY);
+ ASSERT_NE(pagemap_fd, -1);
+ child_pfn = pagemap_get_pfn(pagemap_fd, region);
+ close(pagemap_fd);
+
+ /* Expect PFN to differ after write (COW happened) */
+ if (child_pfn == parent_pfn)
+ _exit(FAIL_ON_CHECK);
+ _exit(0);
+ }
+
+ waitpid(pid, &status, 0);
+ ASSERT_EQ(WEXITSTATUS(status), 0);
+ munmap(region, data->mapsize);
+}
+
+TEST_HARNESS_MAIN
\ No newline at end of file
--
2.34.1
[-- Attachment #2: Type: text/html, Size: 2717 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-10-15 9:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-15 8:43 selftests/mm/rmap: verify correct RMAP handling of COW pages after fork() Itamar Dalal
2025-10-15 8:49 ` David Hildenbrand
2025-10-15 9:02 ` Mike Rapoport
-- strict thread matches above, loose matches on Subject: below --
2025-10-15 8:33 Itamar Dalal
2025-10-15 8:47 ` David Hildenbrand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox