mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mm/madvise: reclaim isolated folios if PTE restart fails
@ 2026-09-12 11:08 Gregory Price
  2026-09-15  6:32 ` Andrew Morton
  2026-09-15 15:55 ` Lorenzo Stoakes (ARM)
  0 siblings, 2 replies; 22+ messages in thread
From: Gregory Price @ 2026-09-12 11:08 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-kernel, kernel-team, akpm, liam, ljs, david, vbabka, jannh,
	wangjiexun, sashiko-bot, stable, Gregory Price (Meta)

MADV_PAGEOUT collects isolated folios on a local list before reclaiming
them after the PTE walk.  The reschedule path drops the PTE lock and then
restarts the mapping with pte_offset_map_lock().

A concurrent operation can remove or replace the PTE table while the lock
is dropped, causing pte_offset_map_lock() to return NULL.  Returning directly
in that case bypasses reclaim_pages(), leaving the collected folios off the
LRU with elevated references.

Route the failure through the existing cleanup path so any isolated folios
are reclaimed or put back.

Simplest userland pseudo-code reproducer:

p = mmap(PMD_SIZE, ANONYMOUS);
touch_every_page(p, PMD_SIZE);
parallel {
   while (1) madvise(p, PMD_SIZE, MADV_PAGEOUT);
   while (1) {
       madvise(p, PMD_SIZE, MADV_DONTNEED);
       touch_every_page(p, PMD_SIZE);
   }
}

Reproduced in qemu trivially with some explicit widening of the race window.

Fixes: b2f557a21bc8 ("mm/madvise: add cond_resched() in madvise_cold_or_pageout_pte_range()")
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260821150912.183976-1-gourry@gourry.net
Cc: <stable@vger.kernel.org>
Assisted-by: LLM
Signed-off-by: Gregory Price (Meta) <gourry@gourry.net>
---
 mm/madvise.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/madvise.c b/mm/madvise.c
index 574aa2bb7c7e..ba5a3d77241a 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -464,7 +464,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
 restart:
 	start_pte = pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
 	if (!start_pte)
-		return 0;
+		goto out;
 	flush_tlb_batched_pending(mm);
 	lazy_mmu_mode_enable();
 	for (; addr < end; pte += nr, addr += nr * PAGE_SIZE) {
@@ -568,6 +568,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
 			folio_deactivate(folio);
 	}
 
+out:
 	if (start_pte) {
 		lazy_mmu_mode_disable();
 		pte_unmap_unlock(start_pte, ptl);
-- 
2.55.0


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2026-09-16 16:10 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-12 11:08 [PATCH] mm/madvise: reclaim isolated folios if PTE restart fails Gregory Price
2026-09-15  6:32 ` Andrew Morton
2026-09-15 14:13   ` Gregory Price
2026-09-15 15:55 ` Lorenzo Stoakes (ARM)
2026-09-15 17:00   ` Gregory Price
2026-09-16 13:18     ` Lorenzo Stoakes (ARM)
2026-09-16 14:02       ` Gregory Price
2026-09-16 14:08         ` Lorenzo Stoakes (ARM)
2026-09-15 17:12   ` Gregory Price
2026-09-16 13:03     ` Lorenzo Stoakes (ARM)
2026-09-16 13:57       ` Gregory Price
2026-09-16 14:12         ` Lorenzo Stoakes (ARM)
2026-09-16 14:42           ` Gregory Price
2026-09-16 14:48             ` David Hildenbrand (Arm)
2026-09-16 14:58               ` Gregory Price
2026-09-16 14:59                 ` David Hildenbrand (Arm)
2026-09-16 15:19                   ` Gregory Price
2026-09-16 15:21                     ` Lorenzo Stoakes (ARM)
2026-09-16 15:24                     ` David Hildenbrand (Arm)
2026-09-16 15:37                       ` Gregory Price
2026-09-16 15:42                         ` David Hildenbrand (Arm)
2026-09-16 16:10                           ` Gregory Price

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®