linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Wei Yang <richard.weiyang@gmail.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	akpm@linux-foundation.org, riel@surriel.com, vbabka@suse.cz,
	harry.yoo@oracle.com, jannh@google.com, baohua@kernel.org,
	linux-mm@kvack.org
Subject: Re: [RFC Patch 0/5] Make anon_vma operations testable
Date: Tue, 27 May 2025 13:31:47 +0200	[thread overview]
Message-ID: <40dc48f9-94d7-46b0-83ed-d3511789c15a@redhat.com> (raw)
In-Reply-To: <20250527063428.4ykrdtive2hfnqdp@master>

On 27.05.25 08:34, Wei Yang wrote:
> On Wed, May 14, 2025 at 01:23:18AM +0000, Wei Yang wrote:
>> On Wed, Apr 30, 2025 at 09:47:16AM +0200, David Hildenbrand wrote:
>> [...]
>>>>>> Agreed, skimming over the tests there are some nice diagrams and cases.
>>>>>>
>>>>>> But I would hope that for most of these cases we could test on a higher
>>>>>> level: test our expectations when running real programs that we want to
>>>>>> check, especially when performing internal changes on how we handle anon
>>>>>> memory + rmap.
>>>>>>
>>>>>> E.g., do fork(), then test if we can successfully perform rmap
>>>>>> lookups/updates (e.g., migrate folio to a different numa node etc).
>>>>>>
>>>>>
>>>>> That's a great point! Wei - if you could look at making some self-tests
>>>>> (i.e. that live in tools/testing/selftests/mm) that try to recreate _real_
>>>>> scenarios that use the rmap like this and assert correct behaviour there,
>>>>> that could be a positive way of moving forward with this.
>>>>>
>>>>
> 
> Ping

Thanks for reminding me and sorry for the late reply.

> 
>>>> I am trying to understand what scenarios you want.
>>>
>>
>> Sorry for the late reply, I handled other things a while.
>>
>>> That is exactly the task to figure out: how can we actually test our rmap
>>> implementation from a higher level. The example regarding fork and migration
>>> is possibly a low-hanging fruit.
>>
>> If my understanding is correct, you suggested two high level way:
>>
>> 1. fork + migrate (move_pages)

Yes, that should be one way of testing it. We could even get multiple 
child processes into place.

>>
>>>
>>> We might already have the functionality to achieve it, *maybe* we'd even want
>>> some extensions to make it all even easier to test.
>>>
>>> For example, MADV_PAGEOUT is refused on folios that are mapped into multiple
>>> processes. Maybe we'd want the option to *still* page it out, just like
>>> MPOL_MF_MOVE_ALL allows with CAP_SYS_NICE to *still* migrate a folio that is
>>> mapped into multiple processes.
>>>
>>
>> 2. madvise(MADV_PAGEOUT)
>>
>> Not fully get it here. You mean fork + madvise(MADV_PAGEOUT) + migrate ?

fork + madvise(MADV_PAGEOUT) only.

Then verify, that it was actually paged out.

For example, we could have 10 processes mapping the page, then call 
madvise(MADV_PAGEOUT) from one process. We can verify in all processes 
if the page is actually no longer mapped using /proc/self/pagemap

We could likely do it with anon pages (swap), shmem pages (swap) and 
pagecache pages (file backed).

... and possibly even with KSM pages!

>>
>> But we need to enable pageout in this way first.

Yes, madvise(MADV_PAGEOUT) needs to be extended to allow forcing a 
pageout (e.g., a new MADVISE_PAGEOUT_SHARED that only works with with 
CAP_SYY_ADMIN).

>>
>> I am not sure why this one is easier way to test. Would you mind sharing more
>> idea on this?

It might be easier than the migration case, because for migration we 
currently need 2 NUMA nodes ...

>>
>>> Some rmap tests could make sense for both, anon and pagecache folios.
>>>
>>>>
>>>> Something like below?
>>>>
>>>>     * fork and migrate a range in child
>>>>     * fork/unmap in parent and migrate a range in child
>>>>
>>>> If the operation is successful, then we are good, right?
>>>
>>> Yes. And one can come up with a bunch of similar rmap test cases, like doing
>>> a partial mremap() of a THP, then testing if the rmap walk still works as
>>> expected, pairing the whole thing with for etc.
>>>
>>
>> For both way, we could arrange all those scenarios and also do partial
>> mremap() during it.

