Re: [PATCH V5 2/2] mm/khugepaged: retry with sync writeback for MADV_COLLAPSE

From: David Hildenbrand (Red Hat)

Date: Mon Jan 19 2026 - 05:08:12 EST


On 1/18/26 20:09, Shivank Garg wrote:
When MADV_COLLAPSE is called on file-backed mappings (e.g., executable
text sections), the pages may still be dirty from recent writes.
collapse_file() will trigger async writeback and fail with
SCAN_PAGE_DIRTY_OR_WRITEBACK (-EAGAIN).

MADV_COLLAPSE is a synchronous operation where userspace expects
immediate results. If the collapse fails due to dirty pages, perform
synchronous writeback on the specific range and retry once.

This avoids spurious failures for freshly written executables while
avoiding unnecessary synchronous I/O for mappings that are already clean.

Reported-by: Branden Moore <Branden.Moore@xxxxxxx>
Closes: https://lore.kernel.org/all/4e26fe5e-7374-467c-a333-9dd48f85d7cc@xxxxxxx
Fixes: 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE")
Suggested-by: David Hildenbrand <david@xxxxxxxxxx>
Tested-by: Lance Yang <lance.yang@xxxxxxxxx>
Signed-off-by: Shivank Garg <shivankg@xxxxxxx>
---

Looks good to me now, thanks Shivank!

Acked-by: David Hildenbrand (Red Hat) <david@xxxxxxxxxx>

--
Cheers

David