Re: [PATCH 08/32] mm/khugepaged: flush file after unlocking folios in collapse_file()
From: Zi Yan
Date: Mon Nov 30 2026 - 12:04:05 EST
On Sun Nov 29, 2026 at 5:06 AM EST, David Hildenbrand (Arm) wrote:
> From: Chris Mason <mason@xxxxxxxxxx>
>
> collapse_file() calls filemap_flush() when it encounters a dirty folio in
> a file that is not open for writing. At that point, source folios earlier
> in the range are still locked. The writable-open check is racy: a writer
> can open the file after the check.
>
> On ext4, the flush may need a journal handle, while EXT4_IOC_MOVE_EXT
> takes a journal handle before locking folios, and a journal commit blocks
> new handles while waiting for existing handles to be released.
>
> Consequently, we can deadlock: collapse_file() waits for a handle, the
> commit waits for extent movement to finish, and extent movement waits for
> a source folio lock.
>
> Let's fix it by deferring filemap_flush() until rollback has unlocked all
> source folios.
>
> This has medium urgency, as it can deadlock ext4 in some scenarios.
>
> Fixes: 75f360696ce9 ("mm/thp: flush file for !is_shmem PageDirty() case in collapse_file()")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Chris Mason <mason@xxxxxxxxxx>
> [ david: rework code; simplify comments and description ]
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
> ---
> mm/khugepaged.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
Makes sense.
Reviewed-by: Zi Yan <ziy@xxxxxxxxxx>
--
Best Regards,
Yan, Zi