From: sashiko-bot@kernel.org
To: "Julian Sun" <sunjunchao@bytedance.com>, linux-ext4@vger.kernel.org
Cc: tytso@mit.edu
Subject: Re: [PATCH v3 2/3] ext4: submit mapped buffers after fatal mapping errors
Date: Mon, 16 Nov 2026 07:24:50 +0000 [thread overview]
Message-ID: <sashiko-outbox-216410@kernel.org> (raw)
In-Reply-To: <20261116064749.194146-1-sunjunchao@bytedance.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ext4: writeback loop continues with give_up_on_write set
after fatal -ENOSPC
--
commit 582dfee51394f04b2556a1a60b05a5f6ce7a4668
Author: Julian Sun <sunjunchao@bytedance.com>
ext4: submit mapped buffers after fatal mapping errors
This commit submits already-mapped buffers in a folio when a subsequent
extent mapping or io_end_vec allocation fails, rather than discarding
the whole folio on fatal mapping errors.
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 6dad9eea78240..ff33ae870b359 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -2600,6 +2600,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))
> @@ -2610,8 +2611,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()
> @@ -2619,18 +2622,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,
> - release_start))
> - goto invalidate_dirty_pages;
> - goto update_disksize;
> - }
> - return err;
> + break;
> }
> ext4_msg(sb, KERN_CRIT,
> "Delayed block allocation failed for "
> @@ -2644,9 +2636,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;
> /*
> @@ -2655,10 +2646,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, release_start))
> + fatal = true;
> +
> + if (fatal)
> + *give_up_on_write = true;
> + if (!progress)
> + return err;
> + }
[Severity: Medium]
Can ext4_do_writepages() keep looping with give_up_on_write set to true
after a fatal -ENOSPC?
When mpage_map_one_extent() fails with -ENOSPC and
ext4_count_free_clusters(sb) == 0 after an earlier extent in the folio was
mapped, mpage_map_and_submit_extent() now submits the partial folio, sets
*give_up_on_write = true, and returns -ENOSPC. However,
ext4_do_writepages() initializes give_up_on_write once outside the
writeback loop and retries -ENOSPC unconditionally:
fs/ext4/inode.c:ext4_do_writepages() {
...
mpage_release_unused_pages(mpd, give_up_on_write, release_start);
/* Submit prepared bio */
ext4_io_submit(&mpd->io_submit);
...
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 mpage_release_unused_pages() clears mpd->scanned_until_end when
mpd->start_pos < mpd->next_pos, the loop continues with give_up_on_write
stuck at true and release_start reset to 0. On the next iteration, either
the same partially submitted folio is re-locked and invalidated in the same
ext4_do_writepages() call, or (in WB_SYNC_NONE while the partial folio is
still under writeback) subsequent dirty folios are processed and any unused
folios left in [mpd->start_pos, mpd->next_pos) get invalidated by the stale
give_up_on_write flag, while ext4_do_writepages() clears ret = 0 and
returns success. The same happens if mpage_submit_partial_folio() fails
after a retryable -ENOSPC or -EAGAIN.
Should ext4_do_writepages() break out of the loop when give_up_on_write is
set instead of retrying -ENOSPC or clearing -EAGAIN?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116064404.189911-1-sunjunchao@bytedance.com?part=2
next prev parent reply other threads:[~2026-11-16 7:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 6:44 [PATCH v3 0/3] ext4: fix buffered writeback error handling Julian Sun
2026-11-16 6:44 ` [PATCH v3 1/3] ext4: fix a race between partial writeback and truncation Julian Sun
2026-11-16 7:02 ` sashiko-bot
2026-11-16 6:47 ` [PATCH v3 2/3] ext4: submit mapped buffers after fatal mapping errors Julian Sun
2026-11-16 7:24 ` sashiko-bot [this message]
2026-11-16 6:47 ` [PATCH v3 3/3] ext4: use atomic bitops for io_end flags Julian Sun
2026-11-16 6:59 ` 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-216410@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox