Skip to contentSkip to conversation

Inline data is compressed unconditinally even when results in increased size

DISCUSSION Hanabishi 2 participants 3 messages Sep 14 Btrfs file system

lore
Share & tools
lore

Hanabishi

author
#0 lore raw

Hello.

I noticed that a btrfs volume with compression enabled (e.g. 'compress=zstd') seems to compress inline data unconditionally, even in situations when compression is ineffective and only leads to increase in size.

It is easily reproducible on small files:

# echo 'a file with test content' > test.txt
# sync
# compsize test.txt
Processed 1 file, 0 regular extents (0 refs), 1 inline.
Type       Perc     Disk Usage   Uncompressed Referenced
TOTAL      172%       43B          25B          25B
zstd       172%       43B          25B          25B

Same file when no compression enabled:

Processed 1 file, 0 regular extents (0 refs), 1 inline.

Type       Perc     Disk Usage   Uncompressed Referenced
TOTAL      100%       25B          25B          25B
none       100%       25B          25B          25B

It's not a big deal on practice, but shouldn't it detect that the file is uncompressible and fall back to no compression? Also, if I remember correctly, it wasn't the case a couple of kernel releases back.

#1 lore raw
Quoted 17 lines · Hanabishi

Hello.

I noticed that a btrfs volume with compression enabled (e.g. 'compress=zstd') seems to compress inline data unconditionally, even in situations when compression is ineffective and only leads to increase in size.

It is easily reproducible on small files:

# echo 'a file with test content' > test.txt
# sync
# compsize test.txt
Processed 1 file, 0 regular extents (0 refs), 1 inline.
Type       Perc     Disk Usage   Uncompressed Referenced
TOTAL      172%       43B          25B          25B
zstd       172%       43B          25B          25B

Same file when no compression enabled:

Quoted 7 lines

Processed 1 file, 0 regular extents (0 refs), 1 inline.

Type       Perc     Disk Usage   Uncompressed Referenced
TOTAL      100%       25B          25B          25B
none       100%       25B          25B          25B

It's not a big deal on practice, but shouldn't it detect that the file is uncompressible and fall back to no compression? Also, if I remember correctly, it wasn't the case a couple of kernel releases back.

It's a recent regression, independent of the compression algorithm used. Fix here:

https://lore.kernel.org/linux-btrfs/721d8fd2c73095d06cbdbfa714a6dfac9c488953.1789407346.git.fdmanana@suse.com/

Thanks.

Quoted 2 lines
author
#2 lore raw
Quoted 1 line

It's a recent regression, independent of the compression algorithm used.

Good that I remember it right, I wasn't sure.
By the way, the actually worst case scenario when it's just 1 byte.

Processed 1 file, 0 regular extents (0 refs), 1 inline.

Type       Perc     Disk Usage   Uncompressed Referenced
TOTAL      1900%      19B           1B           1B
zstd       1900%      19B           1B           1B