linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miao Xie <miaox@cn.fujitsu.com>
To: bo.li.liu@oracle.com
Cc: linux-btrfs@vger.kernel.org, alex.btrfs@zadarastorage.com
Subject: Re: [PATCH 10/17] Btrfs: just flush the delalloc inodes in the source tree before snapshot creation
Date: Thu, 16 May 2013 12:00:05 +0800	[thread overview]
Message-ID: <519459C5.7080403@cn.fujitsu.com> (raw)
In-Reply-To: <20130516032034.GE20202@liubo.jp.oracle.com>

On Thu, 16 May 2013 11:20:39 +0800, Liu Bo wrote:
> On Wed, May 15, 2013 at 03:48:24PM +0800, Miao Xie wrote:
>> Before applying this patch, we need flush all the delalloc inodes in
>> the fs when we want to create a snapshot, it wastes time, and make
>> the transaction commit be blocked for a long time. It means some other
>> user operation would also be blocked for a long time.
>>
>> This patch improves this problem, we just flush the delalloc inodes that
>> in the source trees before snapshot creation, so the transaction commit
>> will complete quickly.
>>
>> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
>> ---
>>  fs/btrfs/ioctl.c       |  6 ++++++
>>  fs/btrfs/transaction.c | 10 +---------
>>  2 files changed, 7 insertions(+), 9 deletions(-)
>>
>> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
>> index 0de4a2f..2677dcc 100644
>> --- a/fs/btrfs/ioctl.c
>> +++ b/fs/btrfs/ioctl.c
>> @@ -555,6 +555,12 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
>>  	if (!root->ref_cows)
>>  		return -EINVAL;
>>  
>> +	ret = btrfs_start_delalloc_inodes(root, 0);
>> +	if (ret)
>> +		return ret;
>> +
>> +	btrfs_wait_ordered_extents(root, 0);
>> +
> 
> Does this look too radical?  Does this snapshot creation ioctl block all
> writes on its src root?

I don't think it is radical, and I think flushing delalloc inodes during the transaction commit
is stupid, especially flushing all the inodes including the roots which are not going to be snapshoted.
Because it will block the operations of the users (such as mkdir, rmdir, create and so on) for
a long time if there are lots of dirty pages.

And The snapshot creation now doesn't block the writes of the source root at all, there is no
appreciable difference between this way and the background flusher.

> No, we can only be sure that there is no ordered extents being added until
> setting trans_no_join, and then it's safe to create pending snapshots.

Actually, we can not avoid that the new ordered extents are added before trans_no_join is set.
But for the users, the 1st case below must be handled correctly, but the 2nd one can be ignored
because we can see the write of the 2nd case as the one that happens after the snapshot creation.

1st case:
	Task
	write data into a file
	make a snapshot

2nd case:
	Task0				Task1
	make a snapshot
	  flush delalloc inodes
					write data into a file
	  commit transaction
	    create_pending_snapshot

Thanks
Miao

