28

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?

2 Answers 2

36

First install compsize.  In Debian/Ubuntu:

apt install btrfs-compsize

In Fedora:

dnf install compsize

Then run it on your filesystem.  Add -x if you don't want to cross into other subvolumes or filesystems.  You must add -x if you have non-btrfs filesystems mounted in the directory tree.

compsize /mnt/btrfs-partition

Example output:

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.)

1
  • it is very slow though Commented Dec 22, 2022 at 21:09
5

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.