From btrfs Wiki
Revision as of 14:47, 10 May 2021 by Kdave (Talk | contribs)

Jump to: navigation, search

Since version 5.12 btrfs supports zoned mode. This is a special on-disk format and allocation/write strategy that's friendly to zoned devices. In short, a device is partitioned into fixed-size zones and each zone can be updated by append-only manner, or reset. As btrfs has no fixed data structures, except the super blocks, the zoned mode only requires block placement that follows the device constraints. You can learn about the whole architecture at

Because of the append-only write, several btrfs features are not supported:

  • nodatacow -- overwrite in-place
  • fallocate -- preallocating space for in-place first write
  • mixed-bg -- unordered writes to data and metadata
  • booting -- resetting the first zone after superblock rotation would remove the boot loader data

The above is really incompatible because it expects an in-place write at some point. There are some features that are not part of the first implementation but is planned to be implemented in the future:

  • only 'single' profile works, TBD: synchronize zone write pointers among the block groups
  • fitrim, TBD: do not depend on free space cache

Creating a zoned filesystem needs btrfs-progs 5.12 or newer (not yet released).



Real hardware

The WD Ultrastar series 600 advertises HM-SMR, ie. the host-managed zoned mode. There are two more: DA (device managed, no zoned information exported to the system), HA (host aware, can be used as regular disk but zoned writes improve performance). There are not many devices available at the moment, the information about exact zoned mode is hard to find, check data sheets or community sources gathering information from real devices.

Emulated: null_blk

The driver null_blk provides memory backed device and is suitable for testing. There are some quirks setting up the devices. The module must be loaded with nr_devices=0 or the numbering of device nodes will be offset. The configfs must be mounted at /sys/kernel/config and the administration of the null_blk devices is done in /sys/kernel/config/nullb. The device nodes are named like /dev/nullb0 and are numbered sequentially. NOTE: the device name may be differen than the named direcotry in sysfs!


   modprobe configfs
   modprobe null_blk nr_devices=0

Create a device mydev, assuming no other previously created devices, size is 2048MiB, zone size 256MiB. There are more tunable parameters, this is a minimal example taking defaults:

   cd /sys/kernel/config/nullb/
   mkdir mydev
   cd mydev
   echo 2048 > size
   echo 1 > zoned
   echo 1 > memory_backed
   echo 256 > zone_size
   echo 1 > power

This will create a device /dev/nullb0 and the value of file index will match the ending number of the device node.

Remove the device:

   rmdir /sys/kernel/config/nullb/mydev

Then continue with mkfs.btrfs /dev/nullb0, the zoned mode is auto-detected.

Compatiblity, incompatibility

  • the feature sets an incompat bit and requires new kernel to access the filesystem (for both read and write)
  • superblock needs to be handled in a special way, there are still 3 copies but at different offsets (0, 512GiB, 4TiB) and the 2 consecutive zones are a ring buffer of the superblocks, finding the latest one needs read it from the write pointer or do a full scan of the zones
  • mixing zoned and non zoned devices is possible (zones are emulated) but is recommended only for testing
  • mixing zoned devices with different zone sizes is not possible
  • zone sizes must be power of two, zone sizes of real devices are eg. 256MiB or 1GiB, larger size is expected, maximum zone size supported by btrfs is 8GiB


Personal tools