> 
> thanks,
> liubo
> 
>>  	pending_snapshot = kzalloc(sizeof(*pending_snapshot), GFP_NOFS);
>>  	if (!pending_snapshot)
>>  		return -ENOMEM;
>> diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
>> index 2b17213..bc22be9 100644
>> --- a/fs/btrfs/transaction.c
>> +++ b/fs/btrfs/transaction.c
>> @@ -1491,17 +1491,9 @@ static int btrfs_flush_all_pending_stuffs(struct btrfs_trans_handle *trans,
>>  					  struct btrfs_root *root)
>>  {
>>  	int flush_on_commit = btrfs_test_opt(root, FLUSHONCOMMIT);
>> -	int snap_pending = 0;
>>  	int ret;
>>  
>> -	if (!flush_on_commit) {
>> -		spin_lock(&root->fs_info->trans_lock);
>> -		if (!list_empty(&trans->transaction->pending_snapshots))
>> -			snap_pending = 1;
>> -		spin_unlock(&root->fs_info->trans_lock);
>> -	}
>> -
>> -	if (flush_on_commit || snap_pending) {
>> +	if (flush_on_commit) {
>>  		ret = btrfs_start_all_delalloc_inodes(root->fs_info, 1);
>>  		if (ret)
>>  			return ret;
>> -- 
>> 1.8.1.4
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


  reply	other threads:[~2013-05-16  3:59 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-15  7:48 [PATCH 00/17] improve the block time during the transaction commit Miao Xie
2013-05-15  7:48 ` [PATCH 01/17] Btrfs: fix accessing a freed tree root Miao Xie
2013-05-15  7:48 ` [PATCH 02/17] Btrfs: fix unprotected root node of the subvolume's inode rb-tree Miao Xie
2013-05-15  7:48 ` [PATCH 03/17] Btrfs: pause the space balance when remounting to R/O Miao Xie
2013-05-15  7:48 ` [PATCH 04/17] Btrfs: remove BUG_ON() in btrfs_read_fs_tree_no_radix() Miao Xie
2013-05-15  7:48 ` [PATCH 05/17] Btrfs: cleanup the similar code of the fs root read Miao Xie
2013-05-15  7:48 ` [PATCH 06/17] Btrfs: introduce grab/put functions for the root of the fs/file tree Miao Xie
2013-05-16  3:36   ` Liu Bo
2013-05-16  4:31     ` Miao Xie
2013-05-16  5:15       ` Liu Bo
2013-05-16  5:34         ` Miao Xie
2013-05-16  6:15           ` Liu Bo
2013-05-16  7:22             ` Miao Xie
2013-05-16 11:54               ` Chris Mason
2013-05-16 14:31                 ` Liu Bo
2013-05-16 14:34                   ` Chris Mason
2013-05-16 14:57                     ` Liu Bo
2013-05-17  1:50                       ` Miao Xie
2013-05-16 12:05               ` Liu Bo
2013-05-15  7:48 ` [PATCH 07/17] Btrfs: don't invoke btrfs_invalidate_inodes() in the spin lock context Miao Xie
2013-05-15  7:48 ` [PATCH 08/17] Btrfs: introduce per-subvolume delalloc inode list Miao Xie
2013-05-15  7:48 ` [PATCH 09/17] Btrfs: introduce per-subvolume ordered extent list Miao Xie
2013-05-15  7:48 ` [PATCH 10/17] Btrfs: just flush the delalloc inodes in the source tree before snapshot creation Miao Xie
2013-05-16  3:20   ` Liu Bo
2013-05-16  4:00     ` Miao Xie [this message]
2013-05-15  7:48 ` [PATCH 11/17] Btrfs: cleanup unnecessary assignment when cleaning up all the residual transaction Miao Xie
2013-05-15  7:48 ` [PATCH 12/17] Btrfs: remove the code for the impossible case in cleanup_transaction() Miao Xie
2013-05-15  7:48 ` [PATCH 13/17] Btrfs: don't wait for all the writers circularly during the transaction commit Miao Xie
2013-05-15  7:48 ` [PATCH 14/17] Btrfs: don't flush the delalloc inodes in the while loop if flushoncommit is set Miao Xie
2013-05-15  7:48 ` [PATCH 15/17] Btrfs: remove unnecessary varient ->num_joined in btrfs_transaction structure Miao Xie
2013-05-15  7:48 ` [PATCH 16/17] Btrfs: remove the time check in btrfs_commit_transaction() Miao Xie
2013-05-15  7:48 ` [PATCH 17/17] Btrfs: make the state of the transaction more readable Miao Xie
2013-05-17  3:53   ` [PATCH V2 " Miao Xie

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=519459C5.7080403@cn.fujitsu.com \
    --to=miaox@cn.fujitsu.com \
    --cc=alex.btrfs@zadarastorage.com \
    --cc=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).