Skip to contentSkip to conversation

ext4: skip i_extra_isize expansion during inode eviction

PATCH In review Helen Koike 3 participants 4 messages Jul 15 – Jul 21 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index ce99807c5f5b..cea3405cd841 100644
@@ -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]

#2 lore raw
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 macro inode_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_isize expansion during inode eviction --- commit 118d9e758f25c66bbc15a2be5b297ae71d3991d9
Author: Helen Koike <[email protected]>

ext4: skip i_extra_isize expansion during inode eviction

This 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
index 03c2253005f00..ec31318c12d9d 100644
@@ -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 function inode_state_read_once() is undeclared when called here in __ext4_mark_inode_dirty() in fs/ext4/inode.c.

Quoted 3 lines
fs/ext4/inode.c +0 -0
  		ext4_try_to_expand_extra_isize(inode, sbi->s_want_extra_isize,
  					       iloc, handle);
 
Reviewed-by on v1 1/1
#3 lore raw
In reply to Helen Koike
Quoted 9 lines · Helen Koike

__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.

Reviewed-by Andreas Dilger <[email protected] <mailto:[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=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
index ce99807c5f5b..cea3405cd841 100644
@@ -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

maintainer
#4 lore raw
In reply to Helen Koike
Quoted 8 lines · Helen Koike

__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.

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