[PATCH v2 13/26] mm/fbatch: no lru_add_drain to collect_longterm_unpinnable_folios()
From: Hugh Dickins
Date: Wed Sep 09 2026 - 06:13:06 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.
Replace the recently added lru_cache_drain_for_folio() by a temporary
stub, so any callers outside mm may build independently of this series.
Signed-off-by: Hugh Dickins <hughd@xxxxxxxxxx>
---
include/linux/swap.h | 9 +++++----
mm/folio.c | 48 --------------------------------------------
mm/gup.c | 9 ---------
3 files changed, 5 insertions(+), 61 deletions(-)
diff --git a/include/linux/swap.h b/include/linux/swap.h
index a6fad5127118..0052a6890435 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -304,11 +304,12 @@ 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);
+static inline void lru_cache_drain_for_folio(const struct folio *folio,
+ unsigned int extra_refs, enum lru_cache_drained *drained)
+{
+ /* Temporary stub for callers' build independent of mm/fbatch series */
+}
/* linux/mm/folio-compat.c */
void mark_page_accessed(struct page *page);
diff --git a/mm/folio.c b/mm/folio.c
index 5021639c5494..d66aa2469e86 100644
--- a/mm/folio.c
+++ b/mm/folio.c
@@ -33,7 +33,6 @@
#include <linux/page_idle.h>
#include <linux/local_lock.h>
#include <linux/buffer_head.h>
-#include <linux/kvm_types.h>
#include "internal.h"
#include "page_alloc.h"
@@ -843,53 +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;
- }
-}
-EXPORT_SYMBOL_FOR_KVM(lru_cache_drain_for_folio);
-
atomic_t lru_disable_count = ATOMIC_INIT(0);
/*
diff --git a/mm/gup.c b/mm/gup.c
index eb898ea1ee22..fa17f99cbb60 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -2266,14 +2266,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;
@@ -2288,13 +2286,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;
--
2.51.0