From: "David Hildenbrand (Arm)" <david@kernel.org>
To: "Barry Song (Xiaomi)" <baohua@kernel.org>,
akpm@linux-foundation.org, linux-mm@kvack.org, ljs@kernel.org
Cc: 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: Wed, 29 Jul 2026 14:11:26 +0200 [thread overview]
Message-ID: <8f74bd51-11f2-4837-9463-d016444e45cc@kernel.org> (raw)
In-Reply-To: <20260709081536.82768-3-baohua@kernel.org>
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 "!=".
> + return false;
> + /*
> + * A global LRU drain is too expensive, but a local drain
> + * can still be beneficial. For example, large folios that
> + * have just been swapped in and fall back from
> + * do_swap_page() to do_wp_page() are likely still in this
> + * CPU's LRU cache.
> + */
Do we really need that comment? It's just the same as we have in
wp_can_reuse_anon_folio(). So either drop it or use the same comment.
I was wondering whether we could unify some logic with
wp_can_reuse_anon_folio(), but the checks are just to different.
Apart from that LGTM. I'm sure there are some micro-optimizations to be had, but
this here should suffice.
--
Cheers,
David
prev parent reply other threads:[~2026-07-29 14:39 UTC|newest]
Thread overview: 5+ 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-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) [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=8f74bd51-11f2-4837-9463-d016444e45cc@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