[Btrfs-devel] [PATCH] delay commit if work is done while we're asleep

Josef Bacik jwhiter at redhat.com
Thu Aug 9 08:34:14 PDT 2007


On Thu, Aug 09, 2007 at 11:20:51AM -0400, Chris Mason wrote:
> On Thu, 9 Aug 2007 11:07:39 -0400
> Josef Bacik <jwhiter at redhat.com> wrote:
> 
> > Hello,
> > 
> > Ok this one works I promise :).  Cleaned a few things up and such,
> > but basically same idea as before, I keep the waitqueue, I use
> > schedule_timeout which keeps us from deadlocking.  This speeds us up
> > a decent amount, without the patch I usually get 70-75 files/sec.
> > With this patch I get between 85-115 files/sec. The reason there is
> > such a wide spread depends mostly on when the transaction cleaner
> > runs while I'm running the test, as this is only single threaded.
> > Feedback is appreciated.  Thank you,
> 
> It looks great to me, thanks for working on this.  One change I'll
> probably make here is to do something like this:
> 
> prepare_to_wait
> if (trans->transaction->num_writers > 1)
>     timeout = MAX_SCHEDULE_TIMEOUT
> else
>     timeout = 1
> drop locks
> schedule_timeout(timeout);
> 
> This way we don't loop in schedule when there are writers around who
> will wake us.  I'll give it a try this afternoon.
 

Sounds good, but one quick comment, I just hit a panic doing a multithreaded
test.  Fortunately its wasn't introduced by my code, just made it easier to hit.
Here is the patch that fixes this problem, tested it out with and without my
patch with no issues.  Do you want me to make the above changes?  Or are you
going to do it?  Thanks much

Josef

diff -r f6da57af2473 transaction.c
--- a/transaction.c	Wed Aug 08 20:17:12 2007 -0400
+++ b/transaction.c	Thu Aug 09 11:34:35 2007 -0400
@@ -446,7 +446,11 @@ int btrfs_commit_transaction(struct btrf
 		mutex_unlock(&root->fs_info->fs_mutex);
 		ret = wait_for_commit(root, cur_trans);
 		BUG_ON(ret);
+
+		mutex_lock(&root->fs_info->trans_mutex);
 		put_transaction(cur_trans);
+		mutex_unlock(&root->fs_info->trans_mutex);
+
 		mutex_lock(&root->fs_info->fs_mutex);
 		return 0;
 	}
@@ -461,10 +465,10 @@ int btrfs_commit_transaction(struct btrf
 			mutex_unlock(&root->fs_info->trans_mutex);
 
 			wait_for_commit(root, prev_trans);
-			put_transaction(prev_trans);
 
 			mutex_lock(&root->fs_info->fs_mutex);
 			mutex_lock(&root->fs_info->trans_mutex);
+			put_transaction(prev_trans);
 		}
 	}
 	while (trans->transaction->num_writers > 1) {



More information about the Btrfs-devel mailing list