deniz.in

Markets

Weather

Loading weather

· via dev.to (home feed)

ZFS gzip-9 compression caused GC pauses; zstd switch exposed Safe RET read hit

A dev.to post traces database GC pauses to gzip-9 compression bursts in ZFS, then finds the zstd-1 read slowdown was AMD's Safe RET mitigation, not ZFS.

ZFS gzip-9 compression caused GC pauses; zstd switch exposed Safe RET read hit

Pauses hidden by averaged dashboards

According to a write-up on dev.to, a production database was regularly stopping all work for long garbage-collection pauses, and the usual dashboards showed nothing unusual because they plotted averages. Sampling once per second revealed the pattern: the pauses lined up with short bursts of ZFS compression CPU that the averages had smoothed away.

The bursts follow from how ZFS works. It does not compress data when the application calls write(); it compresses when it syncs a transaction group, the batch of changes flushed to disk, at least every zfs_txg_timeout seconds (5 by default) or sooner when dirty data accumulates. The team's bursts arrived roughly every 35 seconds, a cadence they observed but did not explain. Each burst was expensive because the pool used gzip-9, gzip's strongest level. Lab measurements later put gzip-9 at 4.7 to 8.4 times the write CPU of zstd-1 on three of the four test CPUs.

A fix, and an unexpected bill

Switching to zstd-1 cut fleet-wide ZFS compression CPU by about 83% when comparing roughly five weeks after the change against before it, and the long pauses mostly disappeared, the post reports. Then reads on some environments got about four times slower.

Compression is not only paid on writes. When a read finds a compressed record in the ARC, ZFS decompresses the whole record unless an uncompressed copy is still in RAM. The dbuf cache that keeps those copies targets 1/32 of the ARC's size, at most 96 MiB in the team's setup, so most ARC-hit reads pay decompression again, with no disk involved.

A controlled benchmark

Production hosts differed in hardware, load, data and configuration, too many variables to prove a cause, so the team built a lab benchmark: identical software and pool on four Google Cloud VM types, each with 4 vCPUs, with the pool on a RAM disk so disk speed could not blur the result. They tested compression off, lz4, gzip at levels 1, 6 and 9, and zstd at 1, 3 and 9, plus zstd-19 in an earlier run. Data sets included the Silesia corpus, the enwik8 Wikipedia text, generated JSON logs, an append-only event log, and incompressible random data as a control. CPU cost was measured in CPU-seconds per GiB using /proc/schedstat, which counts ZFS kernel threads, cross-checked against /proc/stat.

The culprit: Safe RET, not ZFS

The read slowdown tracked a specific machine type: AMD Genoa. The cause turned out to be Safe RET, a Linux kernel security mitigation associated with SRSO, not anything in ZFS itself. In the lab, booting with the mitigation off, done purely to confirm the cause and explicitly not offered as advice, made zstd-1 reads 4.5 times faster on the same machine.

The post's later sections add nuance: there was no single codec winner across workloads and data sets, the same reads cost different amounts depending on codec and record size, and newer AMD Turin hosts are mitigated without Safe RET.

Caveats the authors flag

The benchmark used one VM per type, so a difference includes memory, host, SMT layout and clock, not only the core. Repetitions were few, two or three per cell, though variance was tight where it mattered: at most 1.3% in the headline Genoa zstd-1 cells and up to 19% in the noisiest. Other limits include a single reader thread, one ZFS build and one bundled zstd version (1.4.5, with gzip handled by the kernel's zlib), generated data sets that approximate but do not reproduce real workloads, and a RAM-backed pool with no device I/O.

Why it matters

For database operators, this is a concrete case of ZFS compression being a CPU and latency decision, not just a storage-ratio decision. gzip-9's CPU bursts collided with stop-the-world GC and stretched pauses that averaged dashboards could not see; per-second sampling found them. Decompression cost also lands on reads, including small random reads that must decompress a full 128 KiB record. And the final answer depended on something outside ZFS entirely: a kernel security mitigation tied to the CPU generation. The practical lesson is to benchmark compression settings on the actual hardware and kernel configuration, mitigations included, before rolling them out fleet-wide.

  • #zfs
  • #linux-kernel
  • #databases
  • #performance
  • #storage

Related posts