ext2: only flush DIRSYNC directories on every change
PATCH 1/1 ext2: only flush DIRSYNC directories on every change
Every change of an ext2 directory is written to disk before the system call returns, whether the directory is DIRSYNC or not: its pages with filemap_write_and_wait() and its inode with sync_inode_metadata().
Writes which reach the device for 2000 files, and 200 directories, in a directory without DIRSYNC, with the flusher turned off:
create rename unlink mkdir
before 4000 8000 4000 800
after 0 0 0 0
In a directory with chattr +D the numbers are those of "before", before and after.
commit bc943f4872a7 ("ext2: Don't flush page immediately for DIRSYNC directories") moved the flush from ext2_commit_chunk() to the new ext2_handle_dirsync(). The IS_DIRSYNC() check which was around it didn't move along.
Fix by putting the check into ext2_handle_dirsync().
---
I ran into this while testing an overlayfs series with ext2 as the upper file system. Directory entries were always on disk after a crash, also the ones nobody had synced.
--- fs/ext2/dir.c | 3 +++ 1 file changed, 3 insertions(+)
fs/ext2/dir.c +3 -0
@@ -442,6 +442,9 @@ static int ext2_handle_dirsync(struct inode *dir) {int err; +if (!IS_DIRSYNC (dir)) +return 0 ; + err =filemap_write_and_wait (dir->i_mapping);if (!err) err =sync_inode_metadata (dir,1 );
---
base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
change-id: 20261027-b4-ext2-dirsync-86ca140154bc
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 19 lines
Every change of an ext2 directory is written to disk before the system call returns, whether the directory is DIRSYNC or not: its pages with
filemap_write_and_wait()and its inode withsync_inode_metadata().Writes which reach the device for 2000 files, and 200 directories, in a directory without DIRSYNC, with the flusher turned off:
create rename unlink mkdir
before 4000 8000 4000 800
after 0 0 0 0In a directory with chattr +D the numbers are those of "before", before and after.
commit
bc943f4872a7("ext2: Don't flush page immediately for DIRSYNC directories") moved the flush fromext2_commit_chunk()to the newext2_handle_dirsync(). TheIS_DIRSYNC()check which was around it didn't move along.
Quoted 4 lines
Fix by putting the check into
ext2_handle_dirsync().Fixes bc943f4872a7 ("ext2: Don't flush page immediately for DIRSYNC directories")Signed-off-by Josef Bacik <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 19 lines · Josef Bacik
Every change of an ext2 directory is written to disk before the system call returns, whether the directory is DIRSYNC or not: its pages with
filemap_write_and_wait()and its inode withsync_inode_metadata().Writes which reach the device for 2000 files, and 200 directories, in a directory without DIRSYNC, with the flusher turned off:
create rename unlink mkdir
before 4000 8000 4000 800
after 0 0 0 0In a directory with chattr +D the numbers are those of "before", before and after.
commit
bc943f4872a7("ext2: Don't flush page immediately for DIRSYNC directories") moved the flush fromext2_commit_chunk()to the newext2_handle_dirsync(). TheIS_DIRSYNC()check which was around it didn't move along.
Quoted 4 lines
Fix by putting the check into
ext2_handle_dirsync().Fixes bc943f4872a7 ("ext2: Don't flush page immediately for DIRSYNC directories")Signed-off-by Josef Bacik <[email protected]>
Thanks! Added to my tree.
Honza
Quoted 27 lines
---
I ran into this while testing an overlayfs series with ext2 as the upper file system. Directory entries were always on disk after a crash, also the ones nobody had synced.--- fs/ext2/dir.c | 3 +++ 1 file changed, 3 insertions(+)fs/ext2/dir.c +3
-1@@ -442,6 +442,9 @@ static int ext2_handle_dirsync(struct inode *dir) {int err; +if (!IS_DIRSYNC (dir)) +return 0 ; + err =filemap_write_and_wait (dir->i_mapping);if (!err) err =sync_inode_metadata (dir,1 ); ---base-commit:
c03c1a14507dfaf8b856c2608f9ac216021fc222
change-id: 20261027-b4-ext2-dirsync-86ca140154bc
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR