ZFS handles sync writes differently from normal filesystems-instead of flushing out sync writes to normal storage immediately, ZFS commits them to a special storage area called the ZFS Intent Log, or ZIL. Sync writes are an entirely different animal-when an application requests a sync write, it's telling the filesystem "you need to commit this to non volatile storage now, and until you do so, I can't do anything else." Sync writes must therefore be committed to disk immediately-and if that increases fragmentation or decreases throughput, so be it. For most workloads, the vast majority of write operations are asynchronous-the filesystem is allowed to aggregate them and commit them in batches, reducing fragmentation and tremendously increasing throughput. There are two major categories of write operations-synchronous (sync) and asynchronous (async). Stripe writes are atomic, the vdev is always consistent, and Bob's your uncle. This means that the RAID hole-a condition in which a stripe is only partially written before the system crashes, making the array inconsistent and corrupt after a restart-doesn't affect ZFS. You're always filesystem-consistent, either way.Ĭopy-on-write in ZFS isn't only at the filesystem level, it's also at the disk management level. Unlinking the old block and linking in the new is accomplished in a single operation, so it can't be interrupted-if you dump the power after it happens, you have the new version of the file, and if you dump power before, then you have the old version.
![vdev eviction openzfs vdev eviction openzfs](https://www.redeszone.net/app/uploads-redeszone.net/2021/02/TrueNAS12_general_42-655x331.png)
Instead, the copy-on-write filesystem writes out a new version of the block you modified, then updates the file's metadata to unlink the old block, and link the new block you just wrote. If you ask a copy-on-write filesystem to do the same thing, it says "okay"-but it's lying to you.
![vdev eviction openzfs vdev eviction openzfs](https://i1.wp.com/klarasystems.com/wp-content/uploads/2020/06/AdobeStock_300257078.jpg)
The basic concept is simple-if you ask a traditional filesystem to modify a file in-place, it does precisely what you asked it to. CoW-Copy on Write-is a fundamental underpinning beneath most of what makes ZFS awesome.