Understanding ext4 JBD2 Journal Commit Bottlenecks Under Concurrent fdatasync
Why un-preallocated appends serialize behind the global jbd2/vda1-8 journal transaction lock, and when XFS or fallocated ext4 nojournal_checksum wins.
1. When fdatasync Still Triggers a Full Metadata Journal Commit
In theory, fdatasync(2) only flushes file data blocks and skips inode timestamp updates unless the file's size or block allocation map changed. However, when 16 worker threads append to 16 separate log files without prior fallocate(2), every append allocates new blocks and marks the inode dirty, forcing ext4_sync_file to wait on the global jbd2 transaction commit.
# offcputime-bpfcc -df -p $(pgrep storage-worker) 10
ext4_sync_file
jbd2_complete_transaction
log_wait_commit
schedule -> 84.2% of off-CPU wait time
Pre-allocating files with fallocate(fd, FALLOC_FL_KEEP_SIZE, 0, seg_len) (or migrating multi-file concurrent write workloads to XFS with independent allocation groups) reduced 99th-percentile fdatasync serialization delay from 4.8 ms to 0.31 ms.