Skip to contentSkip to conversation

ext4: Avoid entering writeback paths during fastcommit replay

PATCH Applied Jan Kara 5 participants 8 messages Aug 4 – Aug 21 ext4 file system

lore
Share & tools
lore

Jan Kara

author reviewer
#0 lore raw

PATCH 1/1 ext4: Avoid entering writeback paths during fastcommit replay

Fastcommit replay effectively happens in nojournal mode. This results in ext4_mark_iloc_dirty() setting I_METADATA_WRITEBACK flag and as a result we end up entering filesystem writeback functions. However during fastcommit replay s_writepages_rwsem isn't initialized yet and hence we crash.

Fix the problem by avoiding setting I_METADATA_WRITEBACK during fastcommit replay. Journal replay flushes the whole block device after replay anyway so all metadata is properly persisted and replay is faster this way as a bonus.

Fixes c26339e1df33 ("ext4: Fix data integrity writeout issues in nojournal mode")
---
 fs/ext4/inode.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Christian, please add this fixup to my sync fixing series. Thanks!

fs/ext4/inode.c +8 -3
index 7a1f961cd11c..12ff84ab5741 100644
@@ -6408,9 +6408,10 @@ int ext4_chunk_trans_blocks(struct inode *inode, int nrblocks)
 int ext4_mark_iloc_dirty(handle_t *handle,
 			 struct inode *inode, struct ext4_iloc *iloc)
 {
+	struct super_block *sb = inode->i_sb;
 	int err = 0;
 
-	err = ext4_emergency_state(inode->i_sb);
+	err = ext4_emergency_state(sb);
 	if (unlikely(err)) {
 		put_bh(iloc->bh);
 		return err;
@@ -6425,9 +6426,13 @@ int ext4_mark_iloc_dirty(handle_t *handle,
 	put_bh(iloc->bh);
 	/*
 	 * Mark that there's metadata writeout pending for the inode so that it
-	 * gets properly flushed on fsync(2) and similar.
+	 * gets properly flushed on fsync(2) and similar. We don't bother for
+	 * fastcommit replay as that flushes the whole bdev afterwards anyway.
+	 * It is faster this way and we avoid entering fs writeback paths which
+	 * aren't fully initialized yet.
 	 */
-	if (!EXT4_SB(inode->i_sb)->s_journal) {
+	if (!ext4_handle_valid(handle) &&
+	    !(EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY)) {
 		/*
 		 * Inode didn't need to go through dirtying, make sure it is
 		 * attached to wb so that writeback can handle it.
Signature · 1 line
2.51.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Jan Kara

Fastcommit replay effectively happens in nojournal mode. This results in ext4_mark_iloc_dirty() setting I_METADATA_WRITEBACK flag and as a result we end up entering filesystem writeback functions. However during fastcommit replay s_writepages_rwsem isn't initialized yet and hence we crash.

Fix the problem by avoiding setting I_METADATA_WRITEBACK during fastcommit replay. Journal replay flushes the whole block device after replay anyway so all metadata is properly persisted and replay is faster this way as a bonus.

Quoted 5 lines
Fixes c26339e1df33 ("ext4: Fix data integrity writeout issues in nojournal mode")

---

Hey Jan, yes makese sense and it is fixing the issue for me. Feel free to add:

Regards,
ojaswin

Quoted 40 lines
 fs/ext4/inode.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Christian, please add this fixup to my sync fixing series. Thanks!

fs/ext4/inode.c +8 -3
index 7a1f961cd11c..12ff84ab5741 100644
@@ -6408,9 +6408,10 @@ int ext4_chunk_trans_blocks(struct inode *inode, int nrblocks)
 int ext4_mark_iloc_dirty(handle_t *handle,
 			 struct inode *inode, struct ext4_iloc *iloc)
 {
+	struct super_block *sb = inode->i_sb;
 	int err = 0;
 
-	err = ext4_emergency_state(inode->i_sb);
+	err = ext4_emergency_state(sb);
 	if (unlikely(err)) {
 		put_bh(iloc->bh);
 		return err;
@@ -6425,9 +6426,13 @@ int ext4_mark_iloc_dirty(handle_t *handle,
 	put_bh(iloc->bh);
 	/*
 	 * Mark that there's metadata writeout pending for the inode so that it
-	 * gets properly flushed on fsync(2) and similar.
+	 * gets properly flushed on fsync(2) and similar. We don't bother for
+	 * fastcommit replay as that flushes the whole bdev afterwards anyway.
+	 * It is faster this way and we avoid entering fs writeback paths which
+	 * aren't fully initialized yet.
 	 */
-	if (!EXT4_SB(inode->i_sb)->s_journal) {
+	if (!ext4_handle_valid(handle) &&
+	    !(EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY)) {
 		/*
 		 * Inode didn't need to go through dirtying, make sure it is
 		 * attached to wb so that writeback can handle it.
Signature · 1 line
2.51.0
maintainer
#2 lore raw
In reply to Jan Kara
Quoted 9 lines · Jan Kara

Fastcommit replay effectively happens in nojournal mode. This results in ext4_mark_iloc_dirty() setting I_METADATA_WRITEBACK flag and as a result we end up entering filesystem writeback functions. However during fastcommit replay s_writepages_rwsem isn't initialized yet and hence we crash.

Fix the problem by avoiding setting I_METADATA_WRITEBACK during fastcommit replay. Journal replay flushes the whole block device after replay anyway so all metadata is properly persisted and replay is faster

It looks like this patch is only applicable if the patch series "fs:
Fix missed inode write during fsync" is applied, and in fact appears to fix a problem introduced in "[PATCH v5 17/20] ext4: Fix data integrity writeout issues in nojournal mode"?

- Ted

author reviewer
#3 lore raw
Quoted 7 lines · Theodore Tso
Quoted 6 lines · Jan Kara

Fastcommit replay effectively happens in nojournal mode. This results in ext4_mark_iloc_dirty() setting I_METADATA_WRITEBACK flag and as a result we end up entering filesystem writeback functions. However during fastcommit replay s_writepages_rwsem isn't initialized yet and hence we crash.

Quoted 8 lines
Quoted 3 lines

Fix the problem by avoiding setting I_METADATA_WRITEBACK during fastcommit replay. Journal replay flushes the whole block device after replay anyway so all metadata is properly persisted and replay is faster

It looks like this patch is only applicable if the patch series "fs:
Fix missed inode write during fsync" is applied, and in fact appears to fix a problem introduced in "[PATCH v5 17/20] ext4: Fix data integrity writeout issues in nojournal mode"?

Right, yes, it's meant for Christian to pick this patch up to his tree.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
Tested-by on v1 1/1
#4 lore raw
In reply to Jan Kara
Quoted 11 lines · Jan Kara

Fastcommit replay effectively happens in nojournal mode. This results in ext4_mark_iloc_dirty() setting I_METADATA_WRITEBACK flag and as a result we end up entering filesystem writeback functions. However during fastcommit replay s_writepages_rwsem isn't initialized yet and hence we crash.

Fix the problem by avoiding setting I_METADATA_WRITEBACK during fastcommit replay. Journal replay flushes the whole block device after replay anyway so all metadata is properly persisted and replay is faster this way as a bonus.

Quoted 5 lines
Fixes c26339e1df33 ("ext4: Fix data integrity writeout issues in nojournal mode")

---

Tested this patch and its fixes the reported issue. Hence,

Regards,

Venkat.

Quoted 37 lines
  fs/ext4/inode.c | 11 ++++++++---
  1 file changed, 8 insertions(+), 3 deletions(-)

Christian, please add this fixup to my sync fixing series. Thanks!

fs/ext4/inode.c +8 -3
index 7a1f961cd11c..12ff84ab5741 100644
@@ -6408,9 +6408,10 @@ int ext4_chunk_trans_blocks(struct inode *inode, int nrblocks)
  int ext4_mark_iloc_dirty(handle_t *handle,
  			 struct inode *inode, struct ext4_iloc *iloc)
  {
+	struct super_block *sb = inode->i_sb;
  	int err = 0;
 
-	err = ext4_emergency_state(inode->i_sb);
+	err = ext4_emergency_state(sb);
  	if (unlikely(err)) {
  		put_bh(iloc->bh);
  		return err;
@@ -6425,9 +6426,13 @@ int ext4_mark_iloc_dirty(handle_t *handle,
  	put_bh(iloc->bh);
  	/*
  	 * Mark that there's metadata writeout pending for the inode so that it
-	 * gets properly flushed on fsync(2) and similar.
+	 * gets properly flushed on fsync(2) and similar. We don't bother for
+	 * fastcommit replay as that flushes the whole bdev afterwards anyway.
+	 * It is faster this way and we avoid entering fs writeback paths which
+	 * aren't fully initialized yet.
  	 */
-	if (!EXT4_SB(inode->i_sb)->s_journal) {
+	if (!ext4_handle_valid(handle) &&
+	    !(EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY)) {
  		/*
  		 * Inode didn't need to go through dirtying, make sure it is
  		 * attached to wb so that writeback can handle it.
author reviewer
#5 lore raw
In reply to Jan Kara

Hello Christian!

With all the vacations going on this fixup to apply on top of vfs-7.3.sync branch seems to have fallen through the cracks (I guess the note below the changelog was too hidden, next time I'll try to indicate this is a fixup inside the subject - maybe like [PATCH FIXUP vfs-7.3.sync]). Anyway, can you please pick it up and push it to Linus later during the merge window? Thanks!

Honza

Quoted 56 lines · Jan Kara

Fastcommit replay effectively happens in nojournal mode. This results in ext4_mark_iloc_dirty() setting I_METADATA_WRITEBACK flag and as a result we end up entering filesystem writeback functions. However during fastcommit replay s_writepages_rwsem isn't initialized yet and hence we crash.

Fix the problem by avoiding setting I_METADATA_WRITEBACK during fastcommit replay. Journal replay flushes the whole block device after replay anyway so all metadata is properly persisted and replay is faster this way as a bonus.

Fixes c26339e1df33 ("ext4: Fix data integrity writeout issues in nojournal mode")
---
 fs/ext4/inode.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Christian, please add this fixup to my sync fixing series. Thanks!

fs/ext4/inode.c +8 -3
index 7a1f961cd11c..12ff84ab5741 100644
@@ -6408,9 +6408,10 @@ int ext4_chunk_trans_blocks(struct inode *inode, int nrblocks)
 int ext4_mark_iloc_dirty(handle_t *handle,
 			 struct inode *inode, struct ext4_iloc *iloc)
 {
+	struct super_block *sb = inode->i_sb;
 	int err = 0;
 
-	err = ext4_emergency_state(inode->i_sb);
+	err = ext4_emergency_state(sb);
 	if (unlikely(err)) {
 		put_bh(iloc->bh);
 		return err;
@@ -6425,9 +6426,13 @@ int ext4_mark_iloc_dirty(handle_t *handle,
 	put_bh(iloc->bh);
 	/*
 	 * Mark that there's metadata writeout pending for the inode so that it
-	 * gets properly flushed on fsync(2) and similar.
+	 * gets properly flushed on fsync(2) and similar. We don't bother for
+	 * fastcommit replay as that flushes the whole bdev afterwards anyway.
+	 * It is faster this way and we avoid entering fs writeback paths which
+	 * aren't fully initialized yet.
 	 */
-	if (!EXT4_SB(inode->i_sb)->s_journal) {
+	if (!ext4_handle_valid(handle) &&
+	    !(EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY)) {
 		/*
 		 * Inode didn't need to go through dirtying, make sure it is
 		 * attached to wb so that writeback can handle it.
Signature · 1 line
2.51.0
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#7 lore raw
In reply to Jan Kara
Quoted 6 lines · Jan Kara

Fastcommit replay effectively happens in nojournal mode. This results in ext4_mark_iloc_dirty() setting I_METADATA_WRITEBACK flag and as a result we end up entering filesystem writeback functions. However during fastcommit replay s_writepages_rwsem isn't initialized yet and hence we crash.

Quoted 6 lines

Fix the problem by avoiding setting I_METADATA_WRITEBACK during fastcommit replay. Journal replay flushes the whole block device after replay anyway so all metadata is properly persisted and replay is faster this way as a bonus.

[...]

Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/1] ext4: Avoid entering writeback paths during fastcommit replay

      https://git.kernel.org/vfs/vfs/c/0ecd56573c1f
#6 lore raw
In reply to Jan Kara
Quoted 8 lines · Jan Kara

Hello Christian!

With all the vacations going on this fixup to apply on top of vfs-7.3.sync branch seems to have fallen through the cracks (I guess the note below the changelog was too hidden, next time I'll try to indicate this is a fixup inside the subject - maybe like [PATCH FIXUP vfs-7.3.sync]). Anyway, can you please pick it up and push it to Linus later during the merge window? Thanks!

Yes, sorrry I missed this! Picked it up now. Thanks for reminding me!

Christian