Blog/Btrfs space cache=v2 with mkfs

From Forza's ramblings

2021-01-31: Enable space cache v2 by default with mkfs.btrfs[edit | edit source]

Since btrfs-progs 5.9 it has been possible to enable space_cache=v2, also known as free space tree, by default when creating new filesystems.

You would use the -R free-space-tree option when making the new filesystem. Then there is no longer a need to use the space_cache=v2 mount option.

# mkfs.btrfs -R list-all
Runtime features available:
quota               - quota support (qgroups) (0x1, compat=3.4)
free-space-tree     - free space tree (space_cache=v2) (0x2, compat=4.5, safe=4.9)

For more information about what space cache is you should read the dedicated article.

There is an ongoing discussion to enable space_cache v2 by default. It is tracked in the GitHub tracker https://github.com/kdave/btrfs-progs/issues/295

Converting existing v1 format to v2[edit | edit source]

To change to space_cache v2 you have to unmount the filesystem and mount it with the space_cache=v2 mount option.

# umount /mnt/btrfs 
# btrfs check --clear-space-cache v1 /dev/device
# mount /dev/device /mnt/btrfs -o space_cache=v2

For a root filesystem it is best to do this from a live-cd/usb media, although it is technically possible to do from the kernel command line.

If you need support or help you can always ask in the #btrfs IRC channel!