Part 1 of 7 · 2 min read
Why this page comes fourth
In this module you will
- Explain why one file operation needs several disk writes, and what a crash between them leaves.
- Classify the disk after a crash at each point of a three-write update.
- Describe what
fsckchecks, and why it takes so long on a large disk. - Describe write-ahead logging: journal, commit, checkpoint and replay, with the write counts.
- Compare the journal modes, and write a program that replaces a file atomically.
Page 2 ended with a delete that changes three places on disk. A power cut can arrive between any two of the writes. Level 8 showed that writes may also be reordered, since caches and schedulers reorder them. This page shows what that does to the structures, and how file systems avoid the damage. The idea of a log that is written before the real change returns in databases and in Level 12.
About this example About this example
Real: The C programs of sections 1 and 5 were compiled with gcc -Wall -Wextra and run on a Linux test machine (kernel 6.18, e2fsprogs 1.47.0). The e2fsck output in section 2 came from a 16 MiB ext4 image with a journal, which I damaged on purpose with debugfs -w. The default journal of 4 MiB was read from dumpe2fs -h.
Scripted: The transaction of three metadata blocks, the write counts of the journal and the fsck time of 11.5 minutes (64 GiB of inode tables at 100 MB/s) are made up to show the idea. The program in section 1 classifies a simplified model of an append, not real ext4 code.
Not real: No real crash was caused. The damage in section 2 was set by hand to show what fsck reports. Real file systems also have checksums, barriers and several journal modes that this page only outlines.