From 170607ebd9c891d6765445434460065b2e73ca51 Mon Sep 17 00:00:00 2001 From: Timofey Titovets Date: Tue, 6 Jun 2017 14:41:15 +0300 Subject: [PATCH] Btrfs: compression must free at least one sector size We already skip storing data where compression does not make the result at least one byte less. Let's make the logic better and check that compression frees at least one sector size of bytes, otherwise it's not that useful. Signed-off-by: Timofey Titovets Reviewed-by: David Sterba [ changelog updated ] Signed-off-by: David Sterba --- fs/btrfs/inode.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index b74a6d23a0fe..a21a984d84d9 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -607,12 +607,11 @@ static noinline void compress_file_range(struct inode *inode, /* * one last check to make sure the compression is really a - * win, compare the page count read with the blocks on disk + * win, compare the page count read with the blocks on disk, + * compression must free at least one sector size */ total_in = ALIGN(total_in, PAGE_SIZE); - if (total_compressed >= total_in) { - will_compress = 0; - } else { + if (total_compressed + blocksize <= total_in) { num_bytes = total_in; *num_added += 1; -- GitLab