From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Barry Song <baohua@kernel.org>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org, ljs@kernel.org,
baolin.wang@linux.alibaba.com, dev.jain@arm.com,
lance.yang@linux.dev, liam@infradead.org,
linux-kernel@vger.kernel.org, npache@redhat.com,
ryan.roberts@arm.com, ziy@nvidia.com, vbabka@kernel.org,
rppt@kernel.org, surenb@google.com, mhocko@suse.com
Subject: Re: [RFC PATCH v2 2/2] mm: improve large folio reuse for LRU-cached folios
Date: Mon, 3 Aug 2026 10:03:29 +0200 [thread overview]
Message-ID: <a3a2995b-2065-4c48-bbf9-53a28e3d2d94@kernel.org> (raw)
In-Reply-To: <CAGsJ_4xTBvAsqSano5dG1m0BDhceOR0VscfQxuH5oeexSX9kmQ@mail.gmail.com>
On 8/3/26 09:24, Barry Song wrote:
> On Wed, Jul 29, 2026 at 8:11 PM David Hildenbrand (Arm)
> <david@kernel.org> wrote:
>>
>> On 7/9/26 10:15, Barry Song (Xiaomi) wrote:
>>> Large folios may now reside in the per-CPU LRU cache. Before
>>> attempting to reuse them, drain the local LRU cache, which
>>> can still be beneficial in cases where the folios are likely
>>> to remain in this CPU's LRU cache:
>>>
>>> int main(int argc, char *argv[])
>>> {
>>> int i;
>>> while (1) {
>>> volatile int *p = mmap(0, SIZE, PROT_READ | PROT_WRITE,
>>> MAP_PRIVATE | MAP_ANONYMOUS,
>>> -1, 0);
>>> for (int i = 0; i < SIZE / sizeof(int); i++)
>>> p[i] = i;
>>> madvise((void *)p, SIZE, MADV_PAGEOUT);
>>> if (!fork())
>>> _exit(0);
>>> for (int i = 0; i < SIZE / sizeof(int); i++)
>>> p[i] = i;
>>> munmap((void *)p, SIZE);
>>> }
>>> return 0;
>>> }
>>>
>>> Signed-off-by: Barry Song (Xiaomi) <baohua@kernel.org>
>>> ---
>>> mm/memory.c | 13 +++++++++++++
>>> 1 file changed, 13 insertions(+)
>>>
>>> diff --git a/mm/memory.c b/mm/memory.c
>>> index 5689b7cff76c..1d08ed5ba99b 100644
>>> --- a/mm/memory.c
>>> +++ b/mm/memory.c
>>> @@ -4136,6 +4136,19 @@ static bool __wp_can_reuse_large_anon_folio(struct folio *folio,
>>> folio_unlock(folio);
>>> }
>>>
>>> + if (folio_may_be_lru_cached(folio) && !folio_test_lru(folio)) {
>>> + if (folio_ref_count(folio) > folio_large_mapcount(folio) + 1)
>>
>> I assume that can just be a "!=".
>
> I was trying to guard against the case where a folio is not on
> the LRU but also does not hold an extra reference. For example,
> the folio is off the LRU, yet
> folio_ref_count(folio) == folio_large_mapcount(folio).
>
> In that case, we could simply reuse !folio_test_lru(folio).
>
> Maybe such a case cannot actually happen, since paths like
> isolate_folio() take an extra reference before removing the
> folio from the LRU.
>
> So we should be ok to just use folio_ref_count(folio) !=
> folio_large_mapcount(folio) +1
I just stumbled into something nasty last week:
https://lore.kernel.org/r/20260731-check_and_migrate_movable_folios-v1-1-e0002d7b791e@kernel.org
For an mTHP, if we end up pinning multiple pages, calculating pin_refs is problematic and
might require us to batch over multiple pages.
But there are some nasty corner cases when just batching contiguous pages.
--
Cheers,
David
prev parent reply other threads:[~2026-08-03 8:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 8:15 [RFC PATCH v2 0/2] mm: enable lru cache for smaller large folios Barry Song (Xiaomi)
2026-07-09 8:15 ` [RFC PATCH v2 1/2] mm: allow smaller large folios to use lru_cache Barry Song (Xiaomi)
2026-07-29 12:13 ` David Hildenbrand (Arm)
2026-07-29 22:26 ` Barry Song (Xiaomi)
2026-07-30 9:28 ` David Hildenbrand (Arm)
2026-07-30 11:28 ` Zi Yan
2026-07-09 8:15 ` [RFC PATCH v2 2/2] mm: improve large folio reuse for LRU-cached folios Barry Song (Xiaomi)
2026-07-29 12:11 ` David Hildenbrand (Arm)
2026-08-03 7:24 ` Barry Song
2026-08-03 8:03 ` David Hildenbrand (Arm) [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=a3a2995b-2065-4c48-bbf9-53a28e3d2d94@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=dev.jain@arm.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=mhocko@suse.com \
--cc=npache@redhat.com \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=surenb@google.com \
--cc=vbabka@kernel.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