mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: Barry Song <baohua@kernel.org>
Cc: Lance Yang <lance.yang@linux.dev>,
	akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org,
	riel@surriel.com, liam@infradead.org, vbabka@kernel.org,
	harry@kernel.org, jannh@google.com, 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: Fri, 6 Nov 2026 21:56:26 +0800	[thread overview]
Message-ID: <3c0185d0-ed2c-458e-bbcc-cd35070ec743@linux.alibaba.com> (raw)
In-Reply-To: <CAGsJ_4zLiwYf6LM_BWoZyiYWxvW2H_siZ0QC7FmEHazF_fLa6g@mail.gmail.com>



On 11/6/26 5:56 PM, Barry Song wrote:
> On Fri, Nov 6, 2026 at 4:55 PM Baolin Wang
> <baolin.wang@linux.alibaba.com> wrote:
> [...]
>>>>> Ouch ... one thing I missed ... what about order-0 reclaim?
>>>>>
>>>>> shrink_folio_list() only sets TTU_SYNC for large folio, so can't we still
>>>>> hit the same race there?
>>>>
>>>> Thanks Lance. But this matches the purpose of the TTU_SYNC flag, which
>>>> is used to avoid racy checks with PVMW_SYNC. If no TTU_SYNC flag is set,
>>>> it means the caller can tolerate some racy checks.
>>>>
>>>> For this case, I think we should set TTU_SYNC unconditionally in
>>>> shrink_folio_list(). Barry, what do you think?
>>>
>>> Baolin, thanks for reaching out to me. I added that flag
>>> mainly for large folios.
>>>
>>> I observed cases where PTEs for large folios are partially
>>> cleared during certain transition states, for example, when
>>> PTEs are cleared before being modified:
>>>
>>> pte = ptep_get_and_clear();
>>> pte modification;
>>> set_pte_at();
>>>
>>> In such cases, page_vma_mapped_walk() skips the empty
>>> entries and starts from the next valid one.
>>>
>>> This may result in partially unmapping PTEs for large folios
>>> and trigger unexpected folio splits. At the time, I was
>>> particularly concerned about unnecessary folio splitting,
>>> so my focus was mainly on large folios.
>>
>> Thanks for the information.
>>
>>> However, I also noticed that a similar race can occur with
>>> small folios. In that case, the folio may simply remain
>>> unreclaimed by the reclamation path.
>>>
>>> However, my main concern at the time was avoiding
>>> unnecessary folio splits.
>>>
>>> Your new race also seems to amplify the same situation.
>>> However, I don't think this problem necessarily depends on
>>> the commit you mentioned. It has been around for a long time.
>>
>> Agree.
>>
>>> If the concern is reclaim failure, I agree that there is no
>>> fundamental difference between large folios and small folios.
>>
>> OK. And I did a quick measurement to reclaim anon and file folios via
>> the memory.reclaim interface.
>>
>>   From test results, reclaiming 1G small anonymous folios (using zram as
>> swap) shows no significant performance change. However, reclaiming 1G
>> mapped clean small file folios does show an observable regression if the
>> TTU_SYNC flag is set.
>>
>> Without TTU_SYNC for small folios:
>> time echo 1G > /sys/fs/cgroup/test/memory.reclaim
>> real    0m0.178s
>> user    0m0.000s
>> sys     0m0.178s
>>
>> With TTU_SYNC for small folios:
>> real    0m0.315s
>> user    0m0.000s
>> sys     0m0.314s
>>
>> So for the current patch, I'd prefer to keep things as is: only sync
>> when TTU_SYNC is set. Without setting the TTU_SYNC flag, keep the
>> original logic, meaning the caller can tolerate some racy checks.
>>
>> Any other thoughts?
> 
> I'm still struggling to understand where the regression comes
> from. You're doing echo 1G > /sys/fs/cgroup/test/memory.reclaim
> without the concurrent CPU 1 (MADV_DONTNEED) operation that
> causes the race.
> 
> so the regression actually comes from other places, maybe here?

Yes, I think so. But I haven't had time to dig into how this affects my 
tests yet. I'll dig into this later.

  reply	other threads:[~2026-11-06 13:56 UTC|newest]

Thread overview: 21+ 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-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 [this message]
2026-11-05 11:37 ` Pedro Falcato
2026-11-06  2:12   ` Baolin Wang

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=3c0185d0-ed2c-458e-bbcc-cd35070ec743@linux.alibaba.com \
    --to=baolin.wang@linux.alibaba.com \
    --cc=akpm@linux-foundation.org \
    --cc=ayushr@modal.com \
    --cc=baohua@kernel.org \
    --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®