From: Timofey Titovets <nefelim4ag@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Timofey Titovets <nefelim4ag@gmail.com>
Subject: [PATCH 2/4] Btrfs: make should_defrag_range() understood compressed extents
Date: Tue, 19 Dec 2017 13:02:45 +0300 [thread overview]
Message-ID: <20171219100247.13880-3-nefelim4ag@gmail.com> (raw)
In-Reply-To: <20171219100247.13880-1-nefelim4ag@gmail.com>
Both, defrag ioctl and autodefrag - call btrfs_defrag_file()
for file defragmentation.
Kernel default target extent size - 256KiB.
Btrfs progs default - 32MiB.
Both bigger then maximum size of compressed extent - 128KiB.
That lead to rewrite all compressed data on disk.
Fix that by check compression extents with different logic.
As addition, make should_defrag_range() understood compressed extent type,
if requested target compression are same as current extent compression type.
Just don't recompress/rewrite extents.
To avoid useless recompression of compressed extents.
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
---
fs/btrfs/ioctl.c | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 45a47d0891fc..b29ea1f0f621 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1008,7 +1008,7 @@ static bool defrag_check_next_extent(struct inode *inode, struct extent_map *em)
static int should_defrag_range(struct inode *inode, u64 start, u32 thresh,
u64 *last_len, u64 *skip, u64 *defrag_end,
- int compress)
+ int compress, int compress_type)
{
struct extent_map *em;
int ret = 1;
@@ -1043,8 +1043,29 @@ static int should_defrag_range(struct inode *inode, u64 start, u32 thresh,
* real extent, don't bother defragging it
*/
if (!compress && (*last_len == 0 || *last_len >= thresh) &&
- (em->len >= thresh || (!next_mergeable && !prev_mergeable)))
+ (em->len >= thresh || (!next_mergeable && !prev_mergeable))) {
ret = 0;
+ goto out;
+ }
+
+
+ /*
+ * Try not recompress compressed extents
+ * thresh >= BTRFS_MAX_UNCOMPRESSED will lead to
+ * recompress all compressed extents
+ */
+ if (em->compress_type != 0 && thresh >= BTRFS_MAX_UNCOMPRESSED) {
+ if (!compress) {
+ if (em->len == BTRFS_MAX_UNCOMPRESSED)
+ ret = 0;
+ } else {
+ if (em->compress_type != compress_type)
+ goto out;
+ if (em->len == BTRFS_MAX_UNCOMPRESSED)
+ ret = 0;
+ }
+ }
+
out:
/*
* last_len ends up being a counter of how many bytes we've defragged.
@@ -1342,7 +1363,8 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
if (!should_defrag_range(inode, (u64)i << PAGE_SHIFT,
extent_thresh, &last_len, &skip,
- &defrag_end, do_compress)){
+ &defrag_end, do_compress,
+ compress_type)){
unsigned long next;
/*
* the should_defrag function tells us how much to skip
--
2.15.1
next prev parent reply other threads:[~2017-12-19 10:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-19 10:02 [PATCH 0/4] Btrfs: just bunch of patches to ioctl.c Timofey Titovets
2017-12-19 10:02 ` [PATCH 1/4] Btrfs: btrfs_dedupe_file_range() ioctl, remove 16MiB restriction Timofey Titovets
2017-12-19 21:23 ` Darrick J. Wong
2018-01-08 9:17 ` Timofey Titovets
2017-12-19 10:02 ` Timofey Titovets [this message]
2018-05-29 14:05 ` [PATCH 2/4] Btrfs: make should_defrag_range() understood compressed extents Timofey Titovets
2017-12-19 10:02 ` [PATCH 3/4] Btrfs: allow btrfs_defrag_file() uncompress files on defragmentation Timofey Titovets
2017-12-19 10:02 ` [PATCH 4/4] Btrfs: reduce size of struct btrfs_inode Timofey Titovets
2018-01-09 10:53 ` [PATCH 0/4] Btrfs: just bunch of patches to ioctl.c Timofey Titovets
2018-02-09 9:00 ` Timofey Titovets
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171219100247.13880-3-nefelim4ag@gmail.com \
--to=nefelim4ag@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).