Your pool has 64 GB of ARC, eight NVMe drives, and it still serves small random reads at 300 IOPS. You add RAM, the number barely moves. That is the classic ZFS mis-tuning signature: the bottleneck is not capacity, it is a handful of dataset properties and one irreversible vdev decision made when the pool was created.
This guide covers the four knobs that produce measurable gains — ARC sizing, recordsize, ashift, and the three cache vdev types — plus the snapshot-retention tooling that keeps the whole thing from degrading over twelve months. Every command below is taken from OpenZFS documentation or the projects’ own repositories.
Quick Verdict (TL;DR)
- Databases, VM images, and anything with small random I/O: set
recordsize=16K(8K for MySQL/PostgreSQL data files) and keep the ARC at 50–75% of RAM. Expect the largest single win here. - Media, backup targets, and large sequential files: set
recordsize=1Mwithcompression=zstd. Sequential throughput jumps, ARC pressure drops. - New pools: always
ashift=12. It is a one-way door — you cannot fix it later without destroying the pool. - Do not buy an L2ARC before you have measured ARC misses. An L2ARC on a pool with a 99% hit rate is a waste of a drive bay. A SLOG is only useful if you have synchronous writes and a device with power-loss protection.
- Snapshot retention:
sanoidfor policy-driven snapshots on a single host,znapzendwhen you also need remote replication with bandwidth shaping.
The Four Knobs That Matter
| Setting | Default | Recommended (general purpose) | What it changes | Reversible? |
|---|---|---|---|---|
zfs_arc_max | 50% of RAM | 50–75% of RAM on dedicated storage hosts | Read cache ceiling | Yes (module reload) |
recordsize | 128K | 16K (DB/VM), 128K (mixed), 1M (media/backup) | Max block size per file | Yes, new writes only |
ashift | 9 (512B) | 12 (4K) | Minimum allocation unit | No |
compression | lz4 | lz4 or zstd | On-the-fly compression | Yes |
atime | on | off (or relatime) | Metadata write amplification | Yes |
xattr | on | sa | Extended attribute storage | Partially |
Decision Matrix: Match the Setting to the Workload
| Your workload | Change this first | Why |
|---|---|---|
| PostgreSQL / MySQL data directory | recordsize=8K or 16K | Matches the database page size, eliminates read-modify-write |
| QEMU/KVM or Proxmox disk images | recordsize=64K + volblocksize=16K on zvols | Image writes are hole-punched and misaligned at 128K |
| Nextcloud / SMB file shares | recordsize=1M, atime=off, xattr=sa | Large files, no benefit from small blocks, fewer metadata ops |
| Backup target (restic, borg, Veeam) | recordsize=1M, compression=zstd, logbias=throughput | Sequential streams, compressible payload |
| Elasticsearch / Loki chunks | recordsize=1M, logbias=throughput | Append-only segments |
| NFS export with sync writes | Add a SLOG with power-loss protection | Every fsync otherwise waits on the slowest data disk |
| Read-heavy web assets | Verify ARC hit rate before adding L2ARC | Persistent L2ARC only pays off when the working set exceeds RAM |
OpenZFS — Sizing the ARC Correctly
OpenZFS (openzfs/zfs, 12,586 stars, last push 2026-11-24) defaults zfs_arc_max to half of physical RAM on Linux. On a hypervisor that also runs containers, that default is usually wrong in the other direction: ARC grows lazily and can starve the page cache, causing unexpected swap pressure under memory pressure.
Set the cap explicitly. The module loads from the initramfs, so the parameter must be present there:
| |
| |
Verify after reboot — a mismatch here means the initramfs was not rebuilt:
| |
Two numbers decide whether more RAM will help: ARC hit rate and demand data misses. If hits are above 98% and misses are flat, adding memory buys nothing. If hit rate is 85% and mfu (most-frequently-used) is being evicted constantly, you are thrashing and either more RAM or better recordsize will help.
A caveat that costs people weekends: on ZFS-on-root systems, zfs_arc_max set at runtime via /sys/module/zfs/parameters/ is silently reset by the next module load. Always use modprobe.d.
recordsize — The Highest-Leverage Dataset Property
recordsize is the maximum block size ZFS uses for a file. It is not a fixed allocation: files smaller than recordsize use smaller blocks. That is exactly why the “128K is fine for everything” advice is wrong for databases — a 16K random overwrite in a 128K record forces ZFS to read the full 128K record, modify it, and write it back with a new checksum. Each 16K write becomes a 128K read plus a 128K write.
| |
Three rules that prevent surprises:
- Existing data keeps its old recordsize. The property only applies to newly written blocks. A
zfs send | zfs recvinto a new dataset, or a full rewrite, is the only way to convert in place. - Do not shrink
recordsizefor a file that is written once and read whole. 1M records for a 4 GB ISO produce fewer metadata operations and less ARC overhead than 128K records. - zvols use
volblocksize, notrecordsize. 16K is the modern default for a reason; 8K is still correct for database volumes with 8K pages. Changing it on an existing zvol requires a full rewrite.
ashift — Get It Right Once
ashift=12 (4 KiB sectors) is correct for every 512e and 4Kn drive manufactured in the last decade, and for essentially all SSDs. ashift=9 lets ZFS write 512-byte allocations that the drive must read-modify-write internally, which is measurable as write amplification and inflated latency.
| |
A pool created with ashift=9 cannot be repaired. The only remedy is to recreate the pool and restore from backup. If you inherited one, check first — this is the single most common “why is my pool slow” finding on second-hand hardware:
| |
autotrim=on is worth enabling on SSD pools that are not already trimmed by the OS, but it competes with foreground I/O — on write-heavy pools, run a scheduled zpool trim during off-hours instead.
SLOG, L2ARC, and special vDevs — Buy the Right One
These three vdev types solve different problems, and buying the wrong one is a recurring waste of money.
| vdev type | Solves | Requires | Typical gain | Risk if it fails |
|---|---|---|---|---|
| SLOG (separate log) | Slow fsync on sync-write workloads (NFS, databases, VM images) | Power-loss-protected NVMe | 5–50× lower sync latency | Pool survives; falls back to main log |
| L2ARC (read cache) | Working set larger than RAM, read-heavy | Fast NVMe, spare RAM for indexes | Higher hit rate, fewer disk reads | Pool survives; only cache lost |
| special vDev | Metadata and small-block latency | Mirrored fast NVMe | Large metadata/directory win | Pool lost without redundancy |
| |
Measure before and after with latency histograms, not with dd:
| |
If your workload is asynchronous writes (most file servers with sync=disabled or standard and no fsync), a SLOG does literally nothing. That is the most common wasted NVMe drive in homelabs.
Retention: sanoid vs znapzend
Snapshots are free until they are not: a dataset with 4,000 snapshots makes zfs list and zfs destroy operations crawl, and zfs send resumes become slow. Policy-driven retention is mandatory.
sanoid (jimsalterjrs/sanoid, 3,915 stars, last push 2026-06-05) is the standard single-host choice on Linux and FreeBSD. Install from distro packages rather than the repo’s install script — the upstream README explicitly warns that the install script is for maintainers.
| |
| |
| |
znapzend (oetiker/znapzend, 675 stars, last push 2026-07-07) is the better fit when snapshots must also be replicated to a second host and you need to shape the transfer bandwidth with mbuffer. Retention is expressed as a plan chain edited per dataset with znapzendzetup edit, and transfers are resumable.
Rule of thumb for both: keep enough hourly snapshots to cover your worst “oops” window (36 hours is a sane default), 30 daily, and 3 monthly. Prune aggressively — snapshot metadata is charged to ARC and to every zfs list.
Verification and Ongoing Care
Do not leave a tuned pool untested. Scrub monthly, watch for checksum errors, and alert on capacity above 80% — ZFS write performance degrades as a pool fills because of the spacemap and allocation search cost.
| |
If you are still deciding on the storage layer itself, our mdadm vs Btrfs vs ZFS comparison covers the architecture trade-offs, and the self-hosted NAS guide covers appliance choices. For replication topology, see ZFS replication tools compared, and pair your tuning with disk health monitoring so a failing drive does not silently degrade a vdev.
Pitfalls That Cost Real Data
ashift=9on modern drives. Unfixable without recreating the pool. Check before you migrate data in, not after.- Shrinking
recordsizeon an existing dataset and expecting a change. Old blocks keep their size forever; only rewrites adopt the new value. - A SLOG without power-loss protection. A consumer NVMe with a volatile write cache can lose acknowledged sync writes on power failure — worse than having no SLOG at all.
- A single-device special vDev. Metadata loss equals pool loss. Always mirror it.
- Dedup enabled “to save space”. The dedup table consumes roughly 300 bytes per unique block in RAM. Run
zdb -S tankfirst; for most workloads the answer is no. - Setting
zfs_arc_maxat runtime only. It reverts on module reload unless it is in/etc/modprobe.d/zfs.confand the initramfs is rebuilt. - Filling the pool past 90%. Allocation becomes fragmented and write latency climbs sharply. Keep 20% free.
FAQ
Does a larger ARC always improve ZFS performance? No. ARC only helps when the working set exceeds what is cached and the hit rate is below roughly 98%. On a host with a 99% hit rate, extra RAM is wasted; on a host where ARC competes with application memory, an oversized ARC causes swapping and makes everything slower.
Can I change recordsize on a dataset that already holds data?
Yes, the property is writable at any time, but it only affects blocks written after the change. Existing records keep their original size until they are rewritten, so plan a full rewrite or a zfs send | zfs recv migration if you need uniform block sizes.
Is ashift=12 always the right choice? For all 512e and 4Kn drives and for SSDs, yes. ashift is fixed at vdev creation and cannot be changed, so the only correction is to recreate the pool. Always set it explicitly instead of relying on autodetection.
Do I need a SLOG for a fast NVMe pool? Only if your workload issues synchronous writes — NFS exports, database commits, VM images with write barriers. With asynchronous writes the SLOG is never touched. It also must have power-loss protection, or you risk losing acknowledged writes.
What is the difference between L2ARC and a special vDev? L2ARC is a read cache for data blocks and is disposable: if it dies, the pool keeps running. A special vDev stores metadata and small blocks and is part of the pool topology — if it is not mirrored and it fails, the pool is lost.
How many snapshots should I keep?
Enough to cover your realistic recovery window, not more. A common policy is 36 hourly, 30 daily, and 3 monthly. Thousands of snapshots slow down zfs list, zfs destroy, and send/receive resume operations.
💰 想测试你的市场判断力?我用 Polymarket 做预测市场交易——这是全球最大的预测市场平台,从大选结果到技术监管时间线,什么都可以押注。和赌博不同,这是真正的信息市场:你懂的信息越多,胜率越高。我靠预测技术相关事件的走向已经赚了不少。用我的邀请链接注册:Polymarket.com