ext4: skip i_extra_isize expansion during inode eviction
Subsystems (2)
PATCH 1/1 ext4: skip i_extra_isize expansion during inode eviction
__ext4_mark_inode_dirty may be called from the eviction/free path (via ext4_truncate → ext4_ext_truncate → mark_inode_dirty), which may call ext4_try_to_expand_extra_isize() that could create a new EA inode, wasting work that will be immediately discarded.
Skip the expansion when the inode is transitioning to freed.
---
Hello,
I saw this while investigating the syzbot issue (see the stack trace of unlink "-> #0"):
https://syzkaller.appspot.com/bug?extid=d91a6e2efb07bd3354e9
While the reported issue is fixed by:
7f473f971382 ("ext4: lockdep: handle i_data_sem subclassing for special inodes")
I believe the call to ext4_try_to_expand_extra_isize() in the eviction path doesn't make sense in the first place.
I understand this is not a major optimization, so not a high priority, but sending it anyway in case anyone finds it useful.
--- fs/ext4/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext4/inode.c +2 -1
@@ -6603,7 +6603,8 @@ int __ext4_mark_inode_dirty(handle_t *handle, struct inode *inode,if (err) goto out; -if (EXT4_I (inode)->i_extra_isize < sbi->s_want_extra_isize) +if (EXT4_I (inode)->i_extra_isize < sbi->s_want_extra_isize && + !(inode_state_read_once (inode) & (I_FREEING |I_WILL_FREE )))ext4_try_to_expand_extra_isize (inode, sbi->s_want_extra_isize, iloc, handle);
Signature · 1 line
2.54.0
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 2 lines · On 7/15/26 3:10 PM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The patch introduces a build failure by using an undeclared function or macroinode_state_read_once().
This is a false positive.
inode_state_read_once() is declared in linux/fs.h and is already used in other places in inode.c and it builds fine.
Helen
Quoted 33 lines
--
--- Patch [1]: [PATCH] ext4: skip
i_extra_isizeexpansion during inode eviction --- commit118d9e758f25c66bbc15a2be5b297ae71d3991d9
Author: Helen Koike <[email protected]>ext4: skip
i_extra_isizeexpansion during inode evictionThis commit modifies
__ext4_mark_inode_dirty()to skip expanding the inode extra isize when the inode is in the process of being freed. This avoids unnecessary work that will be discarded.fs/ext4/inode.c int __ext4_mark_inode_dirty(handle_t *handle, struct inode *inode, · line 5900
Quoted 11 lines
fs/ext4/inode.c +2
-1@@ -5896,7 +5896,8 @@ int __ext4_mark_inode_dirty(handle_t *handle, struct inode *inode,if (err) goto out; -if (EXT4_I (inode)->i_extra_isize < sbi->s_want_extra_isize) +if (EXT4_I (inode)->i_extra_isize < sbi->s_want_extra_isize && + !(inode_state_read_once (inode) & (I_FREEING |I_WILL_FREE )))[Severity: Low]
Does this code introduce a build failure? It looks like the macro or functioninode_state_read_once()is undeclared when called here in__ext4_mark_inode_dirty()infs/ext4/inode.c.Quoted 3 lines
fs/ext4/inode.c +0
-0ext4_try_to_expand_extra_isize (inode, sbi->s_want_extra_isize, iloc, handle);
Quoted 9 lines · Helen Koike
__ext4_mark_inode_dirtymay be called from the eviction/free path (viaext4_truncate→ext4_ext_truncate→mark_inode_dirty), which may callext4_try_to_expand_extra_isize()that could create a new EA inode, wasting work that will be immediately discarded.Skip the expansion when the inode is transitioning to freed.
Signed-off-by Helen Koike <[email protected]>
Quoted 36 lines
---
Hello,
I saw this while investigating the syzbot issue (see the stack trace of unlink "-> #0"):
https://syzkaller.appspot.com/bug?extid=d91a6e2efb07bd3354e9While the reported issue is fixed by:
7f473f971382("ext4: lockdep: handlei_data_semsubclassing for special inodes")
I believe the call toext4_try_to_expand_extra_isize()in the eviction path doesn't make sense in the first place.I understand this is not a major optimization, so not a high priority, but sending it anyway in case anyone finds it useful.
---fs/ext4/inode.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)fs/ext4/inode.c +2
-1@@ -6603,7 +6603,8 @@ int __ext4_mark_inode_dirty(handle_t *handle, struct inode *inode,if (err) goto out; -if (EXT4_I (inode)->i_extra_isize < sbi->s_want_extra_isize) +if (EXT4_I (inode)->i_extra_isize < sbi->s_want_extra_isize && + !(inode_state_read_once (inode) & (I_FREEING |I_WILL_FREE )))ext4_try_to_expand_extra_isize (inode, sbi->s_want_extra_isize, iloc, handle);Signature · 1 line
2.54.0
Cheers, Andreas
Theodore Tso
maintainerQuoted 8 lines · Helen Koike
__ext4_mark_inode_dirtymay be called from the eviction/free path (viaext4_truncate???ext4_ext_truncate???mark_inode_dirty), which may callext4_try_to_expand_extra_isize()that could create a new EA inode, wasting work that will be immediately discarded.Skip the expansion when the inode is transitioning to freed.
Signed-off-by Helen Koike <[email protected]>
This issue has been addressed via the patch[1] "ext4: set EXT4_STATE_NO_EXPAND in ext4_evict_inode".
[1] https://patch.msgid.link/[email protected]
Thanks,
- Ted