Lxd btfrs defrag needed?

Hi all,

Ininstalled the default btrfs filesystem for my containers. Do we need to defrag them? Some containers are becoming slow to respond

You could do a btrfs scrub and btrfs balance run, but that’s usually more for validating consistency than to improve speed.


Do i do this on the lxd.img file?

from: https://lxd.readthedocs.io/en/latest/

For production environments, you should be using block backed storage instead both for performance and reliability reasons.


What do you mean with this?

@stgraber has answered to your first question that the operations you want to do have nothing to bring performance-wise; you replied by answering you wanted to do them anyway, and gave the additional information that you were using a loop file backed storage. So I pointed to you that using a loop file backed storage is not recommended for performance reasons, hence you would be better off switching storage mode to block based if performance is your primary concern. That’s it.

Is there an easy way to switch? And how could i do this?

If you have enough available disk space and your system uses LVM, that’s reasonably easy. You can use lvreduce to make space available, then lvcreate to create another volume in the freed space. Then you use something like

sudo lxc storage create new_default btrfs source=/dev/ubuntu-vg/lxd

Very important with btrfs: the partition should NOT be initialized before calling lxc storage create. If it is, the best way is to delete it with lvdelete and recreate it again.

Once you have your new shining storage pool, you move your containers to the new storage pool with lxc move -s . Once it’s done, make the new storage default, remove the old storage and finally you delete the image file. lxc storage --help is your friend.

If your disk is not formatted with LVM, you will have to sweat with fdisk. Ugh. Better to add another disk maybe :slight_smile:

Hi gpatel-fr,

Thank you for your reply but i need some help here. My setup is now:

  • 4 x ssd in raid 10
  • formatted as xfs filesystem
  • on top of this i installed lxd with the btrfs pool

What should be the setup. should i create 2 raid storage devices and use one for btrfs pool?

Probably but I can’t give you best advice, I have always avoided XFS file systems since I discovered that there is no way to reduce them.
So the only way I can think of is to do a backup, reformat everything and restore.
Maybe there are XFS tricks to work around this, but I don’t know them.