public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Josef Bacik <josef@redhat.com>
To: Chris Ball <cjb@laptop.org>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [review] Btrfs: Allow shrinking close to used space
Date: Wed, 25 Feb 2009 15:02:29 -0500	[thread overview]
Message-ID: <20090225200229.GB10849@unused.rdu.redhat.com> (raw)
In-Reply-To: <m34oyixrcp.fsf@pullcord.laptop.org>

On Wed, Feb 25, 2009 at 02:13:10PM -0500, Chris Ball wrote:
> Hi,
> 
> This patch (against experimental HEAD) attempts to make shrinking more
> robust, by only updating device size if we've succeeded in creating
> enough free space without any failures in btrfs_relocate_chunk().
> 
> Here's a log with my patch applied.  The two things to note are that a
> near-limit shrink now works, and that a failed shrink (in this case,
> trying to shrink to less than the used space) no longer updates the
> device size erroneously:
> 
>   http://dev.laptop.org/~cjb/btrfs/shrink-log
> 
> Please review carefully -- I'm still new to btrfs.  The short version of
> the patch is:
> 
> * create a success path, as a break out of the while(1) relocating
>   (rather than going to the "done" label).
> * move the device size updating code into that path
> * leave "path->reada = 2;" behind in the entry path, since path is
>   used by the searching operation rather than the later resize.
> 
> Thanks!
> 
> Signed-off-by: Chris Ball <cjb@laptop.org>
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 1316139..e2fa072 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -1815,30 +1815,8 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
>  	if (!path)
>  		return -ENOMEM;
>  
> -	trans = btrfs_start_transaction(root, 1);
> -	if (!trans) {
> -		ret = -ENOMEM;
> -		goto done;
> -	}
> -
>  	path->reada = 2;
>  
> -	lock_chunks(root);
> -
> -	device->total_bytes = new_size;
> -	if (device->writeable)
> -		device->fs_devices->total_rw_bytes -= diff;

So I think you still want to do this part, to keep the allocator from actually
allocating new space in the area we are trying to cull with the shrink, we just
don't want to update the ondisk stuff just yet, so everything else can be moved
to below the loop.

So this
> -	ret = btrfs_update_device(trans, device);
> -	if (ret) {
> -		unlock_chunks(root);
> -		btrfs_end_transaction(trans, root);
> -		goto done;
> -	}
> -	WARN_ON(diff > old_total);
> -	btrfs_set_super_total_bytes(super_copy, old_total - diff);

to here should all be moved below like you have it.  Other than that it looks
good.  Thanks,

Josef

  reply	other threads:[~2009-02-25 20:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-25 19:13 [review] Btrfs: Allow shrinking close to used space Chris Ball
2009-02-25 20:02 ` Josef Bacik [this message]
2009-02-26  2:31   ` Yan Zheng
2009-03-02  2:29     ` Chris Ball

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=20090225200229.GB10849@unused.rdu.redhat.com \
    --to=josef@redhat.com \
    --cc=cjb@laptop.org \
    --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