Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

btrfs: reject single block sized compression early

Currently for an inode that needs compression, even if there is a delalloc
range that is single fs block sized and can not be inlined, we will
still go through the compression path.

Then inside compress_file_range(), we have one extra check to reject
single block sized range, and fall back to regular uncompressed write.

This rejection is in fact a little too late, we have already allocated
memory to async_chunk, delayed the submission, just to fallback to the
same uncompressed write.

Change the behavior to reject such cases earlier at
inode_need_compress(), so for such single block sized range we won't
even bother trying to go through compress path.

And since the inline small block check is inside inode_need_compress()
and compress_file_range() also calls that function, we no longer need a
dedicate check inside compress_file_range().

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>

authored by

Qu Wenruo and committed by
David Sterba
59615e2c d6f6109f

+8 -12
+8 -12
fs/btrfs/inode.c
··· 816 816 return 0; 817 817 } 818 818 819 + /* 820 + * If the delalloc range is only one fs block and can not be inlined, 821 + * do not even bother try compression, as there will be no space saving 822 + * and will always fallback to regular write later. 823 + */ 824 + if (start != 0 && end + 1 - start <= fs_info->sectorsize) 825 + return 0; 819 826 /* Defrag ioctl takes precedence over mount options and properties. */ 820 827 if (inode->defrag_compress == BTRFS_DEFRAG_DONT_COMPRESS) 821 828 return 0; ··· 960 953 if (actual_end <= start) 961 954 goto cleanup_and_bail_uncompressed; 962 955 963 - total_compressed = actual_end - start; 964 - 965 - /* 966 - * Skip compression for a small file range(<=blocksize) that 967 - * isn't an inline extent, since it doesn't save disk space at all. 968 - */ 969 - if (total_compressed <= blocksize && 970 - (start > 0 || end + 1 < inode->disk_i_size)) 971 - goto cleanup_and_bail_uncompressed; 972 - 973 - total_compressed = min_t(unsigned long, total_compressed, 974 - BTRFS_MAX_UNCOMPRESSED); 956 + total_compressed = min_t(unsigned long, actual_end - start, BTRFS_MAX_UNCOMPRESSED); 975 957 total_in = 0; 976 958 ret = 0; 977 959