Part 2 of 7 · 2 min read
Update in place
Think of a notice board where every change means scraping a card and rewriting it at the same spot, even when the changes are in different corners. The writer walks around the board all day. The analogy stops in one place: a board has no memory of its older cards, while a file system could keep them.
In plain words: The file systems of pages 2 to 4 update in place. A small change to a file writes its data block, its inode, and perhaps a bitmap and a directory, and these are at four different places on the disk. On a spinning disk, each costs a seek (Level 8, page 1). A crash in the middle leaves a mixture, so a journal is needed. A different method writes every change to fresh space and never touches the old blocks until the new ones are safely in place. This gives sequential writes, and a clean choice between old and new.
A worked example (made up to show the idea). A program creates 100 small files. Each creation writes 3 blocks at three different places: the data, the inode and the directory block. With the drive of Level 8, a random 4 KiB write costs 13.2 ms. In place, the cost is 100 x 3 x 13.2 ms = 3.96 s. If all 300 blocks are collected into one sequential write of 300 x 4 KiB = 1,228,800 bytes, the cost is one seek and rotation of 13.17 ms plus a transfer of 1,228,800 / 100,000,000 s = 12.29 ms, which is 25.5 ms. The ratio is 3.96 s / 25.5 ms, about 155.
The key lines. The gain comes from turning many small random writes into one large sequential one. It needs a place to put the new blocks, and a way to find them later, since they no longer sit at fixed addresses.
Update in place
Update in place is the policy of changing data by overwriting it at its existing disk location. It keeps the layout of the file system fixed, and it makes each small change a random write and a possible crash-consistency problem.
Example: an ext4 file system that overwrites a data block at the same block number.
Check yourself: 1. How many random writes does creating one small file cost in the model? 2. Why does one large sequential write beat 300 small ones on a spinning disk? 3. What must a file system add if blocks no longer have fixed addresses?