From: Liu Bo <bo.li.liu@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 2/2] Btrfs: make snapshot-aware defrag as a mount option
Date: Sat, 27 Oct 2012 18:28:41 +0800 [thread overview]
Message-ID: <1351333721-3220-2-git-send-email-bo.li.liu@oracle.com> (raw)
In-Reply-To: <1351333721-3220-1-git-send-email-bo.li.liu@oracle.com>
This feature works on our crucial write endio path, so if we've got
lots of fragments to process, it will be kind of a disaster to the
performance, so I make such a change.
One can benifit from it while mounting with '-o snap_aware_defrag'.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/ctree.h | 1 +
fs/btrfs/inode.c | 16 ++++++++++------
fs/btrfs/ioctl.c | 5 +++--
fs/btrfs/super.c | 12 ++++++++++--
4 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 926c9ff..f9cd9c9 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1756,6 +1756,7 @@ struct btrfs_ioctl_defrag_range_args {
#define BTRFS_MOUNT_CHECK_INTEGRITY (1 << 20)
#define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
#define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR (1 << 22)
+#define BTRFS_MOUNT_SA_DEFRAG (1 << 23)
#define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)
#define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 35e6993..069499e 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2488,13 +2488,17 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
ordered_extent->file_offset + ordered_extent->len - 1,
0, &cached_state);
- ret = test_range_bit(io_tree, ordered_extent->file_offset,
- ordered_extent->file_offset + ordered_extent->len - 1,
- EXTENT_DEFRAG, 1, cached_state);
- if (ret && btrfs_root_last_snapshot(&root->root_item) >=
+ if (btrfs_test_opt(root, SA_DEFRAG)) {
+ ret = test_range_bit(io_tree, ordered_extent->file_offset,
+ ordered_extent->file_offset +
+ ordered_extent->len - 1,
+ EXTENT_DEFRAG, 1, cached_state);
+ if (ret &&
+ btrfs_root_last_snapshot(&root->root_item) >=
BTRFS_I(inode)->generation) {
- /* the inode is shared */
- new = record_old_file_extents(inode, ordered_extent);
+ /* the inode is shared */
+ new = record_old_file_extents(inode, ordered_extent);
+ }
}
if (nolock)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 6116880..1367165 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1058,8 +1058,9 @@ again:
}
- set_extent_defrag(&BTRFS_I(inode)->io_tree, page_start, page_end - 1,
- &cached_state, GFP_NOFS);
+ if (btrfs_test_opt(BTRFS_I(inode)->root, SA_DEFRAG))
+ set_extent_defrag(&BTRFS_I(inode)->io_tree, page_start,
+ page_end - 1, &cached_state, GFP_NOFS);
unlock_extent_cached(&BTRFS_I(inode)->io_tree,
page_start, page_end - 1, &cached_state,
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 915ac14..24eac5f 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -308,8 +308,8 @@ enum {
Opt_compress_type, Opt_compress_force, Opt_compress_force_type,
Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
- Opt_enospc_debug, Opt_subvolrootid, Opt_defrag, Opt_inode_cache,
- Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
+ Opt_enospc_debug, Opt_subvolrootid, Opt_defrag, Opt_sa_defrag,
+ Opt_inode_cache, Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
Opt_check_integrity, Opt_check_integrity_including_extent_data,
Opt_check_integrity_print_mask, Opt_fatal_errors,
Opt_err,
@@ -344,6 +344,7 @@ static match_table_t tokens = {
{Opt_enospc_debug, "enospc_debug"},
{Opt_subvolrootid, "subvolrootid=%d"},
{Opt_defrag, "autodefrag"},
+ {Opt_sa_defrag, "snap_aware_defrag"},
{Opt_inode_cache, "inode_cache"},
{Opt_no_space_cache, "nospace_cache"},
{Opt_recovery, "recovery"},
@@ -564,6 +565,11 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
printk(KERN_INFO "btrfs: enabling auto defrag\n");
btrfs_set_opt(info->mount_opt, AUTO_DEFRAG);
break;
+ case Opt_sa_defrag:
+ printk(KERN_INFO "btrfs: enabling snapshot-aware"
+ " defrag\n");
+ btrfs_set_opt(info->mount_opt, SA_DEFRAG);
+ break;
case Opt_recovery:
printk(KERN_INFO "btrfs: enabling auto recovery\n");
btrfs_set_opt(info->mount_opt, RECOVERY);
@@ -935,6 +941,8 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)
seq_puts(seq, ",enospc_debug");
if (btrfs_test_opt(root, AUTO_DEFRAG))
seq_puts(seq, ",autodefrag");
+ if (btrfs_test_opt(root, SA_DEFRAG))
+ seq_puts(seq, ",snap_aware_defrag");
if (btrfs_test_opt(root, INODE_MAP_CACHE))
seq_puts(seq, ",inode_cache");
if (btrfs_test_opt(root, SKIP_BALANCE))
--
1.7.7.6
next prev parent reply other threads:[~2012-10-27 10:36 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-27 10:28 [PATCH 1/2 v4] Btrfs: snapshot-aware defrag Liu Bo
2012-10-27 10:28 ` Liu Bo [this message]
2012-10-30 23:31 ` [PATCH 2/2] Btrfs: make snapshot-aware defrag as a mount option David Sterba
2012-10-31 0:34 ` Liu Bo
2012-10-31 0:44 ` David Sterba
2012-10-31 13:31 ` Liu Bo
2012-11-01 14:43 ` Chris Mason
2012-11-01 15:49 ` Liu Bo
2012-10-29 20:06 ` [PATCH 1/2 v4] Btrfs: snapshot-aware defrag Mitch Harder
2012-10-30 1:20 ` Liu Bo
2012-10-30 20:59 ` Mitch Harder
2012-10-31 12:13 ` Itaru Kitayama
2012-10-31 12:55 ` Liu Bo
2012-11-01 11:08 ` Itaru Kitayama
2012-11-01 11:21 ` Liu Bo
2012-11-01 14:05 ` Itaru Kitayama
2012-11-01 16:01 ` Liu Bo
[not found] ` <CANW9uyt9qE9384WnQq5ggZ2hb-DbahZe8KY5-WXRFSKTiedekg@mail.gmail.com>
2012-11-26 10:30 ` Liu Bo
2012-12-12 19:37 ` Mitch Harder
2012-12-13 1:28 ` Liu Bo
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=1351333721-3220-2-git-send-email-bo.li.liu@oracle.com \
--to=bo.li.liu@oracle.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).