[PATCH v2 8/8] mm/khugepaged: flesh out try_to_unmap_flush() comment
From: Pedro Falcato
Date: Wed Nov 11 2026 - 13:23:48 EST
Flesh out any correctness concerns with try_to_unmap batching, flushing
and its interaction with the rest of collapse_file().
Signed-off-by: Pedro Falcato <pfalcato@xxxxxxx>
---
mm/khugepaged.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index accd8b4895d3..fd947e698ed0 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -2597,8 +2597,12 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr,
xa_unlocked:
/*
- * Flush before copying the folios, or releasing them in rollback.
- * This is a no-op if out_unlock already flushed the batch.
+ * try_to_unmap() flush must be done now before copying, regardless
+ * of success or not. In case of success, folios are about to be
+ * copied and collapsed onto a single large folio. In that case,
+ * stale TLB entries need to be flushed out, so no racing write may
+ * get lost. In case of failure, stale TLB entries need to be flushed
+ * out before putting the folio (which can possibly free it).
*/
try_to_unmap_flush();
--
2.56.0