From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: Barry Song <21cnbao@gmail.com>
Cc: "David Hildenbrand (Arm)" <david@kernel.org>,
Pedro Falcato <pfalcato@suse.de>,
akpm@linux-foundation.org, ljs@kernel.org, riel@surriel.com,
liam@infradead.org, vbabka@kernel.org, harry@kernel.org,
jannh@google.com, lance.yang@linux.dev, qi.zheng@linux.dev,
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: Tue, 10 Nov 2026 11:48:19 +0800 [thread overview]
Message-ID: <3819fbff-d605-44ad-8217-b7d07956fee8@linux.alibaba.com> (raw)
In-Reply-To: <CAGsJ_4wGQ68vEhCS=6CAAr9K4O3Q2fazjpP8QSK2Zs3r6R4Wfg@mail.gmail.com>
On 11/9/26 12:27 PM, Barry Song wrote:
> On Mon, Nov 9, 2026 at 11:42 AM Baolin Wang
> <baolin.wang@linux.alibaba.com> wrote:
>>
>>
>>
>> On 11/8/26 3:58 AM, David Hildenbrand (Arm) wrote:
>>> On 11/6/26 03:12, Baolin Wang wrote:
>>>>
>>>>
>>>> On 11/5/26 7:37 PM, Pedro Falcato wrote:
>>>>> On Thu, Nov 05, 2026 at 10:56:28AM +0800, 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.
>>>>>
>>>>> This is very handwavy. Do you have numbers? Does this actually make sense?
>>>>
>>>> This is hard to measure in practice. But in theory, if we can't reclaim
>>>> cold large folios that are actually unmapped due to the racy checks, it
>>>> could cause cold/hot inversion (e.g., in MGLRU) and increase refaults.
>>>> In extreme cases, failing to reclaim unmapped large folios could even
>>>> cause OOM.
>>>
>>> Yeah, but the question is if it really matters in practice.
>>>
>>> I agree that page_mapped_in_vma() should sync properly, but the current impact
>>> might not be as severe.
>>
>> Yes, what I meant is the theoretical impact. In practice, this race is
>> not easy to trigger with no real reports so far, or the impact is tolerable.
>>
>> But I still think the fix is needed, as it matches the purpose of the
>> TTU_SYNC flag.
>
> I assume the impact comes from LRU over-protecting folios
> that remain mapped after try_to_unmap().
> try_to_unmap(folio, flags);
> if (folio_mapped(folio)) {
> stat->nr_unmap_fail += nr_pages;
> if (!was_swapbacked &&
> folio_test_swapbacked(folio))
> stat->nr_lazyfree_fail += nr_pages;
> goto activate_locked;
> }
>
> folios are activated - over protected in LRU.
>
> The racy window should be quite small in theory, so the
> impact might not be that severe. There is no evidence
> that it could lead to OOM.
>
> For large folios, the impact could be greater because
> we are over-protecting more memory, potentially
> increasing with the folio order. For small folios, we
> are only over-protecting a single 4KB page.
Agree.
> So perhaps the current TTU_SYNC flag for large folios
> is reasonable. Baolin's patch to respect the flag,
> which currently applies to large folios, also seems
> reasonable, as long as we don't extend it to small
> folios and introduce regressions, possibly in
> map_pte()?
>
> I'm also wondering whether we should downgrade
> ACTIVATE to KEEP, which would allow racy folios to be
> reclaimed sooner.
>
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 071a6eaef1a1..726266e49533 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -1353,7 +1353,7 @@ static unsigned int shrink_folio_list(struct
> list_head *folio_list,
> if (!was_swapbacked &&
> folio_test_swapbacked(folio))
> stat->nr_lazyfree_fail += nr_pages;
> - goto activate_locked;
> + goto keep_locked;
> }
> }
Sounds reasonable to me. It's also not easy to measure the impact. As
mentioned earlier, this kind of racy check scenario probably doesn't
have much impact anyway.
prev parent reply other threads:[~2026-11-10 3:48 UTC|newest]
Thread overview: 26+ 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-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 [this message]
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=3819fbff-d605-44ad-8217-b7d07956fee8@linux.alibaba.com \
--to=baolin.wang@linux.alibaba.com \
--cc=21cnbao@gmail.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®