All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miao Xie <miaox@cn.fujitsu.com>
To: Josef Bacik <josef@redhat.com>
Cc: Chris Mason <chris.mason@oracle.com>,
	Linux Btrfs <linux-btrfs@vger.kernel.org>
Subject: Re: [RFC][PATCH 3/3] Btrfs: improve truncation of btrfs
Date: Mon, 09 Jan 2012 13:35:49 +0800	[thread overview]
Message-ID: <4F0A7CB5.9020501@cn.fujitsu.com> (raw)
In-Reply-To: <20120106145031.GA2031@localhost.localdomain>

On Fri, 6 Jan 2012 09:50:31 -0500, Josef Bacik wrote:
> On Fri, Jan 06, 2012 at 11:51:16AM +0800, Miao Xie wrote:
>> On thu, 5 Jan 2012 10:15:50 -0500, Josef Bacik wrote:
>>>> +	trans = btrfs_start_transaction(root, 2);
>>>> +	if (IS_ERR(trans))
>>>> +		return PTR_ERR(trans);
>>>>  
>>>>  	/*
>>>>  	 * setattr is responsible for setting the ordered_data_close flag,
>>>> @@ -6621,26 +6585,12 @@ static int btrfs_truncate(struct inode *inode)
>>>>  	 * using truncate to replace the contents of the file will
>>>>  	 * end up with a zero length file after a crash.
>>>>  	 */
>>>> -	if (inode->i_size == 0 && BTRFS_I(inode)->ordered_data_close)
>>>> +	if (newsize == 0 && BTRFS_I(inode)->ordered_data_close)
>>>>  		btrfs_add_ordered_operation(trans, root, inode);
>>
>> Since we have write out all the dirty page, we can drop the following code which is
>> in front of the while loop, and move the first btrfs_start_transaction() into the loop,
>> the logic of btrfs_truncate() will become simpler.
>>
>>>>  	while (1) {
>>>> -		ret = btrfs_block_rsv_refill(root, rsv, min_size);
>>>> -		if (ret) {
>>>> -			/*
>>>> -			 * This can only happen with the original transaction we
>>>> -			 * started above, every other time we shouldn't have a
>>>> -			 * transaction started yet.
>>>> -			 */
>>>> -			if (ret == -EAGAIN)
>>>> -				goto end_trans;
>>>> -			err = ret;
>>>> -			break;
>>>> -		}
>>>> -
>>>
>>> Taking this part out is wrong, we need to have this slack space to account for
>>> any COW that truncate does.  Other than that this looks pretty good.  Thanks,
>>>
>>
>> I think we can take this part out, because we start a new transaction every time we
>> do a truncation, and reserve enough space at that time. See below:
>>
> 
> Ok let me rephrase.  The whole reason I do this is because the reservation stuff
> is tricky, we may not actually use any of this space and so constantly going
> back to reserve it makes us much more likely to fail our truncate() because of
> ENOSPC.  But if we just hold onto a min size and then refill it when we need to
> we lower the risk considerably, so this needs to stay.  Thanks,

I see.
But I think this method is too gingerly, it can not avoid the ENOSPC completely, but it
makes the code more complex. Though dropping this part will make the risk of ENOSPC higher,
it doesn't break the meta-data. so it is enough that reserving space when starting a new
transaction and just return the error number if ENOSPC happens.

Thanks
Miao

      reply	other threads:[~2012-01-09  5:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-05  8:32 [RFC][PATCH 3/3] Btrfs: improve truncation of btrfs Miao Xie
2012-01-05 15:15 ` Josef Bacik
2012-01-06  3:51   ` Miao Xie
2012-01-06 14:50     ` Josef Bacik
2012-01-09  5:35       ` Miao Xie [this message]

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=4F0A7CB5.9020501@cn.fujitsu.com \
    --to=miaox@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.