From: Jan Kara <jack@suse.cz>
To: Yun Zhou <yun.zhou@windriver.com>
Cc: tytso@mit.edu, adilger.kernel@dilger.ca,
libaokun@linux.alibaba.com, jack@suse.cz, ojaswin@linux.ibm.com,
ritesh.list@gmail.com, yi.zhang@huawei.com,
viro@zeniv.linux.org.uk, brauner@kernel.org,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, xiaowu.417@qq.com
Subject: Re: [PATCH v11 4/5] ext4: remove ea_inode_array mechanism in favor of ext4_put_ea_inode()
Date: Mon, 29 Jun 2026 13:42:20 +0200 [thread overview]
Message-ID: <m5r4btltl5swpuifvrmobsmmjyrgxckgp4fpsenuf5fofnqlqj@poubnm4v42of> (raw)
In-Reply-To: <20260629110848.3085662-5-yun.zhou@windriver.com>
On Mon 29-06-26 19:08:47, Yun Zhou wrote:
> Now that ext4_put_ea_inode() handles deferred iput safely for all cases
> (using iput_if_not_last + embedded llist_node), the ea_inode_array
> mechanism for batching deferred iputs is redundant.
>
> Remove:
> - ext4_expand_inode_array() and ext4_xattr_inode_array_free()
> - struct ext4_xattr_inode_array and EIA_INCR/EIA_MASK defines
> - ea_inode_array parameter from ext4_xattr_inode_dec_ref_all(),
> ext4_xattr_release_block(), and ext4_xattr_delete_inode()
> - ea_inode_array variable from ext4_evict_inode()
>
> Instead, ext4_xattr_inode_dec_ref_all() now calls ext4_put_ea_inode()
> directly after processing each EA inode. This simplifies the code
> by eliminating multi-layer parameter threading and removes the need
> for callers to manage array lifetime.
>
> Signed-off-by: Yun Zhou <yun.zhou@windriver.com>
> Suggested-by: Jan Kara <jack@suse.cz>
Nice. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/ext4/inode.c | 6 +---
> fs/ext4/xattr.c | 80 ++++---------------------------------------------
> fs/ext4/xattr.h | 7 -----
> 3 files changed, 6 insertions(+), 87 deletions(-)
>
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 0d131371ad3d..6f1b84e46a2e 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -176,7 +176,6 @@ void ext4_evict_inode(struct inode *inode)
> * (xattr block freeing), bitmap, group descriptor (inode freeing)
> */
> int extra_credits = 6;
> - struct ext4_xattr_inode_array *ea_inode_array = NULL;
> bool freeze_protected = false;
>
> trace_ext4_evict_inode(inode);
> @@ -282,8 +281,7 @@ void ext4_evict_inode(struct inode *inode)
> }
>
> /* Remove xattr references. */
> - err = ext4_xattr_delete_inode(handle, inode, &ea_inode_array,
> - extra_credits);
> + err = ext4_xattr_delete_inode(handle, inode, extra_credits);
> if (err) {
> ext4_warning(inode->i_sb, "xattr delete (err %d)", err);
> stop_handle:
> @@ -291,7 +289,6 @@ void ext4_evict_inode(struct inode *inode)
> ext4_orphan_del(NULL, inode);
> if (freeze_protected)
> sb_end_intwrite(inode->i_sb);
> - ext4_xattr_inode_array_free(ea_inode_array);
> goto no_delete;
> }
>
> @@ -321,7 +318,6 @@ void ext4_evict_inode(struct inode *inode)
> ext4_journal_stop(handle);
> if (freeze_protected)
> sb_end_intwrite(inode->i_sb);
> - ext4_xattr_inode_array_free(ea_inode_array);
> return;
> no_delete:
> /*
> diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
> index d6950b0b8f40..01b9aff0cd25 100644
> --- a/fs/ext4/xattr.c
> +++ b/fs/ext4/xattr.c
> @@ -114,10 +114,6 @@ const struct xattr_handler * const ext4_xattr_handlers[] = {
> #define EA_INODE_CACHE(inode) (((struct ext4_sb_info *) \
> inode->i_sb->s_fs_info)->s_ea_inode_cache)
>
> -static int
> -ext4_expand_inode_array(struct ext4_xattr_inode_array **ea_inode_array,
> - struct inode *inode);
> -
> #ifdef CONFIG_LOCKDEP
> void ext4_xattr_inode_set_class(struct inode *ea_inode)
> {
> @@ -1160,7 +1156,6 @@ static void
> ext4_xattr_inode_dec_ref_all(handle_t *handle, struct inode *parent,
> struct buffer_head *bh,
> struct ext4_xattr_entry *first, bool block_csum,
> - struct ext4_xattr_inode_array **ea_inode_array,
> int extra_credits, bool skip_quota)
> {
> struct inode *ea_inode;
> @@ -1197,14 +1192,6 @@ ext4_xattr_inode_dec_ref_all(handle_t *handle, struct inode *parent,
> if (err)
> continue;
>
> - err = ext4_expand_inode_array(ea_inode_array, ea_inode);
> - if (err) {
> - ext4_warning_inode(ea_inode,
> - "Expand inode array err=%d", err);
> - ext4_put_ea_inode(parent->i_sb, ea_inode);
> - continue;
> - }
> -
> err = ext4_journal_ensure_credits_fn(handle, credits, credits,
> ext4_free_metadata_revoke_credits(parent->i_sb, 1),
> ext4_xattr_restart_fn(handle, parent, bh, block_csum,
> @@ -1212,6 +1199,7 @@ ext4_xattr_inode_dec_ref_all(handle_t *handle, struct inode *parent,
> if (err < 0) {
> ext4_warning_inode(ea_inode, "Ensure credits err=%d",
> err);
> + ext4_put_ea_inode(parent->i_sb, ea_inode);
> continue;
> }
> if (err > 0) {
> @@ -1221,6 +1209,7 @@ ext4_xattr_inode_dec_ref_all(handle_t *handle, struct inode *parent,
> ext4_warning_inode(ea_inode,
> "Re-get write access err=%d",
> err);
> + ext4_put_ea_inode(parent->i_sb, ea_inode);
> continue;
> }
> }
> @@ -1229,6 +1218,7 @@ ext4_xattr_inode_dec_ref_all(handle_t *handle, struct inode *parent,
> if (err) {
> ext4_warning_inode(ea_inode, "ea_inode dec ref err=%d",
> err);
> + ext4_put_ea_inode(parent->i_sb, ea_inode);
> continue;
> }
>
> @@ -1245,6 +1235,7 @@ ext4_xattr_inode_dec_ref_all(handle_t *handle, struct inode *parent,
> entry->e_value_inum = 0;
> entry->e_value_size = 0;
>
> + ext4_put_ea_inode(parent->i_sb, ea_inode);
> dirty = true;
> }
>
> @@ -1271,7 +1262,6 @@ ext4_xattr_inode_dec_ref_all(handle_t *handle, struct inode *parent,
> static void
> ext4_xattr_release_block(handle_t *handle, struct inode *inode,
> struct buffer_head *bh,
> - struct ext4_xattr_inode_array **ea_inode_array,
> int extra_credits)
> {
> struct mb_cache *ea_block_cache = EA_BLOCK_CACHE(inode);
> @@ -1313,7 +1303,6 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode,
> ext4_xattr_inode_dec_ref_all(handle, inode, bh,
> BFIRST(bh),
> true /* block_csum */,
> - ea_inode_array,
> extra_credits,
> true /* skip_quota */);
> ext4_free_blocks(handle, inode, bh, 0, 1,
> @@ -2182,12 +2171,8 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
>
> /* Drop the previous xattr block. */
> if (bs->bh && bs->bh != new_bh) {
> - struct ext4_xattr_inode_array *ea_inode_array = NULL;
> -
> ext4_xattr_release_block(handle, inode, bs->bh,
> - &ea_inode_array,
> 0 /* extra_credits */);
> - ext4_xattr_inode_array_free(ea_inode_array);
> }
> error = 0;
>
> @@ -2863,46 +2848,6 @@ int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
> return error;
> }
>
> -#define EIA_INCR 16 /* must be 2^n */
> -#define EIA_MASK (EIA_INCR - 1)
> -
> -/* Add the large xattr @inode into @ea_inode_array for deferred iput().
> - * If @ea_inode_array is new or full it will be grown and the old
> - * contents copied over.
> - */
> -static int
> -ext4_expand_inode_array(struct ext4_xattr_inode_array **ea_inode_array,
> - struct inode *inode)
> -{
> - if (*ea_inode_array == NULL) {
> - /*
> - * Start with 15 inodes, so it fits into a power-of-two size.
> - */
> - (*ea_inode_array) = kmalloc_flex(**ea_inode_array, inodes,
> - EIA_MASK, GFP_NOFS);
> - if (*ea_inode_array == NULL)
> - return -ENOMEM;
> - (*ea_inode_array)->count = 0;
> - } else if (((*ea_inode_array)->count & EIA_MASK) == EIA_MASK) {
> - /* expand the array once all 15 + n * 16 slots are full */
> - struct ext4_xattr_inode_array *new_array = NULL;
> -
> - new_array = kmalloc_flex(**ea_inode_array, inodes,
> - (*ea_inode_array)->count + EIA_INCR,
> - GFP_NOFS);
> - if (new_array == NULL)
> - return -ENOMEM;
> - memcpy(new_array, *ea_inode_array,
> - struct_size(*ea_inode_array, inodes,
> - (*ea_inode_array)->count));
> - kfree(*ea_inode_array);
> - *ea_inode_array = new_array;
> - }
> - (*ea_inode_array)->count++;
> - (*ea_inode_array)->inodes[(*ea_inode_array)->count - 1] = inode;
> - return 0;
> -}
> -
> /*
> * ext4_xattr_delete_inode()
> *
> @@ -2913,7 +2858,6 @@ ext4_expand_inode_array(struct ext4_xattr_inode_array **ea_inode_array,
> * references on xattr block and xattr inodes.
> */
> int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
> - struct ext4_xattr_inode_array **ea_inode_array,
> int extra_credits)
> {
> struct buffer_head *bh = NULL;
> @@ -2952,7 +2896,6 @@ int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
> ext4_xattr_inode_dec_ref_all(handle, inode, iloc.bh,
> IFIRST(header),
> false /* block_csum */,
> - ea_inode_array,
> extra_credits,
> false /* skip_quota */);
> }
> @@ -2991,7 +2934,7 @@ int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
>
> }
>
> - ext4_xattr_release_block(handle, inode, bh, ea_inode_array,
> + ext4_xattr_release_block(handle, inode, bh,
> extra_credits);
> /*
> * Update i_file_acl value in the same transaction that releases
> @@ -3013,19 +2956,6 @@ int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
> return error;
> }
>
> -void ext4_xattr_inode_array_free(struct ext4_xattr_inode_array *ea_inode_array)
> -{
> - int idx;
> -
> - if (ea_inode_array == NULL)
> - return;
> -
> - for (idx = 0; idx < ea_inode_array->count; ++idx)
> - iput(ea_inode_array->inodes[idx]);
> - kfree(ea_inode_array);
> -}
> -
> -
> /*
> * Worker function for deferred EA inode iput. Processes all inodes queued
> * on s_ea_inode_to_free in a context free of xattr_sem/jbd2 handle locks.
> diff --git a/fs/ext4/xattr.h b/fs/ext4/xattr.h
> index ad98f7e7348d..518f0283e174 100644
> --- a/fs/ext4/xattr.h
> +++ b/fs/ext4/xattr.h
> @@ -131,11 +131,6 @@ struct ext4_xattr_ibody_find {
> struct ext4_iloc iloc;
> };
>
> -struct ext4_xattr_inode_array {
> - unsigned int count;
> - struct inode *inodes[] __counted_by(count);
> -};
> -
> extern const struct xattr_handler ext4_xattr_user_handler;
> extern const struct xattr_handler ext4_xattr_trusted_handler;
> extern const struct xattr_handler ext4_xattr_security_handler;
> @@ -187,9 +182,7 @@ extern int __ext4_xattr_set_credits(struct super_block *sb, struct inode *inode,
> bool is_create);
>
> extern int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
> - struct ext4_xattr_inode_array **array,
> int extra_credits);
> -extern void ext4_xattr_inode_array_free(struct ext4_xattr_inode_array *array);
> extern void ext4_init_ea_inode_work(struct ext4_sb_info *sbi);
> extern void ext4_put_ea_inode(struct super_block *sb, struct inode *inode);
>
> --
> 2.43.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2026-06-29 11:42 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-29 11:08 [PATCH v11 0/5] ext4: deferred iput framework for EA inodes Yun Zhou
2026-06-29 11:08 ` [PATCH v11 1/5] fs: add iput_if_not_last() helper Yun Zhou
2026-06-30 8:53 ` Christian Brauner
2026-06-30 9:05 ` Mateusz Guzik
2026-06-30 11:34 ` Jan Kara
2026-07-02 13:35 ` Zhou, Yun
2026-07-02 14:29 ` Jan Kara
2026-07-02 14:55 ` Zhou, Yun
2026-07-02 22:41 ` Theodore Tso
2026-06-29 11:08 ` [PATCH v11 2/5] ext4: introduce ext4_put_ea_inode() for safe deferred iput Yun Zhou
2026-06-29 11:34 ` Jan Kara
2026-06-29 11:37 ` Jan Kara
2026-06-29 11:08 ` [PATCH v11 3/5] ext4: convert all EA inode iput() calls to ext4_put_ea_inode() Yun Zhou
2026-06-29 11:38 ` Jan Kara
2026-06-29 11:08 ` [PATCH v11 4/5] ext4: remove ea_inode_array mechanism in favor of ext4_put_ea_inode() Yun Zhou
2026-06-29 11:42 ` Jan Kara [this message]
2026-06-29 11:08 ` [PATCH v11 5/5] ext4: prevent deadlock from duplicate EA inode references on corrupted fs Yun Zhou
2026-06-29 11:48 ` Jan Kara
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=m5r4btltl5swpuifvrmobsmmjyrgxckgp4fpsenuf5fofnqlqj@poubnm4v42of \
--to=jack@suse.cz \
--cc=adilger.kernel@dilger.ca \
--cc=brauner@kernel.org \
--cc=libaokun@linux.alibaba.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ojaswin@linux.ibm.com \
--cc=ritesh.list@gmail.com \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
--cc=xiaowu.417@qq.com \
--cc=yi.zhang@huawei.com \
--cc=yun.zhou@windriver.com \
/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