$linuxjunkies
>

write barrier

also: ordered writes, flush barriers

A mechanism that ensures disk writes are physically committed in the correct order, preventing data corruption if the system crashes or loses power during I/O operations.

A write barrier is a storage subsystem feature that enforces strict ordering of write operations to disk. When enabled, the system ensures that a write marked with a barrier is physically completed to non-volatile storage before any subsequent writes are allowed to proceed. This protects against data inconsistency when unexpected shutdowns occur.

Without write barriers, a filesystem might issue multiple write commands to the disk controller, but the controller's internal cache could reorder them for performance reasons. If power is lost before all data reaches the platter, the writes might complete in the wrong order, leaving the filesystem in an inconsistent state.

Modern filesystems like ext4 and XFS use write barriers to protect critical metadata operations. For example, when a file is deleted, the filesystem must first mark the inode as deleted, then update the free-space bitmap—these steps must occur in the correct order, enforced by barriers.

Write barriers have a performance cost since they prevent write reordering optimizations. Some storage devices (like battery-backed RAID controllers with persistent caches) can safely disable barriers, but most single-drive systems benefit from keeping them enabled for data safety.

Related terms