Btrfs: btrfs_defrag_file() force use target extent size SZ_128KiB for compressed data
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
@@ -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
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_256KiBand btrfs-progs useSZ_32MiBas target extent lengh.Problem:
Compressed extents always have lengh at < 128KiB (BTRFS_MAX_COMPRESSED) Sobtrfs_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.Signed-off-by Timofey Titovets <[email protected]>--- fs/btrfs/ioctl.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)fs/btrfs/ioctl.c +23
-1@@ -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.