From: Wandun Chen 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 Closes: https://lore.kernel.org/all/DU0PR01MB10385345F7153F334100981888259A@DU0PR01MB10385.eurprd01.prod.exchangelabs.com/ Suggested-by: Vlastimil Babka Signed-off-by: Wandun Chen Link: https://lore.kernel.org/all/33275585-f2db-4779-89f0-3ae24b455a67@suse.cz/ [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