From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: "David Hildenbrand (Arm)" <david@kernel.org>,
akpm@linux-foundation.org, ljs@kernel.org
Cc: riel@surriel.com, liam@infradead.org, vbabka@kernel.org,
harry@kernel.org, jannh@google.com, lance.yang@linux.dev,
qi.zheng@linux.dev, pfalcato@suse.de, ayushr@modal.com,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: synchronize with PTE table reclaim for all folio sizes
Date: Mon, 16 Nov 2026 21:34:53 +0800 [thread overview]
Message-ID: <01d59bbc-46d4-4da2-805c-bf540d50eb37@linux.alibaba.com> (raw)
In-Reply-To: <9e66d5f7-ee81-4204-8d62-b06d26a00623@kernel.org>
On 11/16/26 8:03 PM, David Hildenbrand (Arm) wrote:
> On 11/16/26 04:44, Baolin Wang wrote:
>>
>>
>> On 11/14/26 1:39 AM, David Hildenbrand (Arm) wrote:
>>> On 11/5/26 03:56, Baolin Wang wrote:
>>>> Similar to commit 243cf1f67b36 ("mm: memory: fix truncation removing mapped
>>>> folios"), the '!pmd_present()' check in page_vma_mapped_walk() can also race
>>>> with concurrent page table reclamation via zap_empty_pte_table().
>>>>
>>>> page_vma_mapped_walk() is used by many functions including try_to_unmap(),
>>>> try_to_migrate(), folio_mkclean(), pfn_mkclean_range(), remove_migration_ptes(),
>>>> page_mapped_in_vma(), and mapping_wrprotect_range(). Except for try_to_unmap()
>>>> and try_to_migrate(), the other callers do not perform post-walk accounting
>>>> checks, so the race has no observable impact on them.
>>>>
>>>> For migration, the race can cause unnecessary retries. For reclaim via
>>>> try_to_unmap(), the race can cause failure to reclaim a folio that is in
>>>> fact already unmapped (as shown below), which may lead to unexpected OOM
>>>> or increased refaults.
>>>>
>>>> CPU 0 (reclaim) CPU 1 (MADV_DONTNEED)
>>>> -------------------------------- --------------------------------
>>>> folio_lock(F)
>>>> try_to_unmap(F, TTU_SYNC)
>>>> zap_pte_range(full PMD range)
>>>> spin_lock(ptl)
>>>> clear PTEs
>>>> zap_empty_pte_table()
>>>> spin_trylock(pml)
>>>> pmd_clear()
>>>> spin_unlock(pml)
>>>>
>>>> page_vma_mapped_walk()
>>>> observe !pmd_present(pmde)
>>>> nr_pages < HPAGE_PMD_NR
>>>> skip synchronization
>>>> return false
>>>>
>>>> try_to_unmap() returns
>>>> folio_mapped(F) == true
>>>> nr_unmap_fail += folio_nr_pages(F)
>>>> tlb_flush_mmu_tlbonly()
>>>> tlb_flush_rmaps()
>>>> remove F's rmaps
>>>> spin_unlock(ptl)
>>>>
>>>> Commit 243cf1f67b36 ("mm: memory: fix truncation removing mapped folios")
>>>> has already moved the PMD clear operation (via zap_empty_pte_table()) to
>>>> after tlb_flush_rmaps(). Similarly, page_vma_mapped_walk() also needs to
>>>> use sync_with_folio_pmd_zap() to synchronize and avoid memory ordering
>>>> issues on weakly ordered CPUs.
>>>>
>>>> Fixes: 6375e95f381e ("mm: pgtable: reclaim empty PTE page in madvise(MADV_DONTNEED)")
>>>> Cc: stable@vger.kernel.org
>>>> Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
>>>> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>>>> ---
>>>> mm/page_vma_mapped.c | 5 +----
>>>> 1 file changed, 1 insertion(+), 4 deletions(-)
>>>>
>>>> diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c
>>>> index e6b6170c2f4f..8797467b6f0c 100644
>>>> --- a/mm/page_vma_mapped.c
>>>> +++ b/mm/page_vma_mapped.c
>>>> @@ -293,10 +293,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
>>>> spin_unlock(pvmw->ptl);
>>>> pvmw->ptl = NULL;
>>>> } else if (!pmd_present(pmde)) {
>>>> - if ((pvmw->flags & PVMW_SYNC) &&
>>>> - thp_vma_suitable_order(vma, pvmw->address,
>>>> - PMD_ORDER) &&
>>>> - (pvmw->nr_pages >= HPAGE_PMD_NR))
>>>> + if (pvmw->flags & PVMW_SYNC)
>>>> sync_with_folio_pmd_zap(mm, pvmw->pmd);
>>>>
>>>> goto next_pmd;
>>>
>>> Baolin, how to proceed with that? Are you intending a resend? Including some of
>>> the performance impact and ways forward to optimize?
>>
>> I hope we can merge this fix first if no other objections. As I replied
>> to Barry, whether to set TTU_SYNC for small folios should be done in a
>> separate patch (this is a pre-existing issue) with proper measurement
>> (though it may be hard to measure the actual impact). What do you think?
>
> Can you update the patch description to include some of the performance aspects
> and planned next steps?
Sure.
However, regarding performance aspects, I'm not sure what kind of
testing you expect. Since this fixes a uncommon concurrent race, do you
want performance data under that race condition, or impact on common
paths like try_to_unmap/try_to_migrate()?
next prev parent reply other threads:[~2026-11-16 13:35 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 2:56 Baolin Wang
2026-11-05 3:22 ` Qi Zheng
2026-11-05 4:54 ` Lance Yang
2026-11-05 5:48 ` Lance Yang
2026-11-05 9:00 ` Baolin Wang
2026-11-05 10:06 ` David Hildenbrand (Arm)
2026-11-05 11:18 ` Baolin Wang
2026-11-05 13:22 ` Lance Yang
2026-11-05 19:35 ` David Hildenbrand (Arm)
2026-11-06 1:57 ` Baolin Wang
2026-11-06 2:33 ` Lance Yang
2026-11-06 2:54 ` Baolin Wang
2026-11-07 20:05 ` David Hildenbrand (Arm)
2026-11-06 6:24 ` Barry Song
2026-11-06 8:54 ` Baolin Wang
2026-11-06 9:15 ` Lance Yang
2026-11-06 9:29 ` Lance Yang
2026-11-06 9:50 ` Baolin Wang
2026-11-06 9:56 ` Barry Song
2026-11-06 13:56 ` Baolin Wang
2026-11-10 6:23 ` Baolin Wang
2026-11-10 8:54 ` Barry Song
2026-11-05 11:37 ` Pedro Falcato
2026-11-06 2:12 ` Baolin Wang
2026-11-07 19:58 ` David Hildenbrand (Arm)
2026-11-09 3:39 ` Baolin Wang
2026-11-09 4:27 ` Barry Song
2026-11-10 3:48 ` Baolin Wang
2026-11-13 17:39 ` David Hildenbrand (Arm)
2026-11-16 3:44 ` Baolin Wang
2026-11-16 12:03 ` David Hildenbrand (Arm)
2026-11-16 13:34 ` Baolin Wang [this message]
2026-11-16 14:09 ` David Hildenbrand (Arm)
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=01d59bbc-46d4-4da2-805c-bf540d50eb37@linux.alibaba.com \
--to=baolin.wang@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=ayushr@modal.com \
--cc=david@kernel.org \
--cc=harry@kernel.org \
--cc=jannh@google.com \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=pfalcato@suse.de \
--cc=qi.zheng@linux.dev \
--cc=riel@surriel.com \
--cc=vbabka@kernel.org \
/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
all inboxes | Powered by JetHome®