I enabled compression on a btrfs volume. Now how do I know the compression ratio of files or directories? Or at least the overall stats?

4 Answers 4


there is third party tool that can do this.



ayush@devbox:/code/compsize$ sudo compsize /opt
Processed 54036 files, 42027 regular extents (42028 refs), 27150 inline.
Type       Perc     Disk Usage   Uncompressed Referenced  
Data        82%      5.3G         6.4G         6.4G       
none       100%      4.3G         4.3G         4.3G       
zlib        37%      427M         1.1G         1.1G       
lzo         56%      588M         1.0G         1.0G  

You can't. Not yet. The feature hasn't been implemented,


  • It is implemented now.
    – Pilot6
    May 21, 2022 at 20:22

compsize has been added to Ubuntu repositories.

You can install it by

sudo apt install btrfs-compsize

If you run man compsize, you'll see

       compsize - calculate compression ratio of a set of files on btrfs

       compsize file-or-dir [ file-or-dir ... ]

       compsize  takes  a  list  of files on a btrfs filesystem (recursing directories) and measures used compression
       types and the effective compression ratio.

       As talking about compression ratio for a partial extent doesn't quite make any sense,  every  used  extent  is
       considered in its entirety.  Every extent is also counted exactly once, even if it's reflinked multiple times.

       The program gives a report similar to:
       Processed 90319 files.
       Type       Perc     Disk Usage   Uncompressed Referenced
       TOTAL       79%      1.4G         1.8G         1.9G
       none       100%      1.0G         1.0G         1.0G
       lzo         53%      446M         833M         843M
  • thanks for this info! just pointing out that the correct package name is sudo apt install btrfs-compsize
    – taiyodayo
    Jul 26, 2023 at 10:37
  • 1
    I fixed the typo, thx.
    – Pilot6
    Jul 27, 2023 at 11:20

It can easily be done by using df and du command line tools. For example, if I mount a btrfs filesystem under /media/etamar/filesystem I can use the following command to view the difference between compressed and actual data sizes:

me@host:~$ df -h /media/etamar/filesystem/ ; du -hd0 /media/etamar/filesystem/

Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb6        31G  6.2G   23G  22% /media/etamar/filesystem
9.4G    /media/etamar/filesystem/

In this case, I stored 9.4 Gigabytes of actual data by using 6.2 Gigabytes of compressed storage space on the BTRFS filesystem. Calculating 6.2/9.4 can be done in many ways (including a calculator).

  • This is wrong according to the current Arch Wiki: "General linux userspace tools such as df(1) will inaccurately report free space on a Btrfs partition... The same limitations apply to ... du(1)..." wiki.archlinux.org/title/Btrfs
    – Alp
    Apr 30, 2023 at 14:30
  • Not so @Alp, because I am not referring to the "free space" which is inaccurately reported - I am referring to the Used space, which is under very accurate accounting in btrfs. May 13, 2023 at 13:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .