login
Login
/
Register
Search
Search this site:
Forums
News
Blogs
Features
Site
Home
»
Mailing list archives
»
linux-kernel
»
2010
»
August
»
23
Re: [PATCH 5/6] btrfs: add a helper try_merge_free_space()
view
thread
Previous message: [
thread
] [
date
] [
author
]
Next message: [
thread
] [
date
] [
author
]
[view in full thread]
From: Josef Bacik
Subject:
Re: [PATCH 5/6] btrfs: add a helper try_merge_free_space()
Date: Monday, August 23, 2010 - 6:15 am
On Mon, Aug 23, 2010 at 09:23:44AM +0800, Li Zefan wrote:
quoted text
> When adding a new extent, we'll firstly see if we can merge > this extent to the left or/and right extent. Extract this as > a helper try_merge_free_space(). > > As a side effect, we fix a small bug that if the new extent > has non-bitmap left entry but is unmergeble, we'll directly > link the extent without trying to drop it into bitmap. > > This also prepares for the next patch. > > Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> > --- > fs/btrfs/free-space-cache.c | 75 ++++++++++++++++++++++++------------------ > 1 files changed, 43 insertions(+), 32 deletions(-) > > diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c > index 20f3141..faeec8f 100644 > --- a/fs/btrfs/free-space-cache.c > +++ b/fs/btrfs/free-space-cache.c > @@ -610,22 +610,14 @@ out: > return ret; > } > > -int btrfs_add_free_space(struct btrfs_block_group_cache *block_group, > - u64 offset, u64 bytes) > +bool try_merge_free_space(struct btrfs_block_group_cache *block_group, > + struct btrfs_free_space *info) > { > - struct btrfs_free_space *right_info = NULL; > - struct btrfs_free_space *left_info = NULL; > - struct btrfs_free_space *info = NULL; > - int ret = 0; > - > - info = kzalloc(sizeof(struct btrfs_free_space), GFP_NOFS); > - if (!info) > - return -ENOMEM; > - > - info->offset = offset; > - info->bytes = bytes; > - > - spin_lock(&block_group->tree_lock); > + struct btrfs_free_space *left_info; > + struct btrfs_free_space *right_info; > + bool merged = false; > + u64 offset = info->offset; > + u64 bytes = info->bytes; > > /* > * first we want to see if there is free space adjacent to the range we > @@ -639,27 +631,11 @@ int btrfs_add_free_space(struct btrfs_block_group_cache *block_group, > else > left_info = tree_search_offset(block_group, offset - 1, 0, 0); > > - /* > - * If there was no extent directly to the left or right of this new > - * extent then we know we're going to have to allocate a new extent, so > - * before we do that see if we need to drop this into a bitmap > - */ > - if ((!left_info || left_info->bitmap) && > - (!right_info || right_info->bitmap)) { > - ret = insert_into_bitmap(block_group, info); > - > - if (ret < 0) { > - goto out; > - } else if (ret) { > - ret = 0; > - goto out; > - } > - } > - > if (right_info && !right_info->bitmap) { > unlink_free_space(block_group, right_info); > info->bytes += right_info->bytes; > kfree(right_info); > + merged = true; > } > > if (left_info && !left_info->bitmap && > @@ -668,8 +644,43 @@ int btrfs_add_free_space(struct btrfs_block_group_cache *block_group, > info->offset = left_info->offset; > info->bytes += left_info->bytes; > kfree(left_info); > + merged = true; > } > > + return merged; > +} > + > +int btrfs_add_free_space(struct btrfs_block_group_cache *block_group, > + u64 offset, u64 bytes) > +{ > + struct btrfs_free_space *info; > + int ret = 0; > + > + info = kzalloc(sizeof(struct btrfs_free_space), GFP_NOFS); > + if (!info) > + return -ENOMEM; > + > + info->offset = offset; > + info->bytes = bytes; > + > + spin_lock(&block_group->tree_lock); > + > + if (try_merge_free_space(block_group, info)) > + goto link; > + > + /* > + * There was no extent directly to the left or right of this new > + * extent then we know we're going to have to allocate a new extent, so > + * before we do that see if we need to drop this into a bitmap > + */ > + ret = insert_into_bitmap(block_group, info); > + if (ret < 0) { > + goto out; > + } else if (ret) { > + ret = 0; > + goto out; > + } > +link: > ret = link_free_space(block_group, info); > if (ret) > kfree(info); > -- > 1.7.0.1 >
Reviewed-by: Josef Bacik <josef@redhat.com> Thanks, Josef --
unsubscribe notice
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to
majordomo@vger.kernel.org
More majordomo info at
http://vger.kernel.org/majordomo-info.html
Please read the FAQ at
http://www.tux.org/lkml/
Previous message: [
thread
] [
date
] [
author
]
Next message: [
thread
] [
date
] [
author
]
Messages in current thread:
[PATCH 0/6] btrfs: some bug fixes for free space cache
, Li Zefan
, (Sun Aug 22, 6:22 pm)
[PATCH 1/6] btrfs: fix threshold calculation for block gro ...
, Li Zefan
, (Sun Aug 22, 6:22 pm)
[PATCH 2/6] btrfs: add helper function free_bitmap()
, Li Zefan
, (Sun Aug 22, 6:23 pm)
[PATCH 3/6] btrfs: free fully occupied bitmap in cluster
, Li Zefan
, (Sun Aug 22, 6:23 pm)
[PATCH 4/6] btrfs: update stats when allocating from a cluster
, Li Zefan
, (Sun Aug 22, 6:23 pm)
[PATCH 5/6] btrfs: add a helper try_merge_free_space()
, Li Zefan
, (Sun Aug 22, 6:23 pm)
[PATCH 6/6] btrfs: check mergeable free space when removin ...
, Li Zefan
, (Sun Aug 22, 6:24 pm)
Re: [PATCH 1/6] btrfs: fix threshold calculation for block ...
, Josef Bacik
, (Mon Aug 23, 6:02 am)
Re: [PATCH 2/6] btrfs: add helper function free_bitmap()
, Josef Bacik
, (Mon Aug 23, 6:03 am)
Re: [PATCH 3/6] btrfs: free fully occupied bitmap in cluster
, Josef Bacik
, (Mon Aug 23, 6:04 am)
Re: [PATCH 4/6] btrfs: update stats when allocating from a ...
, Josef Bacik
, (Mon Aug 23, 6:09 am)
Re: [PATCH 6/6] btrfs: check mergeable free space when rem ...
, Josef Bacik
, (Mon Aug 23, 6:15 am)
Re: [PATCH 5/6] btrfs: add a helper try_merge_free_space()
, Josef Bacik
, (Mon Aug 23, 6:15 am)
Re: [PATCH 4/6] btrfs: update stats when allocating from a ...
, Li Zefan
, (Mon Aug 23, 5:50 pm)
Re: [PATCH 6/6] btrfs: check mergeable free space when rem ...
, Li Zefan
, (Mon Aug 23, 6:04 pm)
Re: [PATCH 4/6] btrfs: update stats when allocating from a ...
, Josef Bacik
, (Mon Aug 23, 7:50 pm)
Re: [PATCH 6/6] btrfs: check mergeable free space when rem ...
, Josef Bacik
, (Mon Aug 23, 7:58 pm)
Navigation
Create content
Mailing list archives
Recent posts
Popular discussions
linux-kernel
:
Kay Sievers
Re: char/tpm: tpm_infineon no longer loaded for HP 2510p laptop
Eric W. Biederman
[PATCH 8/8] sysfs: user namespaces: fix bug with clone(CLONE_NEWUSER) with fairsched
S K
Re: cpufreq doesn't seem to work in Intel Q9300
Bart Van Assche
Re: Is gcc thread-unsafe?
Aaron Straus
Re: [NFS] blocks of zeros (NULLs) in NFS files in kernels >= 2.6.20
git
:
Junio C Hamano
Re: git-svnimport
Junio C Hamano
Re: [PATCH] git-mv: Keep moved index entries inact
Johannes Schindelin
Re: [PATCH] Fix approxidate("never") to always return 0
A Large Angry SCM
Re: [RFC] origin link for cherry-pick and revert
Juergen Ruehle
Re: [ANNOUNCE] Guilt 0.16
linux-netdev
:
Daniel Lezcano
getsockopt(TCP_DEFER_ACCEPT) value change
David Miller
Re: 2.6.27.18: bnx2/tg3: BUG: "scheduling while atomic" trying to ifenslave a seco...
Ingo Molnar
Re: [regression] nf_iterate(), BUG: unable to handle kernel NULL pointer dereference
Eric W. Biederman
[PATCH 14/20] net: Simplify pppol2tp pernet operations.
Jeff Kirsher
[net-2.6 PATCH 2/5] e1000e: increase swflag acquisition timeout for ICHx/PCH
git-commits-head
:
Linux Kernel Mailing List
ath9k_htc: Allocate URBs properly
Linux Kernel Mailing List
sm501: add power control callback
Linux Kernel Mailing List
MIPS: Cavium: Remove unused watchdog code.
Linux Kernel Mailing List
V4L/DVB (8976): af9015: Add USB ID for AVerMedia A309
Linux Kernel Mailing List
ARM: 5670/1: bcmring: add default configuration for bcmring arch
openbsd-misc
:
daniele.pilenga
snmpd hangs on 4.1 looking up hrSWRunTable
Christophe Rioux
Implementation example of snmp
Nick Holland
Re: booting openbsd on eee without cd-rom
Bryan Irvine
Re: OpenBSD 4.7 Released, May 19 2010
Cabillot Julien
Re: OpenBSD isakmpd and pf vs Cisco PIX or ASA
Colocation donated by:
Syndicate