Re: [PATCH 2/3] ntfs: redirty folio when ntfs_write_mft_block() runs out of memory

From: Hyunchul Lee

Date: Fri May 01 2026 - 09:05:10 EST


2026년 5월 1일 (금) 오전 2:21, DaeMyung Kang <charsyam@xxxxxxxxx>님이 작성:
>
> ntfs_write_mft_block() is called by writeback_iter() with the folio
> locked. When the per-call allocations for @locked_nis or @ref_inos
> fail, the function returns -ENOMEM directly without unlocking the
> folio. Any later task that needs the folio's lock then stalls, and
> the folio's dirty state is silently lost from the writeback
> iterator's point of view.
>
> Use folio_redirty_for_writepage() so the folio remains dirty for a
> subsequent writeback pass, unlock it, and only then return -ENOMEM
> so the caller can propagate the error to fsync()/sync_filesystem().
>
> Fixes: f462fdf3d6a4 ("ntfs: reduce stack usage in ntfs_write_mft_block()")
> Signed-off-by: DaeMyung Kang <charsyam@xxxxxxxxx>

Looks good to me.

Reviewed-by: Hyunchul Lee <hyc.lee@xxxxxxxxx>


> ---
> fs/ntfs/mft.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/fs/ntfs/mft.c b/fs/ntfs/mft.c
> index 4051b4823162..00f172fd1b21 100644
> --- a/fs/ntfs/mft.c
> +++ b/fs/ntfs/mft.c
> @@ -2740,8 +2740,11 @@ static int ntfs_write_mft_block(struct folio *folio, struct writeback_control *w
> ntfs_debug("Entering for inode 0x%llx, attribute type 0x%x, folio index 0x%lx.",
> ni->mft_no, ni->type, folio->index);
>
> - if (!locked_nis || !ref_inos)
> + if (!locked_nis || !ref_inos) {
> + folio_redirty_for_writepage(wbc, folio);
> + folio_unlock(folio);
> return -ENOMEM;
> + }
>
> /* We have to zero every time due to mmap-at-end-of-file. */
> if (folio->index >= (i_size >> folio_shift(folio)))
> --
> 2.43.0
>


--
Thanks,
Hyunchul