# BTRFS compression attribute

## The_Great_Sephiroth

I have a quick question for somebody more familiar with the compression functionality of BTRFS than myself. I created a large BTRFS partition and made some subvolumes in preparation for installing Gentoo. I have @boot, @root, @portage, @source, and @home. Currently compression per subvolume is not supported but is in the works. The team recommends working around this by setting the +c flag on the root subvolume directory. The thing is, I want to use zlib for portage and source and lzo for root and home. How can I tell it what to compress with when setting the directory attribute? The boot subvolume will not be compressed.

----------

## Zucca

```
btrfs property set /usr/share/portage compression zlib
```

...might do it. At least +c attribute is inherited by all files inside the directory.

You'll need to use find -command or simialr to then adjust it to files currently inside the directory. And then iirc you need to balance the whole btrfs filesystem to rewrite all the files as compressed ones...

EDIT: This topic got my interest so I went and asked from the #btrfs: *Quote:*   

>  Can I set +c on a directory and then 'btrfs property
> 
>  set /that/same/directory compression zlib' so that
> 
>  all files inside it are compressed with zlib even if
> ...

 

And the answer came: *Quote:*   

>  I think so.
> 
>  Actually, I'd recommend not using the mount options
> 
>  at all,
> ...

 

So... Try it out?

----------

## The_Great_Sephiroth

Thanks, will be trying it shortly.

----------

## The_Great_Sephiroth

It APPEARS to work. Going to try a few more tests and if all goes well I will install to this setup.

----------

## The_Great_Sephiroth

This appears to have worked. Not only that, but I wanted to report GRUB working with this configuration without a hitch. I have three partitions (GPT style). One for GRUB, one for the system which is BTRFS, and a small, 4GB swap partition on the end of the disk. I formated the system partition as BTRFS and made @boot, @root, @portage, @source, and @home subvolumes. Built BTRFS support into my kernel (I do not use an initrd) and it boots fine. Just added "subvol=@whatever" to the mount points in fstab.

----------

## Zucca

I should too set zlib compression to /usr/src, /usr/portage, /var/log ... at least. However if using systemd  then journald can compress the jounal files by itself, if set.

Also something to consider if using SSD is the controller doing its own compression. I don't know if that's the case anymore, but earlier it was. I wonder if the hw compression can be disabled using hdparm or similar...

----------

## dweezil-n0xad

Interesting, I used the new compsize tool to find compression type/ratio on a file or set of files in btrfs to see the difference for portage

/usr/portage is a btrfs subvolume.

results:

```
 # btrfs property set /usr/portage compression lzo

 # btrfs property get /usr/portage compression

compression=lzo

 # emaint sync -r gentoo

>>> Syncing repository 'gentoo' into '/usr/portage'...

/usr/bin/git clone --depth 1 https://github.com/gentoo-mirror/gentoo.git .

<snip>

 # ./compsize /usr/portage

Processed 142043 files.

Type       Perc     Disk Usage   Uncompressed Referenced  

Data        77%      230M         295M         295M       

none       100%      109M         109M         109M       

lzo         64%      120M         185M         185M       

 # rm /usr/portage/* -rf

 # rm /usr/portage/.git* -rf

 # btrfs property set /usr/portage compression zlib

 # btrfs property get /usr/portage compression

compression=zlib

 # emaint sync -r gentoo

>>> Syncing repository 'gentoo' into '/usr/portage'...

/usr/bin/git clone --depth 1 https://github.com/gentoo-mirror/gentoo.git .

<snip>

 # ./compsize /usr/portage

Processed 142043 files.

Type       Perc     Disk Usage   Uncompressed Referenced  

Data        64%      189M         293M         293M       

none       100%       79M          79M          79M       

zlib        51%      110M         214M         214M       

 
```

----------

