From: "Barry Song (Xiaomi)" <baohua@kernel.org>
To: akpm@linux-foundation.org, linux-mm@kvack.org
Cc: baolin.wang@linux.alibaba.com, david@kernel.org,
dev.jain@arm.com, lance.yang@linux.dev, liam@infradead.org,
linux-kernel@vger.kernel.org, ljs@kernel.org, mhocko@suse.com,
npache@redhat.com, rppt@kernel.org, ryan.roberts@arm.com,
surenb@google.com, vbabka@kernel.org, ziy@nvidia.com,
hughd@google.com, ackerleytng@google.com, usama.arif@linux.dev,
joannelkoong@gmail.com, hannes@cmpxchg.org,
"Barry Song (Xiaomi)" <baohua@kernel.org>
Subject: [RFC PATCH v3 3/4] mm: drain LRU cache if necessary for splitting large folios
Date: Wed, 19 Aug 2026 06:59:03 +0800 [thread overview]
Message-ID: <20260818225904.55236-4-baohua@kernel.org> (raw)
In-Reply-To: <20260818225904.55236-1-baohua@kernel.org>
Smaller large folios might now be present in the LRU cache. Use David's
new lru_cache_drain_for_folio() helper to drain the LRU cache before
splitting a folio, ensuring that the folio can be split successfully.
Also, we only perform the drain when it may actually help, assuming
that the lru_cache holds an extra reference.
Signed-off-by: Barry Song (Xiaomi) <baohua@kernel.org>
---
mm/huge_memory.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index ced400f72d43..263ef9b6949d 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -4201,6 +4201,9 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
if (shmem_mapping(mapping))
end = shmem_fallocend(mapping->host, end);
}
+ if (folio_ref_count(folio) == folio_expected_ref_count(folio) + 1 +
+ folio_may_be_lru_cached(folio))
+ lru_cache_drain_for_folio(folio, 1, NULL);
/*
* Racy check if we can split the page, before unmap_folio() will
@@ -4325,6 +4328,9 @@ int folio_split_unmapped(struct folio *folio, unsigned int new_order)
VM_WARN_ON_ONCE_FOLIO(!folio_test_large(folio), folio);
VM_WARN_ON_ONCE_FOLIO(!folio_test_anon(folio), folio);
+ if (folio_ref_count(folio) == folio_expected_ref_count(folio) + 1 +
+ folio_may_be_lru_cached(folio))
+ lru_cache_drain_for_folio(folio, 1, NULL);
if (folio_expected_ref_count(folio) != folio_ref_count(folio) - 1)
return -EAGAIN;
@@ -4805,6 +4811,10 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
goto next;
total++;
+
+ if (folio_ref_count(folio) == folio_expected_ref_count(folio) +
+ folio_may_be_lru_cached(folio))
+ lru_cache_drain_for_folio(folio, 0, NULL);
/*
* For folios with private, split_huge_page_to_list_to_order()
* will try to drop it before split and then check if the folio
--
2.34.1
next prev parent reply other threads:[~2026-08-18 22:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 22:59 [RFC PATCH v3 0/4] mm: enable lru cache for smaller large folios Barry Song (Xiaomi)
2026-08-18 22:59 ` [RFC PATCH v3 1/4] mm: allow smaller large folios to use lru_cache Barry Song (Xiaomi)
2026-08-19 4:34 ` Barry Song
2026-08-18 22:59 ` [RFC PATCH v3 2/4] mm: improve large folio reuse for LRU-cached folios Barry Song (Xiaomi)
2026-08-18 22:59 ` Barry Song (Xiaomi) [this message]
2026-08-18 22:59 ` [RFC PATCH v3 4/4] mm: batch lru_cache draining in deferred_split_scan Barry Song (Xiaomi)
2026-08-19 3:02 ` [RFC PATCH v3 0/4] mm: enable lru cache for smaller large folios Lance Yang
2026-08-19 4:38 ` Barry Song
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=20260818225904.55236-4-baohua@kernel.org \
--to=baohua@kernel.org \
--cc=ackerleytng@google.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=joannelkoong@gmail.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=usama.arif@linux.dev \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.