From: Zhang Yi <yi.zhang@huaweicloud.com>
To: Ojaswin Mujoo <ojaswin@linux.ibm.com>
Cc: Theodore Ts'o <tytso@mit.edu>,
Andreas Dilger <adilger.kernel@dilger.ca>,
Baokun Li <libaokun@linux.alibaba.com>, Jan Kara <jack@suse.cz>,
"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 03/13] ext4: preserve convert pending extents when adding unwrit extents to es cache
Date: Tue, 1 Dec 2026 20:54:46 +0800 [thread overview]
Message-ID: <7f08a6ab-8909-48a7-b2e2-b7455d23f49f@huaweicloud.com> (raw)
In-Reply-To: <20261127-ext4-endio-zero-bug-v2-3-4106968e4d15@linux.ibm.com>
Hi Ojaswin,
Thank you for this series!
On 11/27/2026 11:10 PM, Ojaswin Mujoo wrote:
> ext4_es_insert_extent() interfaces overwrites the old range with the new
> extent type. This can cause a CONVERT_PENDING extent type to be lost when
> it is overwritten with unwritten extent.
>
> This is undesirable because paths like falloc will call
> ext4_es_insert_extent() which removes all extents in the range and then
> adds the new unwritten es extent.
I don't understand here. I can't imagine how this happens. A normal
fallocate() can only insert an unwritten extent entry when it reaches
ext4_map_create_blocks(), but since I already added an early-return
path for unwritten extents in ext4_map_blocks() in 7f373083b45757, the
scenario you described should not reach ext4_map_create_blocks()
anymore. Am I missing something?
Thanks,
Yi.
> To ensure this doesn't end up removing
> pending CONV_PENDING extents, we add logic in __es_remove_extent() to check
> if we are crossing any CONV_PENDING extent, in which case we don't cache
> the new unwrit extent.
>
> Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
> ---
> fs/ext4/extents_status.c | 67 ++++++++++++++++++++++++++++++++++++++++--------
> 1 file changed, 57 insertions(+), 10 deletions(-)
>
> diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
> index 28528f19be1d..75dd065106e4 100644
> --- a/fs/ext4/extents_status.c
> +++ b/fs/ext4/extents_status.c
> @@ -181,7 +181,8 @@ static int __es_insert_extent(struct inode *inode, struct extent_status *newes,
> static int __es_remove_extent(struct inode *inode, ext4_lblk_t lblk,
> ext4_lblk_t end, unsigned int status,
> int *reserved, struct extent_status *res,
> - struct extent_status *prealloc);
> + struct extent_status *prealloc,
> + bool *preserve_conv_pending);
> static int es_reclaim_extents(struct ext4_inode_info *ei, int *nr_to_scan);
> static int __es_shrink(struct ext4_sb_info *sbi, int nr_to_scan,
> int *nr_scanned);
> @@ -924,6 +925,7 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
> struct extent_status *es2 = NULL;
> struct pending_reservation *pr = NULL;
> bool revise_pending = false;
> + bool preserve_conv_pending;
>
> if (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY)
> return;
> @@ -946,7 +948,8 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
> revise_pending = sbi->s_cluster_ratio > 1 &&
> test_opt(inode->i_sb, DELALLOC) &&
> (status & (EXTENT_STATUS_WRITTEN |
> - EXTENT_STATUS_UNWRITTEN));
> + EXTENT_STATUS_UNWRITTEN |
> + EXTENT_STATUS_CONVERT_PENDING));
> retry:
> if (err1 && !es1)
> es1 = __es_alloc_extent(true);
> @@ -956,7 +959,10 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
> pr = __alloc_pending(true);
> write_lock(&EXT4_I(inode)->i_es_lock);
>
> - err1 = __es_remove_extent(inode, lblk, end, 0, &resv_used, NULL, es1);
> + preserve_conv_pending = status & EXTENT_STATUS_UNWRITTEN;
> +
> + err1 = __es_remove_extent(inode, lblk, end, 0, &resv_used, NULL, es1,
> + &preserve_conv_pending);
> if (err1 != 0)
> goto error;
> /* Free preallocated extent if it didn't get used. */
> @@ -966,6 +972,15 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
> es1 = NULL;
> }
>
> + /*
> + * For now, to keep things simple we don't insert an unwritten extent if
> + * there are conver pending extents already in the range. Hopefully they
> + * will be cached once we finish the endio conversoin, however this can
> + * be implemented later if performance issues are noticed.
> + */
> + if (preserve_conv_pending)
> + goto skip_insert;
> +
> err2 = __es_insert_extent(inode, &newes, es2);
> if (err2 == -ENOMEM && !ext4_es_must_keep(&newes))
> err2 = 0;
> @@ -978,6 +993,7 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
> es2 = NULL;
> }
>
> +skip_insert:
> if (revise_pending) {
> err3 = __revise_pending(inode, lblk, len, &pr);
> if (err3 < 0)
> @@ -1063,7 +1079,7 @@ void ext4_es_cache_extent(struct inode *inode, ext4_lblk_t lblk,
> }
> /* Check and remove all extents in range. */
> err = __es_remove_extent(inode, lblk, end, status, NULL,
> - &chkes, NULL);
> + &chkes, NULL, NULL);
> if (err) {
> if (err == -EINVAL)
> conflict = true;
> @@ -1502,7 +1518,8 @@ static unsigned int get_rsvd(struct inode *inode, ext4_lblk_t end,
> static int __es_remove_extent(struct inode *inode, ext4_lblk_t lblk,
> ext4_lblk_t end, unsigned int status,
> int *reserved, struct extent_status *res,
> - struct extent_status *prealloc)
> + struct extent_status *prealloc,
> + bool *preserve_conv_pending)
> {
> struct ext4_es_tree *tree = &EXT4_I(inode)->i_es_tree;
> struct rb_node *node;
> @@ -1513,6 +1530,16 @@ static int __es_remove_extent(struct inode *inode, ext4_lblk_t lblk,
> int err;
> bool count_reserved = true;
> struct rsvd_count rc;
> + bool has_conv_pending = false;
> + bool preserve_es = preserve_conv_pending && *preserve_conv_pending;
> +
> +
> + /*
> + * Reset it, we will set it again based on if the range had a convert
> + * pending entry
> + */
> + if (preserve_es)
> + *preserve_conv_pending = false;
>
> if (reserved == NULL || !test_opt(inode->i_sb, DELALLOC))
> count_reserved = false;
> @@ -1540,6 +1567,12 @@ static int __es_remove_extent(struct inode *inode, ext4_lblk_t lblk,
>
> len1 = lblk > es->es_lblk ? lblk - es->es_lblk : 0;
> len2 = ext4_es_end(es) > end ? ext4_es_end(es) - end : 0;
> +
> + if (ext4_es_is_convert_pending(es) && preserve_es) {
> + has_conv_pending = true;
> + goto next;
> + }
> +
> if (len1 > 0)
> es->es_len = len1;
> if (len2 > 0) {
> @@ -1583,6 +1616,7 @@ static int __es_remove_extent(struct inode *inode, ext4_lblk_t lblk,
> if (count_reserved)
> count_rsvd(inode, lblk, orig_es.es_len - len1,
> &orig_es, &rc);
> +next:
> node = rb_next(&es->rb_node);
> if (node)
> es = rb_entry(node, struct extent_status, rb_node);
> @@ -1597,8 +1631,14 @@ static int __es_remove_extent(struct inode *inode, ext4_lblk_t lblk,
> if (count_reserved)
> count_rsvd(inode, es->es_lblk, es->es_len, es, &rc);
> node = rb_next(&es->rb_node);
> - rb_erase(&es->rb_node, &tree->root);
> - ext4_es_free_extent(inode, es);
> +
> + if (ext4_es_is_convert_pending(es) && preserve_es) {
> + has_conv_pending = true;
> + } else {
> + rb_erase(&es->rb_node, &tree->root);
> + ext4_es_free_extent(inode, es);
> + }
> +
> if (!node) {
> es = NULL;
> break;
> @@ -1613,19 +1653,26 @@ static int __es_remove_extent(struct inode *inode, ext4_lblk_t lblk,
> if (err)
> return err;
>
> + if (ext4_es_is_convert_pending(es) && preserve_es) {
> + has_conv_pending = true;
> + goto out;
> + }
> +
> len1 = ext4_es_end(es) - end;
> if (count_reserved)
> count_rsvd(inode, es->es_lblk, orig_len - len1,
> es, &rc);
> es->es_lblk = end + 1;
> es->es_len = len1;
> - if (ext4_es_is_written(es) || ext4_es_is_unwritten(es)) {
> + if (ext4_es_is_mapped(es)) {
> block = es->es_pblk + orig_len - len1;
> ext4_es_store_pblock(es, block);
> }
> }
>
> out:
> + if (preserve_conv_pending && has_conv_pending)
> + *preserve_conv_pending = true;
> if (count_reserved)
> *reserved = get_rsvd(inode, end, es, &rc);
> return 0;
> @@ -1670,7 +1717,7 @@ void ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk,
> * is reclaimed.
> */
> write_lock(&EXT4_I(inode)->i_es_lock);
> - err = __es_remove_extent(inode, lblk, end, 0, &reserved, NULL, es);
> + err = __es_remove_extent(inode, lblk, end, 0, &reserved, NULL, es, NULL);
> if (err)
> goto error;
> /* Free preallocated extent if it didn't get used. */
> @@ -2288,7 +2335,7 @@ void ext4_es_insert_delayed_extent(struct inode *inode, ext4_lblk_t lblk,
> }
> write_lock(&EXT4_I(inode)->i_es_lock);
>
> - err1 = __es_remove_extent(inode, lblk, end, 0, NULL, NULL, es1);
> + err1 = __es_remove_extent(inode, lblk, end, 0, NULL, NULL, es1, NULL);
> if (err1 != 0)
> goto error;
> /* Free preallocated extent if it didn't get used. */
>
next prev parent reply other threads:[~2026-12-01 12:54 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 15:10 [PATCH v2 00/13] ext4: fix endio zeroout corruption by tracking to-be-converted unwritten IOs Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 01/13] ext4: disable zeroout fallback in ext4_split_extent() Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 02/13] ext4: introduce CONVERT_PENDING extent status type Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 03/13] ext4: preserve convert pending extents when adding unwrit extents to es cache Ojaswin Mujoo
2026-12-01 12:54 ` Zhang Yi [this message]
2026-11-27 15:10 ` [PATCH v2 04/13] ext4: add es helper to convert unwrit to convert pending without changing i_es_seq Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 05/13] ext4: add support to track convert pending ranges in ext4_map_blocks() Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 06/13] ext4: add tracking for unwritten to-be-converted ranges in dio write path Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 07/13] ext4: add tracking for unwritten to-be-converted ranges in non iomap buffered path Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 08/13] ext4: add tracking for unwritten to-be-converted ranges in " Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 09/13] ext4: don't zeroout if conv pending ranges are present Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 10/13] ext4: add tracepoints for extent split and convert Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 11/13] ext4: update extent status cache when zeroing extents Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 12/13] ext4: don't drop the extents in case extent split fails Ojaswin Mujoo
2026-11-27 15:11 ` [PATCH v2 13/13] ext4: re-enable zeroout fallback Ojaswin Mujoo
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=7f08a6ab-8909-48a7-b2e2-b7455d23f49f@huaweicloud.com \
--to=yi.zhang@huaweicloud.com \
--cc=adilger.kernel@dilger.ca \
--cc=jack@suse.cz \
--cc=libaokun@linux.alibaba.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ojaswin@linux.ibm.com \
--cc=ritesh.list@gmail.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
all inboxes | Powered by JetHome®