Thread (32 messages) 32 messages, 2 authors, 2021-07-20
STALE1808d
Revisions (2)
  1. v1 current
  2. v2 [diff vs current]

[PATCH 25/27] btrfs: allow subpage to compress a range which only covers one page

From: Qu Wenruo <hidden>
Date: 2021-07-13 06:15:53
Subsystem: btrfs file system, filesystems (vfs and infrastructure), the rest · Maintainers: Chris Mason, David Sterba, Alexander Viro, Christian Brauner, Linus Torvalds

[BUG]
With expertimental subpage compression write enabled, btrfs still refuse
to compress a completely valid range:

 mkfs.btrfs -f -s 4k $dev
 mount $dev -o compress $mnt

 xfs_io -f -c "pwrite 0 64K" $mnt/file
 umount $mnt

The result extent is uncompressed.

[CAUSE]
It turns out we have extra check on whether we should compress the range
in compress_file_range().

The check looks like:

	if (nr_pages > 1 && inode_need_compress(BTRFS_I(inode), start, end)) {

This means, we will only compress range which covers more than one page.

This check no longer makes sense for subpage, as one page can contain
several sectors.

[FIX]
Don't use @nr_pages, but directly compare @total_compressed against
@blocksize to determine whether we need to do compression.

Signed-off-by: Qu Wenruo <redacted>
---
 fs/btrfs/inode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 1432e268c13e..1cab1e99e46e 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -630,7 +630,8 @@ static noinline int compress_file_range(struct async_chunk *async_chunk)
 	 * inode has not been flagged as nocompress.  This flag can
 	 * change at any time if we discover bad compression ratios.
 	 */
-	if (nr_pages > 1 && inode_need_compress(BTRFS_I(inode), start, end)) {
+	if (total_compressed > blocksize &&
+	    inode_need_compress(BTRFS_I(inode), start, end)) {
 		WARN_ON(pages);
 		pages = kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS);
 		if (!pages) {
-- 
2.32.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help