Btrfs compression randomly doesn't compress parts of files

A lot of files that should be compressible aren’t getting compressed by btrfs.

Note: I have my disk mounted with compress-force=zstd:6 but it seemed to happen with the default compress=zstd:1 as well.

To reproduce:

  1. yes ladsfjlkdsafjl > test.bin
  2. ctrl-c after a bit
  3. sudo compsize test.bin
  4. dd if=test.bin of=test2.bin bs=1M
  5. sudo compsize test2.bin
  6. Repeat 4 and 5 a few times

Expected result:
All test2.bins are fully compressed

Actual result:
Sometimes, the files have random amounts of non-compressed data
The amount not compressed changes with each duplication of the file

I think this is due to a mismatch between the system page size and the btrfs sector size:

Would it make more sense for the default asahi install image to use a sector size of 16K instead of the 4K size it uses currently, since it’s not like it’ll be used with any 4K page systems?

The Asahi images are built on 4K page ARM64 builders, so that is not possible. It would also make it a weird configuration, since the btrfs tools default to 4K now on all systems (for compatibility), and weird configurations are less likely to be well tested especially going forward. We also don’t want to make running 4K kernels natively completely impossible.

1 Like