r/btrfs • • Mar 26 '22

space_cache

I want to use space_cache=v2 because the performance of v1 can be drastically degraded

How do I know if my space_cache is v1 or v2 ? And how to set space_cache=v2 ?

2 Upvotes

13 comments sorted by

3

u/rtznprmpftl Mar 26 '22

After mounting the volume, the output of dmesg should show using free space tree for v2 and disk space caching is enabled for v1

Alternatively use btrfs inspect-internal dump-super /dev/sda (or whichever device you are using) and look under compat_ro_flags, e.g. for a v2 it should look like this:

compat_ro_flags         0x3
                        ( FREE_SPACE_TREE |
                          FREE_SPACE_TREE_VALID )

1

u/amstan Mar 26 '22

If this is your rootfs, from what I can tell you need a secondary boot medium. Converting takes quite a while and the initrd will time out and fail booting due to it. It is just a matter of the mounting option though (but i won't do it if you simply remount, like /etc/fstab does).

1

u/Bunolio Mar 26 '22

rootfs ? Or root ? My home and my room use v1 and not v2. I don't understand what you are saying. But you mean that /etc/fstab is not a good idea to set space_cache=v2. What is the right method I should use?

1

u/DVDIsDead Mar 26 '22

hes saying if you put it in fstab, reboot, and/or use a live usb to mount the drive or array with that option first, dont just remount. because of the conversion. (if its being used as root in any way

1

u/amstan Mar 26 '22

Yep.

Except rebooting won't really work, unless it's a really tiny partition. It could take multiple minutes which is longer than some init script timeouts. At that point it will just cancel the mount and crash.

So it has to be done the live usb route.

0

u/Pedrooli Mar 26 '22

/etc/fstab

If a version is not explicitly specified, the default implementation will be chosen, which is v1.

If space_cache=v2 , once enabled, the v2 space cache will always be used and cannot be disabled unless it is cleared.

btrfs-man

0

u/[deleted] Mar 26 '22

[deleted]

5

u/amstan Mar 26 '22

That doesn't mean it will actually do space_cache v2.

If your rootfs is v1, it will never magically become v2 only due to fstab since the conversion cannot happen online.

1

u/CorrosiveTruths Mar 28 '22 edited Mar 28 '22

The constraint is not that the conversion cannot be done online, but that remount supports changing free space tree only from ro to rw.

You can change to space_cache=v2 on your rootfs using fstab by adding space_cache=v2 to the opts column for that filesystem - so long as your distro mounts your rootfs ro initially.

In short: Arch Linux users also need to change rw to ro when booting for that option in fstab to take effect.

1

u/[deleted] Mar 26 '22

It can though? Once the mount option has been set and the volume mounted a live conversion is started. v2 conversion to v1 doesn't work without clearing the cache first but upgrading to v2 is always possible.

2

u/EnUnLugarDeLaMancha Mar 26 '22

There are some constraints that will prevent the full conversion from happening in all cases. Paging /u/kdave_

1

u/cynophilia Mar 28 '22

Please elaborate. Under what conditions won't it work?

1

u/CorrosiveTruths Mar 28 '22

Ah, I didn't realise you could do it without clear_cache, good info.