#19197·zfs

On a pool whose only top-level vdev is a single leaf disk, once that vdev drops below `VDEV_STATE_HEALTHY`, **every single-copy allocation falls back to gang blocks, permanently*

Author: gicanlegalCreated Sep 26, 2026Updated Sep 26, 2026
LabelsType: Defect

System information

Type Version/Name
Distribution Name TrueNAS SCALE (Debian-based)
Distribution Version 24.04.2.5 (Dragonfish)
Kernel Version 6.6.32-production+truenas
Architecture x86_64
OpenZFS Version zfs-2.2.4-1 / zfs-kmod-2.2.4-1

Describe the problem you're observing

On a pool whose only top-level vdev is a single leaf disk, once that vdev drops below VDEV_STATE_HEALTHY, every single-copy allocation falls back to gang blocks, permanently — independent of free space, fragmentation, or the metaslab_force_ganging tunables.

The guard is in metaslab_alloc_dva() (module/zfs/metaslab.c):

c
/*
 * Avoid writing single-copy data to an unhealthy,
 * non-redundant vdev, unless we've already tried all
 * other vdevs.
 */
if (vd->vdev_state < VDEV_STATE_HEALTHY &&
    d == 0 && !try_hard && vd->vdev_children == 0) {
        metaslab_trace_add(zal, mg, NULL, psize, d,
            TRACE_VDEV_ERROR, allocator);

On a multi-vdev pool the comment's escape hatch — "unless we've already tried all other vdevs" — makes this safe. On a single-vdev pool there are no other vdevs to try, so the allocation fails and zio_write_gang_block() is the result, for every allocation, for as long as the vdev stays below HEALTHY.

All four conditions hold trivially for a degraded single-disk pool: state below HEALTHY, copies=1 so d == 0, a leaf vdev with vdev_children == 0, and the first (!try_hard) attempt.

This was not an out-of-space or fragmentation condition. At the time of the writes the pool was at 25% capacity with 31.9 GB free, 22.81 GB of it in chunks

= 128K with a largest free chunk of 128 MB, and all 86 metaslabs reporting 10–17% fragmentation.

Controlled experiment

200 MB of /dev/urandom written to the same pool, minutes apart, with zpool clear as the only change:

vdev DEGRADED        1600 / 1600 L0 blocks ganged   (100%)
after zpool clear    0 / 1600 L0 blocks ganged      (0%)

The same split is visible historically across the whole pool — data written while the vdev was healthy vs. data written after it was marked DEGRADED:

dataset written Aug 2024    0 / 11779   blocks >=64K ganged
dataset written Sep 2026    11779 / 11779

Space amplification on a 70.4 MB file was 6.5 MB (dsize 76.9M vs 70.3M for a byte-identical copy written while healthy; the block checksums match exactly).

Why this is more than a space-efficiency problem

This pool is a TrueNAS boot-pool, which on most installations is a single disk — so the condition above is the normal case, not an edge case.

The ganged initramfs became unreadable to GRUB, which made the system unbootable after every OS update for an extended period. GRUB's ZFS reader handles ganged L0 data blocks correctly (the kernel image had 71 of 72 data blocks ganged and loaded fine) but fails on a ganged L1 indirect block, so only files large enough to need a sizable L1 are affected. The initramfs is one of them:

file                  L2      L1      L0        GRUB
initrd (degraded)     0/1     2/3     563/563   read error at offset 0
vmlinuz (degraded)     -      0/1      71/72    reads
System.map (degraded)  -      0/1      48/48    reads
initrd (healthy)      0/1     0/3       0/563   reads

What made this very hard to diagnose is that ZFS itself was completely correct throughout: scrubs were clean, no data errors, and the files read perfectly through the normal I/O path. The GRUB failure is separate and not reported here, but it is the reason the allocation behaviour has severe consequences on exactly the pool topology where the guard has no exit.

Relation to prior work

#14003 (merged Oct 2022) removed the vd->vdev_stat.vs_write_errors > 0 term from this same condition, after a pool ganged everything because all its disks had accumulated write errors. The remaining vdev_state term reproduces the same outcome for a vdev degraded by checksum errors.

Question for maintainers: should this guard apply when the metaslab class has only one allocatable vdev — i.e. when skipping it cannot lead to a better placement, only to ganging? Falling through to try_hard in that case would preserve the intent (prefer a healthy vdev when one exists) without the permanent gang fallback.

Describe how to reproduce the problem

  1. Create a pool with a single leaf vdev (zpool create tank /dev/<disk>), copies=1, plenty of free space.
  2. Get the vdev into a state below VDEV_STATE_HEALTHY — in my case checksum errors accumulated until ZFS marked it DEGRADED with aux_state: 'err_exceeded'. Injecting checksum errors until the vdev is marked DEGRADED should reproduce it.
  3. Write a large file: dd if=/dev/urandom of=/tank/test.bin bs=1M count=200 ; sync
  4. Inspect the block pointers:
zdb -O tank test.bin            # -> object id
zdb -ddddd tank <obj>

A block is ganged when its DVA asize exceeds psize rounded up to the vdev ashift. A plain asize > psize comparison counts every sub-ashift block as ganged and inflates the result badly.

Definitive confirmation: dump 512 bytes at the block's DVA with zdb -R tank <vdev>:<offset>:200 and look for 0210da7ab10c7a11 (ZEC_MAGIC) at offset 0x1d8 — the embedded checksum that terminates a gang block header.

  1. zpool clear tank, repeat step 3, and compare. In my case ganging went from 100% to 0% with no other change.

Include any warning/errors/backtraces from the system logs

There are none, and that is part of the problem. Nothing is logged when this happens. zpool events is empty of error classes, dmesg shows no I/O errors, scrubs complete with 0 errors and 0B repaired, and zpool status reports errors: No known data errors. The only visible indication is the vdev state itself:

  pool: boot-pool
 state: DEGRADED
  scan: scrub repaired 0B in 00:00:26 with 0 errors
config:
        NAME        STATE     READ WRITE CKSUM
        boot-pool   DEGRADED     0     0     0
          sda3      DEGRADED     0     0     0  too many errors

errors: No known data errors

(The READ/WRITE/CKSUM counters read zero because they reset on import; the degraded: 1 / aux_state: 'err_exceeded' flags persist in the vdev config.)

A user with a degraded single-disk pool gets silent, total gang allocation with no diagnostic pointing at it.