Notes and Analysis on ZFS and ECC Memory
Network-Attached Storage (NAS) has become common in personal and home scenarios. In the process of building a NAS system, whether to use ECC memory is a frequently discussed and debated issue. This article attempts to analyze the origin and necessity of ECC memory requirements using TrueNAS's ZFS file system as an example.
1. ECC Memory
The greatest benefit of ECC (Error Correction Code) memory is its ability to detect and correct random bit flips through parity checking, thereby restoring the correct data in memory.
2. ZFS File System
ZFS developers have stated that, theoretically, the ZFS file system itself is no more dependent on ECC functionality than any other file system. Of course, if data in memory is corrupted due to random bit flips (caused by various factors such as cosmic rays), the data recorded from memory to the file system will indeed be incorrect, but other file systems face the exact same risk probabilities. Therefore, under the same conditions without ECC memory, the probability of errors occurring during file read/write operations in ZFS is exactly the same as in other file systems. Furthermore, ZFS retains file checksum information and checksums of that checksum information on the disk, providing superior data security.
3. ZFS-based Applications
As a powerful file system, ZFS provides many advanced features that other file systems do not possess, such as compression and deduplication. It is these applications that exponentially increase the requirement for memory data integrity. For example, if the dictionary used during compression is corrupted, it doesn’t just damage a single file; it compromises the safety of the entire dataset or even the entire pool. This is the fundamental reason why many people emphasize the use of ECC memory in ZFS systems.
4. Precautions for TrueNAS without ECC Memory
If you have very high requirements for data integrity, you may consider not using certain advanced ZFS features, such as deduplication and compression (note that compression is enabled by default), to mitigate the risks brought by non-ECC memory.
5. Regarding Data Scrubbing
Regularly performing a scrub can effectively prevent the degradation of magnetic recordings. By “reading data” -> “writing in place,” it refreshes the residual magnetism used by the hard drive to record data. This seems to introduce a possibility: if a random bit flip occurs when reading data into memory, it will trigger a checksum check. If a specific bit flips again during the checksum process, causing a hash collision, the incorrect data could pass the check and be immediately written back to the disk, resulting in the corruption of the original data. However, many consumer or semi-industrial NAS systems that do not use ECC, such as Synology and QNAP, feature regular scrubbing functions, and there are almost no reports of data corruption caused by scrubbing. This is because the probability of the two aforementioned bit flips occurring simultaneously to cause an error is approximately 1/2^256, which is essentially an impossible event in the human world (the probability of a person being struck by lightning in their lifetime is about 1/2^20). Moreover, such damage would only affect a specific file and would not compromise the entire file system. https://jrs-s.net/2015/02/03/will-zfs-and-non-ecc-ram-kill-your-data/
6. Conclusion
It is likely that the vast majority of people will not use features like deduplication (dedup) because it is extremely memory-intensive, slows down read/write speeds, and is irreversible. As for compression, since the compression ratio is often low, turning it off is generally inconsequential. Therefore, if we avoid using the advanced features mentioned above when using the ZFS file system, we can practically ignore the data integrity risks posed by non-ECC memory.
Naturally, this principle applies not only to TrueNAS but also to all NAS systems including Unraid, Synology, QNAP, and FNOS, whether they utilize ZFS, Btrfs, or the EXT4 file system.