From: sashiko-bot@kernel.org
To: "Julian Sun" <sunjunchao@bytedance.com>, linux-ext4@vger.kernel.org
Cc: tytso@mit.edu
Subject: Re: [PATCH v4 2/3] ext4: submit mapped buffers after fatal mapping errors
Date: Mon, 30 Nov 2026 08:00:54 +0000 [thread overview]
Message-ID: <sashiko-outbox-240643@kernel.org> (raw)
In-Reply-To: <20261130073139.4183184-3-sunjunchao@bytedance.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ext4: writeback loop retries after fatal error with
give_up_on_write stuck true
--
commit a666f18d34d90ff94f75e3f4027ae28b8d8778ad
Author: Julian Sun <sunjunchao@bytedance.com>
ext4: submit mapped buffers after fatal mapping errors
This commit updates mpage_map_and_submit_extent() to submit already mapped
buffers in a folio when a subsequent extent mapping or io_end_vec
allocation fails.
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 407a60ac6b85f..ee51b12e31afe 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -2607,6 +2607,7 @@ static int mpage_map_and_submit_extent(handle_t *handle,
> int progress = 0;
> ext4_io_end_t *io_end = mpd->io_submit.io_end;
> struct ext4_io_end_vec *io_end_vec;
> + bool fatal = false;
>
> io_end_vec = ext4_alloc_io_end_vec(io_end);
> if (IS_ERR(io_end_vec))
> @@ -2617,8 +2618,10 @@ static int mpage_map_and_submit_extent(handle_t *handle,
> if (err < 0) {
> struct super_block *sb = inode->i_sb;
>
> - if (ext4_emergency_state(sb))
> - goto invalidate_dirty_pages;
> + if (ext4_emergency_state(sb)) {
> + *give_up_on_write = true;
> + return err;
> + }
> /*
> * Let the uper layers retry transient errors.
> * In the case of ENOSPC, if ext4_count_free_blocks()
> @@ -2626,18 +2629,7 @@ static int mpage_map_and_submit_extent(handle_t *handle,
> */
> if ((err == -ENOMEM) || (err == -EAGAIN) ||
> (err == -ENOSPC && ext4_count_free_clusters(sb))) {
> - /*
> - * We may have already allocated extents for
> - * some bhs inside the folio, issue the
> - * corresponding data to prevent stale data.
> - */
> - if (progress) {
> - if (mpage_submit_partial_folio(mpd,
> - partial_folio_end))
> - goto invalidate_dirty_pages;
> - goto update_disksize;
> - }
> - return err;
> + break;
> }
> ext4_msg(sb, KERN_CRIT,
> "Delayed block allocation failed for "
> @@ -2651,9 +2643,8 @@ static int mpage_map_and_submit_extent(handle_t *handle,
> "be lost\n");
> if (err == -ENOSPC)
> ext4_print_free_blocks(inode);
> - invalidate_dirty_pages:
> - *give_up_on_write = true;
> - return err;
> + fatal = true;
> + break;
> }
> progress = 1;
> /*
> @@ -2662,10 +2653,24 @@ static int mpage_map_and_submit_extent(handle_t *handle,
> */
> err = mpage_map_and_submit_buffers(mpd);
> if (err < 0)
> - goto update_disksize;
> + break;
> } while (map->m_len);
>
> -update_disksize:
> + if (err < 0) {
> + /*
> + * We may have already allocated extents for some bhs inside
> + * the folio, issue the corresponding data to prevent stale
> + * data.
> + */
> + if (progress && mpage_submit_partial_folio(mpd, partial_folio_end))
> + fatal = true;
> +
> + if (fatal)
> + *give_up_on_write = true;
> + if (!progress)
> + return err;
> + }
[Severity: Medium]
Does ext4_do_writepages() keep looping with give_up_on_write latched to
true when a fatal -ENOSPC occurs after partial progress in a folio?
When mpage_map_one_extent() fails with fatal -ENOSPC (free clusters == 0)
after progress == 1, mpage_map_and_submit_extent() submits the partial
folio, sets *give_up_on_write = true, and returns -ENOSPC. In
ext4_do_writepages(), mpage_release_unused_pages() sets
mpd->scanned_until_end = 0 and skips the partially submitted folio up to
partial_folio_end, but the loop then treats -ENOSPC as retryable without
checking give_up_on_write:
fs/ext4/inode.c:ext4_do_writepages() {
...
bool give_up_on_write = false;
...
while (!mpd->scanned_until_end && wbc->nr_to_write > 0) {
loff_t partial_folio_end = 0;
...
if (ret == -ENOSPC && sbi->s_journal) {
jbd2_journal_force_commit_nested(sbi->s_journal);
ret = 0;
continue;
}
if (ret == -EAGAIN)
ret = 0;
/* Fatal error - ENOMEM, EIO... */
if (ret)
break;
}
}
Because give_up_on_write is never reset and the loop does not break when
it is set, the next iteration re-enters with partial_folio_end == 0 and
give_up_on_write == true. In WB_SYNC_ALL mode (or once the bio finishes
during jbd2_journal_force_commit_nested()), it immediately re-processes
the partially submitted folio at mpd->start_pos, fails on the unmapped
extent with progress == 0, invalidates the folio that was meant to be
preserved, and clears ret to 0; if the loop instead advances to later
folios, the stale give_up_on_write == true causes
mpage_release_unused_pages() to invalidate valid dirty folios on any
subsequent extent boundary or transient error.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130073139.4183184-1-sunjunchao@bytedance.com?part=2
next prev parent reply other threads:[~2026-11-30 8:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 7:31 [PATCH v4 0/3] ext4: fix buffered writeback error handling Julian Sun
2026-11-30 7:31 ` [PATCH v4 1/3] ext4: fix a race between partial writeback and truncation Julian Sun
2026-11-30 9:11 ` Zhang Yi
2026-11-30 7:31 ` [PATCH v4 2/3] ext4: submit mapped buffers after fatal mapping errors Julian Sun
2026-11-30 8:00 ` sashiko-bot [this message]
2026-11-30 9:13 ` Zhang Yi
2026-11-30 7:31 ` [PATCH v4 3/3] ext4: use atomic bitops for io_end flags Julian Sun
2026-11-30 8:00 ` [PATCH v4 0/3] ext4: fix buffered writeback error handling sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-240643@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sunjunchao@bytedance.com \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.