From: Wandun Chen <[email protected]>

compact_unevictable_allowed is default 0 under PREEMPT_RT,
isolate_migratepages_block() skips folios with PG_unevictable set.
However, mlock_folio() sets PG_mlocked immediately but defers
PG_unevictable to mlock_folio_batch(), result in a folio with
PG_mlocked=1 but PG_unevictable=0. Compaction will isolate such a
folio.

Fix by checking folio_test_mlocked() together with the existing
folio_test_unevictable() check.

A similar issue has been reported by Alexander Krabler on a 6.12-rt
aarch64 system. Vlastimil suggested to check the mlocked flag [1].

Reported-by: Alexander Krabler <[email protected]>
Closes: 
https://lore.kernel.org/all/du0pr01mb10385345f7153f3341009818882...@du0pr01mb10385.eurprd01.prod.exchangelabs.com/
Suggested-by: Vlastimil Babka <[email protected]>
Signed-off-by: Wandun Chen <[email protected]>
Link: https://lore.kernel.org/all/[email protected]/ 
[1]
---
 mm/compaction.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/compaction.c b/mm/compaction.c
index b776f35ad020..7e07b792bcb5 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -1116,7 +1116,8 @@ isolate_migratepages_block(struct compact_control *cc, 
unsigned long low_pfn,
                is_unevictable = folio_test_unevictable(folio);
 
                /* Compaction might skip unevictable pages but CMA takes them */
-               if (!(mode & ISOLATE_UNEVICTABLE) && is_unevictable)
+               if (!(mode & ISOLATE_UNEVICTABLE) &&
+                   (is_unevictable || folio_test_mlocked(folio)))
                        goto isolate_fail_put;
 
                /*
-- 
2.43.0


Reply via email to