Aside Forcing Writes To Disk
This page is a generated reference surface for selective reading. It exists to keep the learner apps guide-first while still preserving source access.
Learning objectives
- Explain the main ideas and vocabulary in Aside Forcing Writes To Disk.
- Work through the source examples for Aside Forcing Writes To Disk without depending on raw chunk order.
- Use Aside Forcing Writes To Disk as selective reference when learner modules point back to Ostep.
Prerequisites
- None curated yet.
Module targets
module-04-file-systems-io
AI companion modes
- Explain simply
- Socratic tutor
- Quiz me
- Challenge my understanding
- Diagnose my confusion
- Generate extra practice
- Revision mode
- Connect forward / backward
Source-of-truth note
This unit is anchored to Ostep and the source chapter "Aside Forcing Writes To Disk". Use external resources only to clarify, extend, or modernize details without replacing the chapter's conceptual spine.
External enrichment
No chapter-specific enrichment resources are curated yet. Add them in the unit manifest when a source clearly improves learning.
Source provenance
- Primary source:
Ostep - Source chapter: Aside Forcing Writes To Disk
- Raw source file:
212-aside-forcingwritestodisk.md
Merged source
Aside Forcing Writes To Disk
ASIDE: FORCINGWRITESTODISK
To enforce ordering between two disk writes, modern file systems have to take a few extra precautions. In olden times, forcing ordering between two writes,AandB, was easy: just issue the write ofAto the disk, wait for the disk to interrupt the OS when the write is complete, and then issue the write ofB.
Things got slightly more complex due to the increased use of write caches within disks. With write buffering enabled (sometimes calledimmediate reporting), a disk will inform the OS the write is complete when it simply has been placed in the disk's memory cache, and has not yet reached disk. If the OS then issues a subsequent write, it is not guaranteed to reach the disk after previous writes; thus ordering between writes is not preserved. One solution is to disable write buffering. However, more modern systems take extra precautions and issue explicitwrite barriers;
such a barrier, when it completes, guarantees that all writes issued before the barrier will reach disk before any writes issued after the barrier.
All of this machinery requires a great deal of trust in the correct operation of the disk. Unfortunately, recent research shows that some disk manufacturers, in an effort to deliver "higher performing" disks, explicitly ignore write-barrier requests, thus making the disks seemingly run faster but at the risk of incorrect operation [C+13, R+11]. As Kahan said, the fast almost always beats out the slow, even if the fast is wrong.
all five block writes at once, as this would turn five writes into a single sequential write and thus be faster. However, this is unsafe, for the following reason: given such a big write, the disk internally may perform scheduling and complete small pieces of the big write in any order. Thus, the disk internally may (1) write TxB, I[v2], B[v2], and TxE and only later
(2) write Db. Unfortunately, if the disk loses power between (1) and (2),
this is what ends up on disk:
TxB I[v2] B[v2] ?? TxE
Journalid=1 id=1
Why is this a problem? Well, the transaction looks like a valid transaction (it has a begin and an end with matching sequence numbers). Further, the file system can't look at that fourth block and know it is wrong;
after all, it is arbitrary user data. Thus, if the system now reboots and runs recovery, it will replay this transaction, and ignorantly copy the contents of the garbage block '??' to the location where Db is supposed to live. This is bad for arbitrary user data in a file; it is much worse if it happens to a critical piece of file system, such as the superblock, which could render the file system unmountable.