[PATCH alt 13/25] mm/fbatch: no lru_add_drain() to collect_longterm_unpinnable_folios()
From: Hugh Dickins
Date: Mon Aug 24 2026 - 11:08:04 EST
collect_longterm_unpinnable_folios() has no use for lru_add_drain() nor
lru_add_drain_all(), now that the per-cpu fbatch references are gone.
So remove the recently added lru_cache_drain_for_folio().
Signed-off-by: Hugh Dickins <hughd@xxxxxxxxxx>
---
Alternate version for use once David Hildenbrand's two commits
here have been pulled from mm.git into linux.git for 7.3-rc1.
include/linux/swap.h | 8 --------
mm/folio.c | 46 --------------------------------------------
mm/gup.c | 9 ---------
3 files changed, 63 deletions(-)
diff --git a/include/linux/swap.h b/include/linux/swap.h
index 17c60956c553..ecb877fe61ed 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -302,14 +302,6 @@ static inline void folio_add_lru(struct folio *folio)
void folio_mark_accessed(struct folio *folio);
void lru_add_drain_all(void);
-enum lru_cache_drained {
- LRU_CACHE_NOT_DRAINED,
- LRU_CACHE_DRAINED,
- LRU_CACHE_DRAINED_ALL,
-};
-void lru_cache_drain_for_folio(const struct folio *folio,
- unsigned int extra_refs, enum lru_cache_drained *drained);
-
/* linux/mm/folio-compat.c */
void mark_page_accessed(struct page *page);
diff --git a/mm/folio.c b/mm/folio.c
index 1c03b44362c1..7b309059b302 100644
--- a/mm/folio.c
+++ b/mm/folio.c
@@ -842,52 +842,6 @@ void lru_add_drain_all(void)
}
#endif /* CONFIG_SMP */
-/**
- * lru_cache_drain_for_folio() - drain LRU caches if the caches might hold
- * folio references
- * @folio: The folio.
- * @extra_refs: Extra folio references held by the caller.
- * @drained: Drain status for batch folio processing.
- *
- * Drain LRU caches if the caches might hold folio references. Start
- * with a local LRU cache drain, to then drain LRU caches on all CPUs if
- * local draining was insufficient.
- *
- * This function detects LRU cache references by comparing the folio refcount
- * with the sum of the expected folio refcount + extra references held by the
- * caller. Note that we cannot rely on PG_lru to reliably detect all LRU
- * cache references, and there are rare scenarios (concurrent folio (un)mapping)
- * where this function might miss detecting LRU cache references.
- *
- * If @drained is not NULL, the function will avoid re-draining LRU caches
- * when processing multiple folios in a row. In that case, the variable
- * @drained points at must be initialized to LRU_CACHE_NOT_DRAINED before
- * the first invocation by the caller.
- */
-void lru_cache_drain_for_folio(const struct folio *folio,
- unsigned int extra_refs, enum lru_cache_drained *drained)
-{
- if (!folio_may_be_lru_cached(folio))
- return;
-
- if (!drained || *drained == LRU_CACHE_NOT_DRAINED) {
- if (folio_ref_count(folio) ==
- folio_expected_ref_count(folio) + extra_refs)
- return;
- lru_add_drain();
- if (drained)
- *drained = LRU_CACHE_DRAINED;
- }
- if (!drained || *drained == LRU_CACHE_DRAINED) {
- if (folio_ref_count(folio) ==
- folio_expected_ref_count(folio) + extra_refs)
- return;
- lru_add_drain_all();
- if (drained)
- *drained = LRU_CACHE_DRAINED_ALL;
- }
-}
-
atomic_t lru_disable_count = ATOMIC_INIT(0);
/*
diff --git a/mm/gup.c b/mm/gup.c
index 98fdf7b7baca..e87a77dacdb6 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -2273,14 +2273,12 @@ static unsigned long collect_longterm_unpinnable_folios(
struct list_head *movable_folio_list,
struct pages_or_folios *pofs)
{
- enum lru_cache_drained drained = LRU_CACHE_NOT_DRAINED;
unsigned long collected = 0;
struct folio *folio;
long i = 0;
for (folio = pofs_get_folio(pofs, i); folio;
folio = pofs_next_folio(folio, pofs, &i)) {
- const int pin_refs = folio_has_pincount(folio) ? 1 : GUP_PIN_COUNTING_BIAS;
if (folio_is_longterm_pinnable(folio))
continue;
@@ -2295,13 +2293,6 @@ static unsigned long collect_longterm_unpinnable_folios(
continue;
}
- /*
- * We drain not only to make the folio_isolate_lru() succeed,
- * but also to remove any other folio references from LRU
- * caches.
- */
- lru_cache_drain_for_folio(folio, pin_refs, &drained);
-
if (!folio_isolate_lru(folio))
continue;