From: Li Zefan <lizf@cn.fujitsu.com>
To: Chris Mason <chris.mason@oracle.com>
Cc: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>,
Josef Bacik <josef@redhat.com>
Subject: [PATCH 06/12] btrfs: Check mergeable free space when removing a cluster
Date: Thu, 27 Jan 2011 16:44:20 +0800 [thread overview]
Message-ID: <4D413064.5070106@cn.fujitsu.com> (raw)
In-Reply-To: <4D412FE6.7050101@cn.fujitsu.com>
After returing extents from a cluster to the block group, some
extents in the block group may be mergeable.
Reviewed-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
fs/btrfs/free-space-cache.c | 26 ++++++++++++++++++++------
1 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index cf67dc3..a5501ed 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -987,11 +987,18 @@ tree_search_offset(struct btrfs_block_group_cache *block_group,
return entry;
}
-static void unlink_free_space(struct btrfs_block_group_cache *block_group,
- struct btrfs_free_space *info)
+static inline void
+__unlink_free_space(struct btrfs_block_group_cache *block_group,
+ struct btrfs_free_space *info)
{
rb_erase(&info->offset_index, &block_group->free_space_offset);
block_group->free_extents--;
+}
+
+static void unlink_free_space(struct btrfs_block_group_cache *block_group,
+ struct btrfs_free_space *info)
+{
+ __unlink_free_space(block_group, info);
block_group->free_space -= info->bytes;
}
@@ -1364,7 +1371,7 @@ out:
}
bool try_merge_free_space(struct btrfs_block_group_cache *block_group,
- struct btrfs_free_space *info)
+ struct btrfs_free_space *info, bool update_stat)
{
struct btrfs_free_space *left_info;
struct btrfs_free_space *right_info;
@@ -1385,7 +1392,10 @@ bool try_merge_free_space(struct btrfs_block_group_cache *block_group,
left_info = tree_search_offset(block_group, offset - 1, 0, 0);
if (right_info && !right_info->bitmap) {
- unlink_free_space(block_group, right_info);
+ if (update_stat)
+ unlink_free_space(block_group, right_info);
+ else
+ __unlink_free_space(block_group, right_info);
info->bytes += right_info->bytes;
kfree(right_info);
merged = true;
@@ -1393,7 +1403,10 @@ bool try_merge_free_space(struct btrfs_block_group_cache *block_group,
if (left_info && !left_info->bitmap &&
left_info->offset + left_info->bytes == offset) {
- unlink_free_space(block_group, left_info);
+ if (update_stat)
+ unlink_free_space(block_group, left_info);
+ else
+ __unlink_free_space(block_group, left_info);
info->offset = left_info->offset;
info->bytes += left_info->bytes;
kfree(left_info);
@@ -1418,7 +1431,7 @@ int btrfs_add_free_space(struct btrfs_block_group_cache *block_group,
spin_lock(&block_group->tree_lock);
- if (try_merge_free_space(block_group, info))
+ if (try_merge_free_space(block_group, info, true))
goto link;
/*
@@ -1636,6 +1649,7 @@ __btrfs_return_cluster_to_free_space(
node = rb_next(&entry->offset_index);
rb_erase(&entry->offset_index, &cluster->root);
BUG_ON(entry->bitmap);
+ try_merge_free_space(block_group, entry, false);
tree_insert_offset(&block_group->free_space_offset,
entry->offset, &entry->offset_index, 0);
}
--
1.6.3
next prev parent reply other threads:[~2011-01-27 8:44 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-27 8:42 [PATCH 00/12] Btrfs: Some bug fixes Li Zefan
2011-01-27 8:42 ` [PATCH 01/12] btrfs: Fix threshold calculation for block groups smaller than 1GB Li Zefan
2011-01-27 8:42 ` [PATCH 02/12] btrfs: Add helper function free_bitmap() Li Zefan
2011-01-27 8:43 ` [PATCH 03/12] btrfs: Free fully occupied bitmap in cluster Li Zefan
2011-01-27 8:43 ` [PATCH 04/12] btrfs: Update stats when allocating from a cluster Li Zefan
2011-01-27 8:44 ` [PATCH 05/12] btrfs: Add a helper try_merge_free_space() Li Zefan
2011-01-27 8:44 ` Li Zefan [this message]
2011-01-27 8:44 ` [PATCH 07/12] Btrfs: Fix memory leak at umount Li Zefan
2011-01-27 8:44 ` [PATCH 08/12] Btrfs: Fix memory leak on finding existing super Li Zefan
2011-01-27 8:45 ` [PATCH 09/12] Btrfs: Free correct pointer after using strsep Li Zefan
2011-01-27 8:45 ` [PATCH 10/12] Btrfs: Don't return acl info when mounting with noacl option Li Zefan
2011-01-27 8:45 ` [PATCH 11/12] Btrfs: Fix memory leak in writepage fixup work Li Zefan
2011-01-27 8:46 ` [PATCH 12/12] Btrfs: Fix file clone when source offset is not 0 Li Zefan
2012-01-26 13:52 ` Jan Schmidt
2012-01-26 16:17 ` David Sterba
2012-01-30 6:33 ` Li Zefan
2012-01-30 10:03 ` Jan Schmidt
2012-02-01 9:44 ` Li Zefan
2012-02-02 4:31 ` Yan, Zheng
2012-02-02 21:00 ` Jan Schmidt
2012-02-02 4:25 ` Yan, Zheng
2012-02-02 5:31 ` Li Zefan
2012-02-02 6:44 ` Yan, Zheng
2011-01-30 23:48 ` [PATCH 00/12] Btrfs: Some bug fixes Chris Mason
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=4D413064.5070106@cn.fujitsu.com \
--to=lizf@cn.fujitsu.com \
--cc=chris.mason@oracle.com \
--cc=josef@redhat.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).