Skip to contentSkip to conversation

Btrfs: btrfs_defrag_file() force use target extent size SZ_128KiB for compressed data

RFC PATCH In review Timofey Titovets 1 participant 2 messages Dec 13, 2017 – Dec 14, 2017 Btrfs file system

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Btrfs: btrfs_defrag_file() force use target extent size SZ_128KiB for compressed data

Defrag heuristic use extent lengh as threshold, kernel autodefrag use SZ_256KiB and btrfs-progs use SZ_32MiB as target extent lengh.

Problem:
Compressed extents always have lengh at < 128KiB (BTRFS_MAX_COMPRESSED) So btrfs_defrag_file() always rewrite all extents in defrag range.

Hot fix that by force set target extent size to BTRFS_MAX_COMPRESSED, if file allowed to be compressed.

---
 fs/btrfs/ioctl.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
fs/btrfs/ioctl.c +23 -0
index be5bd81b3669..952364ff4108 100644
@@ -1232,6 +1232,26 @@ static int cluster_pages_for_defrag(struct inode *inode,
 
 }
 
+static inline int inode_use_compression(struct inode *inode)
+{
+	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
+
+	/* force compress */
+	if (btrfs_test_opt(fs_info, FORCE_COMPRESS))
+		return 1;
+	/* defrag ioctl */
+	if (BTRFS_I(inode)->defrag_compress)
+		return 1;
+	/* bad compression ratios */
+	if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS)
+		return 0;
+	if (btrfs_test_opt(fs_info, COMPRESS) ||
+	    BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS ||
+	    BTRFS_I(inode)->prop_compress)
+		return 1;
+	return 0;
+}
+
 int btrfs_defrag_file(struct inode *inode, struct file *file,
 		      struct btrfs_ioctl_defrag_range_args *range,
 		      u64 newer_than, unsigned long max_to_defrag)
@@ -1270,6 +1290,9 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
 			compress_type = range->compress_type;
 	}
 
+	if (inode_use_compression(inode))
+		extent_thresh = BTRFS_MAX_COMPRESSED;
+
 	if (extent_thresh == 0)
 		extent_thresh = SZ_256K;
 
Signature · 1 line
2.15.1
#1 lore raw

Ignore that patch please, i will send another

2017-12-14 2:25 GMT+03:00 Timofey Titovets <[email protected]>:

Quoted 59 lines

Defrag heuristic use extent lengh as threshold, kernel autodefrag use SZ_256KiB and btrfs-progs use SZ_32MiB as target extent lengh.

Problem:
Compressed extents always have lengh at < 128KiB (BTRFS_MAX_COMPRESSED) So btrfs_defrag_file() always rewrite all extents in defrag range.

Hot fix that by force set target extent size to BTRFS_MAX_COMPRESSED, if file allowed to be compressed.

---
 fs/btrfs/ioctl.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
fs/btrfs/ioctl.c +23 -1
index be5bd81b3669..952364ff4108 100644
@@ -1232,6 +1232,26 @@ static int cluster_pages_for_defrag(struct inode *inode,
 
 }
 
+static inline int inode_use_compression(struct inode *inode)
+{
+       struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
+
+       /* force compress */
+       if (btrfs_test_opt(fs_info, FORCE_COMPRESS))
+               return 1;
+       /* defrag ioctl */
+       if (BTRFS_I(inode)->defrag_compress)
+               return 1;
+       /* bad compression ratios */
+       if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS)
+               return 0;
+       if (btrfs_test_opt(fs_info, COMPRESS) ||
+           BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS ||
+           BTRFS_I(inode)->prop_compress)
+               return 1;
+       return 0;
+}
+
 int btrfs_defrag_file(struct inode *inode, struct file *file,
                      struct btrfs_ioctl_defrag_range_args *range,
                      u64 newer_than, unsigned long max_to_defrag)
@@ -1270,6 +1290,9 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
                        compress_type = range->compress_type;
        }
 
+       if (inode_use_compression(inode))
+               extent_thresh = BTRFS_MAX_COMPRESSED;
+
        if (extent_thresh == 0)
                extent_thresh = SZ_256K;
 
--

2.15.1

Signature · 2 lines
Have a nice day,
Timofey.