File System Comparison
Journaling Support
Read aloud is unavailable in this browser.
The Guardian of Consistency
Power failures, system crashes, and kernel panics don't wait for file systems to finish their work. Without protection, these interruptions can leave storage in an inconsistent state—metadata pointing to non-existent data, allocation bitmaps disagreeing with actual usage, directory entries referencing corrupted inodes. The result? Filesystem corruption that requires lengthy recovery procedures and potentially permanent data loss.
Journaling solves this by recording intended changes before performing them. If a crash occurs, the journal provides a recovery path: either complete the interrupted operation or cleanly undo it. This transforms crash recovery from hours of fsck scanning to seconds of journal replay.
This page examines journaling implementations across major file systems, explaining how they work, what they protect, and what tradeoffs they embody.
By the end of this page, you will understand how journaling protects filesystem consistency, distinguish between metadata-only and full data journaling, recognize the architectural differences in journaling implementations across FAT, NTFS, ext4, XFS, ZFS, and Btrfs, appreciate the performance implications of different journaling modes, and understand recovery procedures and their time implications.
The Consistency Problem
Before understanding journaling, we must appreciate the problem it solves. File system operations that appear atomic to users often require multiple disk writes that can be interrupted mid-sequence.
Example: Creating a File
Creating a new file involves multiple interdependent disk writes:
- Allocate inode — Mark an inode as in-use in the inode bitmap
- Initialize inode — Write file attributes (size=0, permissions, timestamps)
- Update directory — Add directory entry linking filename to inode number
- Update directory inode — Increment link count, update modification time
- Write data blocks (if file has content)
- Update allocation bitmap — Mark data blocks as allocated
- Update inode — Record data block locations, update file size
What happens if power fails after step 3 but before step 1?
The directory points to an inode that was never allocated. Subsequent operations might:
- Allocate that inode for a different file → Two files sharing an inode → Catastrophe
- Consider the filesystem corrupted and refuse to mount
- Require fsck to detect and remove the orphaned entry
Without journaling, file systems attempted to order writes such that interruption left a recoverable (if imperfect) state. This "careful write ordering" was complex, error-prone, and couldn't prevent all inconsistency scenarios. Modern drives with write caches made ordering even harder to guarantee.
Inconsistency Categories:
| Inconsistency Type | Description | Consequence |
|---|---|---|
| Space leak | Blocks marked allocated but not referenced | Wasted space; not dangerous |
| Dangling pointer | Metadata references non-existent blocks | Potential data corruption |
| Cross-linked files | Multiple files reference same block | Catastrophic; data overwritten |
| Orphaned inode | Inode allocated but not in any directory | Lost file; recoverable via fsck |
| Bitmap mismatch | Allocation bitmap disagrees with actual usage | Space accounting errors |
| Directory inconsistency | Parent/child link counts don't match | Directory traversal failures |
The fsck Solution (Pre-Journaling):
Before journaling, fsck (file system check) scanned entire file systems to detect and repair inconsistencies:
- Walk all directories, recording referenced inodes
- Walk all inodes, recording referenced blocks
- Compare against allocation bitmaps
- Repair discrepancies
For large file systems, this took hours. A 10TB array might require 4-8 hours of fsck after every crash. During this time, the system was unavailable. This was unacceptable for production servers.
Journaling Fundamentals
Journaling (also called write-ahead logging) ensures consistency by recording operations before performing them. The principle is simple: log what you're about to do, then do it. If you crash, the log tells you what to finish or undo.
- •Transaction begins — Group related modifications into a logical transaction
- •Journal write — Write the complete transaction (or its redo information) to the journal
- •Commit record — Write a commit marker indicating the journal entry is complete
- •Checkpoint — Perform actual modifications to file system structures on disk
- •Journal reclaim — Mark journal space as reusable once checkpointing completes
Why This Works:
Crash during journal write (before commit): The transaction is incomplete. On recovery, it's discarded as if it never started. The file system remains in its previous consistent state.
Crash during checkpoint (after commit): The transaction is complete in the journal. On recovery, replay the journal to complete the modifications. The file system reaches the intended consistent state.
Key Insight: Journaling transforms the problem from "ensure complex multi-step operation is atomic" to "ensure single journal commit is atomic." Modern storage hardware can guarantee single-sector write atomicity, making the commit reliable.
Journals are typically placed in a reserved area of the file system (ext4, XFS) or on a dedicated device (ZFS SLOG, specialized NTFS configurations). External journals on fast devices (NVMe) can dramatically improve synchronous write performance.
Journal Types:
Redo Logging (Physical Journaling): The journal contains the new values of modified blocks. On replay, those values are written to their target locations.
- Advantage: Replay is simple—just write the blocks
- Disadvantage: Journal entries are large (entire blocks, not just changes)
Undo Logging: The journal contains the old values of blocks that will be modified. On recovery, operations are undone to restore previous state.
- Advantage: Smaller journal entries for small changes
- Disadvantage: Requires undo during crash recovery; more complex
Redo/Undo Logging: Both old and new values are logged. Provides maximum flexibility at the cost of larger journal entries.
Logical Journaling: Rather than physical block contents, the journal contains logical descriptions of operations ("create inode 12345 with permissions 0644"). Smaller journal entries but more complex replay.
Most file systems use physical redo logging for simplicity and reliability.
Journaling Modes and Coverage
Not all journaling is created equal. The critical distinction is what gets journaled: metadata only, or metadata plus data.
| Mode | Metadata Protected | Data Protected | Performance | Consistency Guarantee |
|---|---|---|---|---|
| No Journaling | ❌ No | ❌ No | Maximum | Full fsck required; data/metadata loss possible |
| Writeback | ✅ Yes | ❌ No* | Fastest journaled | FS structure consistent; stale data in files possible |
| Ordered | ✅ Yes | Ordering only | Moderate | FS consistent; no stale data exposure; files may be truncated |
| Journal/Data | ✅ Yes | ✅ Yes | Slowest | Full consistency; no data loss within journal capacity |
*Writeback mode journals metadata but allows data writes in any order relative to metadata
Understanding Ordered Mode (ext4 default):
Ordered journaling provides a critical safety property: data is written to disk before the metadata that references it.
Without this guarantee, a crash could leave:
- Metadata claiming a file has new blocks
- Those blocks containing old data from a previously deleted file
- Potential security exposure of deleted data
Ordered mode prevents this by:
- Writing file data blocks to their final locations
- Then journaling and committing the metadata update
This ensures that metadata always points to valid data, never to garbage. Performance is good because only metadata goes through the journal.
When Data Journaling Matters:
Full data journaling (ext4 data=journal, NTFS for small files) is rarely needed but essential for:
- Database write-ahead logs that must survive crashes with precise guarantees
- Financial transaction systems requiring absolute write ordering
- Application-level consistency that depends on file content atomicity
The cost: every data write happens twice (once to journal, once to final location), roughly halving write bandwidth.
Even with full data journaling, file systems don't guarantee application-level consistency. Writing file A then file B with data journaling ensures both files are internally consistent, but doesn't guarantee A and B together represent a consistent application state. Databases use their own transaction logs for this reason.
File System Journaling Comparison
Each file system implements journaling (or its equivalent) differently, reflecting its design philosophy and target use cases.
| File System | Mechanism | Coverage | Journal Size | Recovery Time |
|---|---|---|---|---|
| FAT32 | None | None | N/A | Full fsck (hours) |
| NTFS | Transactional log ($LogFile) | Metadata + small file data | 64MB default | Seconds to minutes |
| ext4 | jbd2 journal | Metadata (ordered default) | 128MB typical | Seconds |
| XFS | Metadata journal | Metadata only | To 2GB | Seconds |
| ZFS | Intent Log (ZIL) + COW | Full transactional | SLOG device or pool | Seconds (pool import) |
| Btrfs | Log tree + COW | Full (atomic via COW) | Integrated | Seconds (subvolume mount) |
NTFS Journaling Deep Dive:
NTFS uses $LogFile, a special system file containing a circular transaction log:
What's Logged:
- MFT record changes (creating/modifying files)
- Index updates (directory structure changes)
- Attribute modifications (file metadata)
- Small file content (files small enough to fit in MFT)
Log Structure:
- Restart area: Points to current log position
- Buffer page area: Contains redo and undo records
- Log sequence numbers (LSNs) track ordering
Recovery Process:
- Read restart area to find log position
- Analysis pass: Determine transaction status
- Redo pass: Complete committed transactions
- Undo pass: Rollback uncommitted transactions
Unique NTFS Feature: NTFS also logs changes to resident file data (data stored in MFT rather than separate clusters). This provides full consistency for small files without explicit data journaling mode.
ext4 Journaling Deep Dive:
ext4's journal is managed by the jbd2 (journaling block device) subsystem:
Journaling Modes:
# /etc/fstab options
data=writeback # Fastest; metadata only; stale data risk
data=ordered # Default; metadata journaled, data ordered
data=journal # Slowest; full data+metadata journaling
Journal Commits:
- Commits occur every 5 seconds by default (
commit=5) - Or when journal fills to threshold
- Or on explicit sync/fsync
Barriers:
ext4 uses write barriers to ensure journal commits are truly durable before proceeding. Disabling barriers (barrier=0) improves performance but risks data loss if cache isn't battery-backed.
Disabling write barriers (for performance) assumes either: (1) the storage has battery-backed cache, or (2) you're willing to accept data loss on power failure. Consumer SSDs often have volatile write caches; enterprise SSDs often have power-loss protection. Know your hardware before disabling barriers.
XFS Journaling Deep Dive:
XFS uses a metadata-only journal with several optimizations:
Log Location:
- Internal log: Allocated within the file system (default)
- External log: On a dedicated device for performance
Delayed Logging: XFS aggregates metadata changes in memory, committing batches to the log. This reduces log I/O and improves performance for metadata-intensive workloads.
LSN Tracking: Log Sequence Numbers ensure ordering without synchronous writes. Metadata carries its last-written LSN; recovery replays only log entries with higher LSNs.
Recovery: XFS log recovery is extremely fast—typically under 5 seconds regardless of filesystem size, since it only replays the log, not scan the entire filesystem.
ZFS Intent Log (ZIL) Deep Dive:
ZFS takes a fundamentally different approach: Copy-on-Write semantics mean data is never overwritten, so traditional journaling isn't needed for consistency. The ZIL serves a different purpose:
What ZIL Does:
- Journals synchronous writes (fsync, O_SYNC, O_DSYNC)
- Ensures sync semantics are honored despite ZFS's batched writes
- Does NOT journal asynchronous writes (COW handles those)
SLOG (Separate LOG):
- Optional dedicated device for ZIL
- Enterprise SSDs or NVMe for performance
- Without SLOG, ZIL uses main pool (slower for sync writes)
Recovery:
- On pool import, ZIL is replayed
- Committed TXGs need no replay (already consistent via COW)
- Only uncommitted but sync-promised writes need replay from ZIL
Why ZFS Rarely Loses Data: Between COW atomicity and ZIL for sync writes, ZFS's consistency model is arguably the most robust of any common file system.
Copy-on-Write as Alternative to Journaling
ZFS and Btrfs achieve consistency through Copy-on-Write (COW) rather than traditional journaling. Understanding this alternative approach illuminates fundamental differences in modern file system design.
- •Writes changes to journal before updating in-place
- •Journal provides recovery information
- •Data and metadata updated in their original locations
- •Consistent after journal replay
- •Journal is separate overhead
- •Never overwrites existing data
- •Modifications create new blocks
- •Root pointer updated atomically to new tree
- •Old and new states both exist until root switch
- •Consistency is intrinsic, not added
How COW Guarantees Consistency:
Consider modifying a file in a COW file system:
- Read the file's current blocks
- Create new blocks with modified data
- Update inode to point to new blocks (but don't overwrite old inode)
- Create new inode with updated block pointers
- Update parent tree nodes, all the way to root (new copies)
- Atomically update root pointer to new tree
Key insight: Until step 6, the old file system state is completely intact. The atomic pointer update is the "commit."
If crash occurs before step 6: The old root pointer remains valid; old consistent state preserved; new blocks are orphaned (reclaimed by garbage collection).
If crash occurs after step 6: New state is active; old blocks become garbage; consistency is guaranteed.
No journal needed because there's never partial state—either old or new, never mixed.
Btrfs Consistency Model:
Btrfs combines COW with a log tree for additional performance:
Log Tree:
- Handles fsync optimization (avoids full tree commit for every sync)
- Logs pending changes that haven't reached their final location
- Replayed on mount to complete pending operations
Tree Root Updates:
- Superblock contains pointer to tree roots
- Two superblock copies provide atomic update semantics
- Commit alternates between copies
Checksums:
- Every metadata and data block has CRC32C checksum
- Corruption detected on read, before propagation
- Self-healing possible with redundant configurations
COW eliminates journaling overhead but introduces fragmentation: repeatedly modifying files scatters their blocks across the disk rather than maintaining contiguity. This is the tradeoff for atomic updates without write-ahead logging. Periodic defragmentation or workload-aware design can mitigate this.
Performance Implications
Journaling provides essential consistency guarantees, but at a cost. Understanding these performance implications enables informed tradeoffs.
| Aspect | Cost Description | Magnitude | Mitigation |
|---|---|---|---|
| Write amplification | Data written twice (journal + final) | ~2x for data journaling | Use ordered mode; SSD reduces impact |
| Synchronous commits | Must wait for journal durability | 5-10ms per commit (HDD) | Batch commits; external journal device |
| Journal space | Reserved space for journal | 64MB - 2GB | Minimal concern; journal is reusable |
| Sequential bottleneck | Journal is a single sequential stream | Varies | Larger journal; SSD; delayed logging |
| Barrier overhead | Force cache flush before proceeding | 1-5ms per barrier | Enterprise storage with cache; careful barrier=0 |
Optimizing Journal Performance:
Commit Interval:
ext4's default 5-second commit interval balances durability and performance. Increasing it (e.g., commit=30) reduces write frequency at cost of more data at risk during crashes.
External Journal Devices:
| File System | External Journal Support |
|---|---|
| ext4 | Yes: mke2fs -O journal_dev |
| XFS | Yes: mkfs.xfs -l logdev= |
| ZFS | Yes: SLOG (dedicated vdev) |
| NTFS | Limited (enterprise configurations) |
| Btrfs | No (integrated into tree structure) |
Placing journals on fast NVMe devices while data lives on spinning disks provides:
- Fast synchronous write acknowledgment
- Reduced interference with data I/O
- Potentially 10x improvement in sync-heavy workloads
The SSD Journal Advantage:
On SSDs, journaling overhead is dramatically reduced:
- No seek time for journal writes
- Journal commit latency: ~100µs (SSD) vs ~10ms (HDD)
- Write amplification less impactful due to abundant IOPS
This is why journaling performance concerns are primarily HDD-era issues. Modern SSD-based systems rarely need to compromise on journaling mode.
Writeback journaling (metadata only, unordered) is appropriate when: (1) data is application-replicated or cached elsewhere, (2) stale data exposure in recovered files is acceptable, (3) maximum write throughput is critical, and (4) you're running on battery-backed cache that ensures durability anyway.
Recovery Procedures and Time
One of journaling's primary benefits is fast recovery. Let's compare recovery procedures and expectations across file systems.
| File System | Recovery Method | Time (1TB) | Time (100TB) | Data Loss Risk |
|---|---|---|---|---|
| FAT32 | Full fsck scan | 30-60 min | 50+ hours | Possible metadata/data loss |
| ext4 (no journal) | Full e2fsck scan | 20-40 min | 30+ hours | Possible, requires manual repair |
| ext4 (journal) | Journal replay | < 5 seconds | < 30 seconds | Minimal (to last commit) |
| NTFS | Log replay (chkdsk) | 5-60 seconds | 1-10 minutes | Minimal |
| XFS | Log replay | < 5 seconds | < 30 seconds | Minimal |
| ZFS | Pool import + ZIL replay | 5-60 seconds | 1-5 minutes | Minimal (sync writes guaranteed) |
| Btrfs | Log tree replay | < 10 seconds | < 1 minute | Minimal |
Understanding Recovery Processes:
Journal Replay (ext4, XFS, NTFS):
- Mount process detects unclean shutdown (journal has uncommitted entries)
- Read journal from restart point
- Apply committed transactions that weren't checkpointed
- Discard uncommitted transactions
- Clear journal; complete mount
Recovery time is proportional to journal size, not file system size. Even petabyte file systems recover in seconds.
COW Recovery (ZFS, Btrfs):
- Import/mount reads uberblock/superblock
- Find latest consistent root pointer (atomic; cannot be partial)
- Replay ZIL (ZFS) or log tree (Btrfs) for sync writes
- File system is consistent; mount completes
Recovery is almost instantaneous because there's nothing to "repair"—the file system was never inconsistent.
When Full fsck Is Still Needed:
Journaling doesn't protect against everything:
- Media corruption: Bad sectors can corrupt journal or metadata beyond journal protection
- Software bugs: File system bugs might write inconsistent data
- Hardware failures: Failing drives might provide corrupted data
- Journal corruption: If journal itself is corrupted, replay fails
In these cases, full fsck (or equivalent) is required:
e2fsckfor ext4xfs_repairfor XFSzpool scrub+ resilver for ZFS (if redundant)btrfs checkfor Btrfs
If journal replay fails repeatedly, forcing a mount can compound corruption. Always perform appropriate repair tools first. For critical data, image the corrupted volume before attempting repair. In disaster scenarios, professional data recovery may be warranted.
KEEP LEARNING
Keep learning for free.
Read the complete lesson, save your notes and pick up where you left off with a free account. No card needed.