How to List Compression Ratio on Compression Enabled Btrfs?
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 There Is...
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
there is third party tool that can do this.
usage:
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,
compsize has been added to Ubuntu repositories.
You can install it by
sudo apt install btrf-compsize
If you run man compsize, you'll see
NAME
compsize - calculate compression ratio of a set of files on btrfs
SYNOPSIS
compsize file-or-dir [ file-or-dir ... ]
DESCRIPTION
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
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).