What is file system journaling?

Why Interviewers Ask This

Mid-level Operating Systems roles require deep understanding of this topic. Interviewers ask this to separate candidates who truly understand the mechanics from those who only know surface-level concepts.

Answer

Journaling is a technique that maintains a log (journal) of pending file system changes before applying them. If the system crashes during a write, the journal can be replayed to complete or undo partial changes — ensuring file system consistency. Problem without journaling: a typical file write involves multiple disk operations (update data blocks, inode, directory entry, bitmap). If power fails between operations, metadata may be inconsistent (e.g., inode says file has data but bitmap says those blocks are free). Recovery requires full file system check (fsck) which can take hours on large disks. How journaling works: (1) Write-Ahead Logging: before applying changes to the file system, write a journal entry describing the intended changes; (2) Mark transaction as committed; (3) Apply actual changes to the file system; (4) Mark transaction as complete (checkpoint); (5) Journal entry can be reclaimed. Recovery: on reboot after crash, scan journal: committed but not checkpointed transactions → replay them; incomplete (not committed) → ignore/discard them. Fast recovery (seconds vs hours with fsck). Journaling modes (ext4): journal — journal data AND metadata (safest, slowest); ordered (default) — journal metadata only, but write data before metadata (good balance); writeback — journal metadata only, data may be written in any order (fastest, less safe — data before crash may be garbage but filesystem consistent). File systems with journaling: ext3, ext4, NTFS (Windows), APFS (Apple), XFS, JFS. Copy-on-Write file systems (ZFS, Btrfs): no journaling needed — always write new data to new location, atomically update pointer. Provides same consistency guarantee differently.

Common Mistake

Candidates often give textbook answers here. Interviewers are more impressed when you relate the concept to a specific problem you solved in a real Operating Systems project.