A topic in the Open Knowledge Graph — a free, open map of 15,495 topics and the order to learn them in.

Crash Consistency and Journaling File Systems

College Depth 107 in the knowledge graph ☐ I know this ☆ Set as goal
409prerequisites beneath it
See this on the map →
File System ConceptsFile System Implementation+1 more→
file-systems journaling crash-consistency fsck write-ahead-logging persistence

Core Idea

A single file operation, such as appending one block, changes several on-disk structures: the data block, the inode and the free-space bitmap. The disk writes them one at a time, so a power loss or crash in between can leave the structures disagreeing with one another. Crash consistency is the problem of making sure the file system can always return to a consistent state. Journaling solves it by first writing a description of the planned updates to a log (the journal), marking it committed, and only then writing the updates in place, so recovery can simply replay committed entries.

How It's Best Learned

List the three writes needed to append a block, then enumerate every crash point and the state each leaves behind, as in the OSTEP chapter on crash consistency. Compare the cost of the older fix, a full-disk scan with `fsck`, against replaying a small journal. Finish by comparing data journaling with ordered (metadata-only) journaling, which ext4 uses by default.

Common Misconceptions

Explainer

From file system implementation you know that a file is described by an inode, its contents live in data blocks, and a bitmap records which blocks are free. Now look at an ordinary operation: appending 4 KB to a file. Three on-disk structures must change. A new data block is written, the inode gains a pointer to it and a larger size, and the data bitmap marks the block used.

The disk can persist only one write at a time, and the system may crash or lose power between any two. Each crash point leaves a different mess. If only the data block is written, nothing points to it, so the data is lost but the structures still agree. If only the inode is written, it points to a block that may hold old garbage, and the bitmap still calls that block free. If only the bitmap is written, a block is marked used but belongs to no file, so space leaks. This is the crash-consistency problem.

The older answer was to let crashes happen and repair afterward. A tool called fsck scans every inode, directory and bitmap and fixes disagreements. It works, but it is slow, because its time grows with the size of the disk. On a large disk it can take many minutes or longer.

Journaling, a form of write-ahead logging, avoids the scan. Before touching the real structures, the file system writes a transaction to a reserved area called the journal: a begin block, copies of the blocks it is about to change, and finally a commit block. Once the commit block is on disk, the transaction is durable. The file system then writes the blocks to their real locations, a step called checkpointing, and later frees that journal space. After a crash, recovery reads the journal, replays every transaction that has a commit block, and ignores incomplete ones. Either the whole update happens or none of it does.

Copying user data into the journal doubles the cost of every write, so most systems journal only metadata. In ext4's default ordered mode, the data block is written to its final location before the metadata transaction commits. That way an inode never ends up pointing at garbage. Other file systems, such as ZFS and Btrfs, use copy-on-write instead. They never overwrite live blocks in place, and they switch to the new version with a single atomic pointer update.

Practice Questions 4 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Combining Small Groups Within 5 → Number Bonds Within 5 → Number Bonds to 10 → Tens and Ones Place Value → Reading and Writing Three-Digit Numbers → Comparing Three-Digit Numbers → Comparing and Ordering Three-Digit Quantities → Comparing and Ordering Whole Numbers → Comparing Numbers 1 to 20 → Ordering Numbers to 20 → Number Line 0 to 20 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Opposites and Additive Inverses → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Boolean Algebra and Fundamental Laws → Logic Gates Fundamentals → Implementing Boolean Functions with Gates → Karnaugh Map Simplification → Combinational Circuit Design → Flip-Flops and Latches → Binary Counters: Design and Analysis → Binary Arithmetic → Fixed-Point Number Representation → Two's Complement Representation → Overflow and Underflow Detection → Binary Adders: Half-Adders and Full-Adders → Full Adder and Carry Propagation → Carry Lookahead Adder Design → Half Adder Circuit Design → Multiplication Circuit Design → Sequential Circuit Design → Registers and Register Files → Instruction Set Architecture (ISA) → Assembly Language Basics → Memory Organization and Addressing → Memory Hierarchy → Memory Management Fundamentals → Contiguous Memory Allocation and Fragmentation → Paging and Page Tables → File System Implementation → Crash Consistency and Journaling File Systems

Longest path: 108 steps · 409 total prerequisite topics

Prerequisites (3)

Leads To (0)

No topics depend on this one yet.