16
# btrfs filesystem defragment -r -v -czstd:15 /
ERROR: unknown compression type zstd:15
# btrfs filesystem defragment -r -v -czstd_15 /
ERROR: unknown compression type zstd_15
# btrfs filesystem defragment -r -v -czstd15 /
ERROR: unknown compression type zstd15

The btrfs manual page doesn't give the clue on how to select a compression level:

-c[algo]

compress file contents while defragmenting. Optional argument selects the compression algorithm, zlib (default), lzo or zstd. Currently it’s not possible to select no compression. See also section EXAMPLES.

How to select a non-default zstd compression level to re-compress existing btrfs filesystems?



Note: btrfs filesystem defragment on snapshots might result in much larger disk space consumption:

Warning: Defragmenting with Linux kernel versions < 3.9 or ≥ 3.14-rc2 as well as with Linux stable kernel versions ≥ 3.10.31, ≥ 3.12.12 or ≥ 3.13.4 will break up the ref-links of COW data (for example files copied with cp --reflink, snapshots or de-duplicated data). This may cause considerable increase of space usage depending on the broken up ref-links.

Pro Backup
  • 4,686
  • 12
  • 50
  • 82

3 Answers3

13

Kernel 5.1 added ZSTD level support. I tested it with rc1 today using a mount option compress=zstd:12 in /etc/fstab. The default level is 3. To be clear: The change affects only files that are written after this mount command. Some benchmark results: https://lkml.org/lkml/2019/1/28/1930

Sven
  • 275
  • 2
  • 5
  • Trying to set any level fails: `open_ctree failed` – Ken Sharp Jun 07 '20 at 18:49
  • Which kernel version and which Linux distribution? – Sven Jun 19 '20 at 06:00
  • When was the btrfs filesystem created (maybe with a too old version)? – Sven Jun 19 '20 at 06:06
  • I can't remember exactly but I'm running Ubuntu 18.04 and the installation is only about a year old. Alexander's answer below works for me. I'll try again when I update the system. – Ken Sharp Jun 19 '20 at 15:49
  • Being able to mount with a level specification does not mean that defrag accepts it. Tested with openSUSE Leap 15.3 (5.3.18 kernel with backports) and btrfs-progs v4.19.1 using `zlib:6`. – Joachim Wagner Oct 08 '22 at 11:49
5

Not yet (December 28th, 2017) possible:

Q: Can I set the compression level?

A: …, ZSTD level support is planned.

source: https://btrfs.wiki.kernel.org/index.php/Compression

Pro Backup
  • 4,686
  • 12
  • 50
  • 82
4

Try:

$> sudo mount -o remount,compress=zlib:9,compress=zstd /

After that command 'findmnt' displays 'compress=zstd:9' mount option :)

  • 3
    I am wondering, does this also better zstd compress files then default zstd? And how was that verified? Or is this only a display glitch? – Pro Backup Jan 16 '19 at 13:36