]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
btrfs: use blocksize to check if compression is making things larger
authorQu Wenruo <wqu@suse.com>
Mon, 11 Aug 2025 00:13:42 +0000 (09:43 +0930)
committerDavid Sterba <dsterba@suse.com>
Mon, 22 Sep 2025 08:54:31 +0000 (10:54 +0200)
commit0a6dcd42353b96ab4a74796aed1541591de5890c
tree831e9ee6a0c5532c679dcd50a55280f4c97dcf37
parentd71b419f274c2eea83038c8623ddc45d51af70e9
btrfs: use blocksize to check if compression is making things larger

[BEHAVIOR DIFFERENCE BETWEEN COMPRESSION ALGOS]
Currently LZO compression algorithm will check if we're making the
compressed data larger after compressing more than 2 blocks.

But zlib and zstd do the same checks after compressing more than 8192
bytes.

This is not a big deal, but since we're already supporting larger block
size (e.g. 64K block size if page size is also 64K), this check is not
suitable for all block sizes.

For example, if our page and block size are both 16KiB, and after the
first block compressed using zlib, the resulted compressed data is
slightly  larger than 16KiB, we will immediately abort the compression.

This makes zstd and zlib compression algorithms to behave slightly
different from LZO, which only aborts after compressing two blocks.

[ENHANCEMENT]
To unify the behavior, only abort the compression after compressing at
least two blocks.

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/zlib.c
fs/btrfs/zstd.c