Skip to content

Commit a09a8a1

Browse files
Hugh Dickinsakpm00
authored andcommitted
mm/gup: local lru_add_drain() to avoid lru_add_drain_all()
In many cases, if collect_longterm_unpinnable_folios() does need to drain the LRU cache to release a reference, the cache in question is on this same CPU, and much more efficiently drained by a preliminary local lru_add_drain(), than the later cross-CPU lru_add_drain_all(). Marked for stable, to counter the increase in lru_add_drain_all()s from "mm/gup: check ref_count instead of lru before migration". Note for clean backports: can take 6.16 commit a03db23 ("gup: optimize longterm pin_user_pages() for large folio") first. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Hugh Dickins <[email protected]> Acked-by: David Hildenbrand <[email protected]> Cc: "Aneesh Kumar K.V" <[email protected]> Cc: Axel Rasmussen <[email protected]> Cc: Chris Li <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Jason Gunthorpe <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: John Hubbard <[email protected]> Cc: Keir Fraser <[email protected]> Cc: Konstantin Khlebnikov <[email protected]> Cc: Li Zhe <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Peter Xu <[email protected]> Cc: Rik van Riel <[email protected]> Cc: Shivank Garg <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Wei Xu <[email protected]> Cc: Will Deacon <[email protected]> Cc: yangge <[email protected]> Cc: Yuanchu Xie <[email protected]> Cc: Yu Zhao <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 98c6d25 commit a09a8a1

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

mm/gup.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,8 +2287,8 @@ static unsigned long collect_longterm_unpinnable_folios(
22872287
struct pages_or_folios *pofs)
22882288
{
22892289
unsigned long collected = 0;
2290-
bool drain_allow = true;
22912290
struct folio *folio;
2291+
int drained = 0;
22922292
long i = 0;
22932293

22942294
for (folio = pofs_get_folio(pofs, i); folio;
@@ -2307,10 +2307,17 @@ static unsigned long collect_longterm_unpinnable_folios(
23072307
continue;
23082308
}
23092309

2310-
if (drain_allow && folio_ref_count(folio) !=
2311-
folio_expected_ref_count(folio) + 1) {
2310+
if (drained == 0 &&
2311+
folio_ref_count(folio) !=
2312+
folio_expected_ref_count(folio) + 1) {
2313+
lru_add_drain();
2314+
drained = 1;
2315+
}
2316+
if (drained == 1 &&
2317+
folio_ref_count(folio) !=
2318+
folio_expected_ref_count(folio) + 1) {
23122319
lru_add_drain_all();
2313-
drain_allow = false;
2320+
drained = 2;
23142321
}
23152322

23162323
if (!folio_isolate_lru(folio))

0 commit comments

Comments
 (0)