btrfs: how to calculate btrfs compression space savings?

I’ve enabled compression (mounted with compress=lzo) for my btrfs partition and used it for a while.

I’m curious about how much benefit the compression brought me and am interested in the saved space value (sum of all file sizes) - (actual used space).

Is there any straightforward way to get this value, or would I have to write a script that sums up e.g. df output and compres it to btrfs filesystem dfoutput?

Asked By: muffel

||

Per the btrfs wiki, there’s no built-in support for this, but the compsize tool can measure compression on btrfs.

The df output will be similar to btrfs fi df in that it will report how much disk space is used, not the uncompressed size. The wiki says you can “kind of guess” by comparing df output before and after compressing a file. Another option is using some program that will total up the actual data such as rsync --stats on a dry run, which will report how much data is read.

Answered By: fooot

In Debian/Ubuntu:

apt install btrfs-compsize
compsize /mnt/btrfs-partition

In Fedora:

dnf install compsize
compsize /mnt/btrfs-partition

output is like this:

Processed 123574 files, 1399139 regular extents (1399139 refs), 69614 inline.
Type       Perc     Disk Usage   Uncompressed Referenced  
TOTAL       73%      211G         289G         289G       
none       100%      174G         174G         174G       
lzo         32%       37G         115G         115G

It requires root (sudo) to work at all (otherwise SEARCH_V2: Operation not permitted).

It can be used on any directory (totalling the subtree), not just the whole filesystem from the mountpoint.

On a system with zstd, but some old files still compressed with lzo, there will be rows for each of them. (The Perc column is the disk_size / uncompressed_size for that row, not how much of the total is compressed that way. Smaller is better.)

Answered By: Dmytro Gierman
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.