linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 5/5] btrfs: Compresses files using a combination of compression type and compression level.
@ 2022-01-16  8:51 Li Zhang
  2022-01-20  3:38 ` li zhang
  0 siblings, 1 reply; 2+ messages in thread
From: Li Zhang @ 2022-01-16  8:51 UTC (permalink / raw)
  To: linux-btrfs; +Cc: zhanglikernel

1. If the file is being defragmented, combine defrag_compress
and fs_info compression_level (defrag_compress will be
extended in the future).

2. Extract the compression type btrfs_inode using and write to extent,
because decompression does not need to know the compression level.

Signed-off-by: Li Zhang <zhanglikernel@gmail.com>
---
 fs/btrfs/inode.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 3fe485b..fb44899 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -602,7 +602,8 @@ static noinline int compress_file_range(struct async_chunk *async_chunk)
 	unsigned long total_in = 0;
 	int i;
 	int will_compress;
-	int compress_type = fs_info->compress_type;
+	int compress_type = btrfs_compress_combine_type_level(
+        fs_info->compress_type, fs_info -> compress_level);
 	int compressed_extents = 0;
 	int redirty = 0;
 
@@ -683,7 +684,8 @@ static noinline int compress_file_range(struct async_chunk *async_chunk)
 		}
 
 		if (BTRFS_I(inode)->defrag_compress)
-			compress_type = BTRFS_I(inode)->defrag_compress;
+            compress_type = btrfs_compress_combine_type_level(
+                BTRFS_I(inode)->defrag_compress, fs_info->compress_level);
 		else if (BTRFS_I(inode)->prop_compress)
 			compress_type = BTRFS_I(inode)->prop_compress;
 
@@ -706,7 +708,7 @@ static noinline int compress_file_range(struct async_chunk *async_chunk)
 
 		/* Compression level is applied here and only here */
 		ret = btrfs_compress_pages(
-			compress_type | (fs_info->compress_level << 4),
+			compress_type,
 					   inode->i_mapping, start,
 					   pages,
 					   &nr_pages,
@@ -743,7 +745,7 @@ static noinline int compress_file_range(struct async_chunk *async_chunk)
 			/* try making a compressed inline extent */
 			ret = cow_file_range_inline(BTRFS_I(inode), start, end,
 						    total_compressed,
-						    compress_type, pages);
+						    btrfs_compress_type(compress_type), pages);
 		}
 		if (ret <= 0) {
 			unsigned long clear_flags = EXTENT_DELALLOC |
@@ -808,10 +810,12 @@ static noinline int compress_file_range(struct async_chunk *async_chunk)
 			 * The async work queues will take care of doing actual
 			 * allocation on disk for these compressed pages, and
 			 * will submit them to the elevator.
+             * It only need to record compression type, because decompress don't need
+             * to know compression level
 			 */
 			add_async_extent(async_chunk, start, total_in,
 					total_compressed, pages, nr_pages,
-					compress_type);
+					btrfs_compress_type(compress_type));
 
 			if (start + total_in < end) {
 				start += total_in;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-20  3:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-16  8:51 [PATCH 5/5] btrfs: Compresses files using a combination of compression type and compression level Li Zhang
2022-01-20  3:38 ` li zhang

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).