* [RFC PATCH] Btrfs: btrfs_defrag_file() force use target extent size SZ_128KiB for compressed data
@ 2017-12-13 23:25 Timofey Titovets
2017-12-14 13:35 ` Timofey Titovets
0 siblings, 1 reply; 2+ messages in thread
From: Timofey Titovets @ 2017-12-13 23:25 UTC (permalink / raw)
To: linux-btrfs; +Cc: Timofey Titovets
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.
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
---
fs/btrfs/ioctl.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index be5bd81b3669..952364ff4108 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [RFC PATCH] Btrfs: btrfs_defrag_file() force use target extent size SZ_128KiB for compressed data
2017-12-13 23:25 [RFC PATCH] Btrfs: btrfs_defrag_file() force use target extent size SZ_128KiB for compressed data Timofey Titovets
@ 2017-12-14 13:35 ` Timofey Titovets
0 siblings, 0 replies; 2+ messages in thread
From: Timofey Titovets @ 2017-12-14 13:35 UTC (permalink / raw)
To: linux-btrfs; +Cc: Timofey Titovets
Ignore that patch please, i will send another
2017-12-14 2:25 GMT+03:00 Timofey Titovets <nefelim4ag@gmail.com>:
> 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.
>
> Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
> ---
> fs/btrfs/ioctl.c | 23 +++++++++++++++++++++++
> 1 file changed, 23 insertions(+)
>
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index be5bd81b3669..952364ff4108 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -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
--
Have a nice day,
Timofey.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-12-14 13:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-13 23:25 [RFC PATCH] Btrfs: btrfs_defrag_file() force use target extent size SZ_128KiB for compressed data Timofey Titovets
2017-12-14 13:35 ` Timofey Titovets
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.