#24 Default to space_cache=v2
Closed: Fixed 2 years ago by chrismurphy. Opened 3 years ago by ngompa.

For a few years now, Btrfs developers have been recommending using v2 of the free space cache with the filesystem. However, so far the v1 implementation has remained the default.

From the Btrfs wiki about this:

On very large filesystems (many terabytes) and certain workloads, the performance of the v1 space cache may degrade drastically. The v2 implementation, which adds a new B-tree called the free space tree, addresses this issue. Once enabled, the v2 space cache will always be used and cannot be disabled unless it is cleared. Use clear_cache,space_cache=v1 or clear_cache,nospace_cache to do so. If v2 is enabled, kernels without v2 support will only be able to mount the filesystem in read-only mode. The btrfs(8) command currently only has read-only support for v2. A read-write command may be run on a v2 filesystem by clearing the cache, running the command, and then remounting with space_cache=v2.

I'm not sure if we want to do this now or later. I'm a bit concerned about the note indicating that btrfs(8) requires extra steps to work fully on v2 free space cache. I've filed an issue about this to upstream (gh#kdave/btrfs-progs#295), but we should keep it in mind for the future.


@josef, what do you think about this?

I'm concerned there are too many bad defaults. Now we need discards=async, noatime, space_cache=v2, what will be next? If the kernel doesn't have good defaults upstream we're going to wind up in a nightmare where only fresh installs have a good set of options in /etc/fstab and everybody upgrading from old Fedoras will be missing settings that everyone ought to be using....

At least for discard=async, the reason for that mostly comes down to that the kernel lies too much about rotational vs non-rotational.

For noatime and space_cache=v2, I have actually never used each on my systems, so it really hasn't been a problem for me. I suspect the reason that the space_cache is still v1 is because of the warning that btrfs(8) cannot do write operations to a v2 filesystem yet.

To me, I don't really consider each of them particularly deal-breaking, but it would be nice to figure out how to push the btrfs defaults forward.

While v2 itself is rock solid for years now, it is only significantly better compared to v1 with larger file system with heavier writes quickly eating up free space, compared to desktop workloads. It's not a small or big deal to have v1. Or to have users with mixed settings.

The upstream intent is to convert from v1 to v2. And keep in mind with ext4 and XFS, when new file system features are introduced, you have to reformat your file system to get them. Btrfs uses feature flags to avoid that.

v2 is very nearly ready to be the default, there are just a series of weird and misleading mount time behaviors and messages that are best fixed before making v2 the default rather than confusing people.

It's not worth deviating from upstream.

As for discards, no file system defaults to enabling them. Heavy write and delete workloads do currently have the burden put on them to enable discards right now. But the vast majority of Fedora users aren't going to have such workloads that the default weekly fstrim can't manage.

We're having some wonky behavior with space_cache=v2 right now, I'd rather hold off until next release while we work out the edge cases. The free space tree itself is fine, but there's some weirdness around remount and the tools that need to be fleshed out before I want to use it in Fedora.

Sure, that's fine with me.

Metadata Update from @ngompa:
- Issue assigned to josef

3 years ago

Metadata Update from @chrismurphy:
- Issue close_status updated to: Fixed
- Issue status updated to: Closed (was: Open)

2 years ago

@chrismurphy just wonder should space_cache=v2 enabled already by default on fresh Fedora installations which contain 5.15 kernel? Tried now Workstation respin F35-WORK-x86_64-LIVE-20211201.iso and still v1:

/dev/sda2 on / type btrfs (rw,relatime,seclabel,compress=zstd:1,space_cache,subvolid=258,subvol=/root)
/dev/sda2 on /home type btrfs (rw,relatime,seclabel,compress=zstd:1,space_cache,subvolid=256,subvol=/home)

Fedora 35 official media have byrgs-progs ~5.14 which still formats with v1. Respins will have 5.15.1+ and this v2. Rawhide also gets v2.

You can convert a btrfs with v1 to v2 by mounting one time with -o space_cache=v2 which will set a persistent feature flag. You can mount from any installer ISO, or even do it from initramfs. Use rd.break=pre-mount boot param to get to dracut prompt, then mount with the option to /sysroot, then exit or reboot

Login to comment on this ticket.

Metadata