Exactly.

>>
>>> One "problem" here is that even with MPOL_MF_MOVE_ALL,
>>> move_pages() will not move a folio if it already resides on the target node.
>>> So one always needs two NUMA nodes, which is a bit suboptimal for testing
>>> purposes.
>>>
>>> For testing purposes, it could have been helpful a couple of times already to
>>> just have a way of migrating a folio even if it already resides on the
>>> expected node.
>>>
>>
>> This looks we need a new flag for it?
>>
>> Here is my plan if my understanding is correct.
>>
>> 1. Add test cases for fork + migrate. We may limit it only works on machine
>>    with 2 NUMA nodes.
>> 2. Enable move_pages() on local node, then remove the test limitation
>> 3. Enable madvise(MADV_PAGEOUT) with multiple mapping, then add related cases
>> 4. Add mremap() or other cases
>>
>> In general, to verify rmap dose the work correctly, my idea is to
>>
>>   * mmap(MAP_SHARED)
 >>   * write some initial data before fork>>   * after fork and 
migrate, we write some different data to it
>>   * if each process do see the new data, rmap is good.

With pageout (see above) test, we can just verify using 
/proc/self/pagemap in all processes whether the page was paged out (IOW: 
the rmap was able to identify all page locations). And that should work 
with anon/shmem/file/ksm pages IIUC.

>>
>> Does it sound good to you?

Yes, that absolutely goes into the right direction. Having also rmap 
tests for KSM as raised above might be a real benefit.


-- 
Cheers,

David / dhildenb



  reply	other threads:[~2025-05-27 11:31 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-29  9:06 Wei Yang
2025-04-29  9:06 ` [RFC Patch 1/5] mm: move anon_vma manipulation functions to own file Wei Yang
2025-04-29  9:06 ` [RFC Patch 2/5] anon_vma: add skeleton code for userland testing of anon_vma logic Wei Yang
2025-05-01  1:31   ` Wei Yang
2025-05-01  9:41     ` Lorenzo Stoakes
2025-05-01 14:45       ` Wei Yang
2025-04-29  9:06 ` [RFC Patch 3/5] anon_vma: add test for mergeable anon_vma Wei Yang
2025-04-29  9:06 ` [RFC Patch 4/5] anon_vma: add test for reusable anon_vma Wei Yang
2025-04-29  9:06 ` [RFC Patch 5/5] anon_vma: add test to assert no double-reuse Wei Yang
2025-04-29  9:31 ` [RFC Patch 0/5] Make anon_vma operations testable Lorenzo Stoakes
2025-04-29  9:38   ` David Hildenbrand
2025-04-29  9:41     ` Lorenzo Stoakes
2025-04-29 23:56       ` Wei Yang
2025-04-30  7:47         ` David Hildenbrand
2025-04-30 15:44           ` Wei Yang
2025-04-30 21:36             ` David Hildenbrand
2025-05-14  1:23           ` Wei Yang
2025-05-27  6:34             ` Wei Yang
2025-05-27 11:31               ` David Hildenbrand [this message]
2025-05-28  1:17                 ` Wei Yang
2025-05-30  2:11                 ` Wei Yang
2025-05-30  8:00                   ` David Hildenbrand
2025-05-30 14:05                     ` Wei Yang
2025-05-30 14:39                       ` David Hildenbrand
2025-05-30 23:23                         ` Wei Yang
2025-06-03 21:31                           ` David Hildenbrand
2025-04-29 23:15   ` Wei Yang
2025-04-30 14:38     ` Lorenzo Stoakes
2025-04-30 15:41       ` Wei Yang

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=40dc48f9-94d7-46b0-83ed-d3511789c15a@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=harry.yoo@oracle.com \
    --cc=jannh@google.com \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=richard.weiyang@gmail.com \
    --cc=riel@surriel.com \
    --cc=vbabka@suse.cz \
    /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