* [PATCH] Btrfs: fix incorrect compression ratio detection
@ 2014-10-07 22:44 Wang Shilong
2014-11-10 4:20 ` Miao Xie
0 siblings, 1 reply; 2+ messages in thread
From: Wang Shilong @ 2014-10-07 22:44 UTC (permalink / raw)
To: linux-btrfs
Steps to reproduce:
# mkfs.btrfs -f /dev/sdb
# mount -t btrfs /dev/sdb /mnt -o compress=lzo
# dd if=/dev/zero of=/mnt/data bs=$((33*4096)) count=1
after previous steps, inode will be detected as bad compression ratio,
and NOCOMPRESS flag will be set for that inode.
Reason is that compress have a max limit pages every time(128K), if a
132k write in, it will be splitted into two write(128k+4k), this bug
is a leftover for commit 68bb462d42a(Btrfs: don't compress for a small write)
Fix this problem by checking every time before compression, if it is a
small write(<=blocksize), we bail out and fall into nocompression directly.
Signed-off-by: Wang Shilong <wangshilong1991@gmail.com>
---
fs/btrfs/inode.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 344a322..b78e90a 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -411,14 +411,6 @@ static noinline int compress_file_range(struct inode *inode,
(start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size))
btrfs_add_inode_defrag(NULL, inode);
- /*
- * skip compression for a small file range(<=blocksize) that
- * isn't an inline extent, since it dosen't save disk space at all.
- */
- if ((end - start + 1) <= blocksize &&
- (start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size))
- goto cleanup_and_bail_uncompressed;
-
actual_end = min_t(u64, isize, end + 1);
again:
will_compress = 0;
@@ -440,6 +432,14 @@ again:
total_compressed = actual_end - start;
+ /*
+ * skip compression for a small file range(<=blocksize) that
+ * isn't an inline extent, since it dosen't save disk space at all.
+ */
+ if (total_compressed <= blocksize &&
+ (start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size))
+ goto cleanup_and_bail_uncompressed;
+
/* we want to make sure that amount of ram required to uncompress
* an extent is reasonable, so we limit the total size in ram
* of a compressed extent to 128k. This is a crucial number
--
1.8.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Btrfs: fix incorrect compression ratio detection
2014-10-07 22:44 [PATCH] Btrfs: fix incorrect compression ratio detection Wang Shilong
@ 2014-11-10 4:20 ` Miao Xie
0 siblings, 0 replies; 2+ messages in thread
From: Miao Xie @ 2014-11-10 4:20 UTC (permalink / raw)
To: Wang Shilong, linux-btrfs
On Tue, 7 Oct 2014 18:44:35 -0400, Wang Shilong wrote:
> Steps to reproduce:
> # mkfs.btrfs -f /dev/sdb
> # mount -t btrfs /dev/sdb /mnt -o compress=lzo
> # dd if=/dev/zero of=/mnt/data bs=$((33*4096)) count=1
>
> after previous steps, inode will be detected as bad compression ratio,
> and NOCOMPRESS flag will be set for that inode.
>
> Reason is that compress have a max limit pages every time(128K), if a
> 132k write in, it will be splitted into two write(128k+4k), this bug
> is a leftover for commit 68bb462d42a(Btrfs: don't compress for a small write)
>
> Fix this problem by checking every time before compression, if it is a
> small write(<=blocksize), we bail out and fall into nocompression directly.
>
> Signed-off-by: Wang Shilong <wangshilong1991@gmail.com>
Looks good.
Reviewed-by: Miao Xie <miaox@cn.fujitsu.com>
> ---
> fs/btrfs/inode.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 344a322..b78e90a 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -411,14 +411,6 @@ static noinline int compress_file_range(struct inode *inode,
> (start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size))
> btrfs_add_inode_defrag(NULL, inode);
>
> - /*
> - * skip compression for a small file range(<=blocksize) that
> - * isn't an inline extent, since it dosen't save disk space at all.
> - */
> - if ((end - start + 1) <= blocksize &&
> - (start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size))
> - goto cleanup_and_bail_uncompressed;
> -
> actual_end = min_t(u64, isize, end + 1);
> again:
> will_compress = 0;
> @@ -440,6 +432,14 @@ again:
>
> total_compressed = actual_end - start;
>
> + /*
> + * skip compression for a small file range(<=blocksize) that
> + * isn't an inline extent, since it dosen't save disk space at all.
> + */
> + if (total_compressed <= blocksize &&
> + (start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size))
> + goto cleanup_and_bail_uncompressed;
> +
> /* we want to make sure that amount of ram required to uncompress
> * an extent is reasonable, so we limit the total size in ram
> * of a compressed extent to 128k. This is a crucial number
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-11-10 4:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-07 22:44 [PATCH] Btrfs: fix incorrect compression ratio detection Wang Shilong
2014-11-10 4:20 ` Miao Xie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).