From: Dev Jain <dev.jain@arm.com>
To: ryan.roberts@arm.com, david@redhat.com,
kirill.shutemov@linux.intel.com, willy@infradead.org,
ziy@nvidia.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [QUESTION] anon_vma lock in khugepaged
Date: Thu, 5 Dec 2024 15:40:08 +0530 [thread overview]
Message-ID: <ea15f3d3-5dd8-4404-8dab-5673bb5f3413@arm.com> (raw)
In-Reply-To: <20241128062641.59096-1-dev.jain@arm.com>
On 28/11/24 11:56 am, Dev Jain wrote:
> Hi, I was looking at khugepaged code and I cannot figure out what will the problem be
> if we take the mmap lock in read mode. Shouldn't just taking the PMD lock, then PTL,
> then unlocking PTL, then unlocking PMD, solve any races with page table walkers?
>
>
Similar questions:
1. Why do we need anon_vma_lock_write() in collapse_huge_page()? AFAIK we need to walk anon_vma's either
when we are forking or when we are unmapping a folio and need to find all VMAs mapping it; the former path takes the
mmap_write_lock() and so we have no problem, and for the latter, if we just had anon_vma_lock_read(), then it
may happen that kswapd isolates folio from LRU, and traverses rmap and swaps the folio out and khugepaged fails in
folio_isolate_lru(), but then that is not a fatal problem but just a performance degradation due to a race (wherein
the entire code is racy anyways). What am I missing?
2. In what all scenarios does rmap come into play? Fork, swapping out, any other I am missing?
3. Please confirm the correctness: In stark contrast to page migration, we do not need to do rmap walk and nuke all
PTEs referencing the folio, because for anon non-shmem folios, the only way the folio can be shared is forking,
and, if that is the case, folio_put() will not release the folio in __collapse_huge_page_copy_succeeded() -> free_page_and_swap_cache(),
so the old folio is still there and child processes can read from it. Page migration requires that we are able
to deallocate the old folios.
next prev parent reply other threads:[~2024-12-05 10:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20241128062641.59096-1-dev.jain@arm.com>
[not found] ` <d8d29152-ce3f-406d-9e95-a0e8ea2eabbf@redhat.com>
[not found] ` <4cb26a06-d982-4ca3-a5f7-7c6a6c63428c@arm.com>
[not found] ` <3d4c57dd-0821-4684-9018-db8274c170ec@redhat.com>
2024-11-29 7:10 ` [QUESTION] mmap " Dev Jain
2024-11-29 11:30 ` David Hildenbrand
2024-12-02 9:54 ` Dev Jain
2024-12-05 10:10 ` Dev Jain [this message]
2024-12-05 10:53 ` [QUESTION] anon_vma " David Hildenbrand
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=ea15f3d3-5dd8-4404-8dab-5673bb5f3413@arm.com \
--to=dev.jain@arm.com \
--cc=david@redhat.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ryan.roberts@arm.com \
--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