jbd2: Use atomic variables to avoid taking t_handle_lock in jbd2_journal_stop
Theodore Ts'o
maintainerPATCH 1/1 jbd2: Use atomic variables to avoid taking t_handle_lock in jbd2_journal_stop
By using an atomic_t for t_updates and t_outstanding credits, this should allow us to not need to take transaction t_handle_lock in jbd2_journal_stop().
---
It would be interesting to get some quick performance tests with and without this patch on (a) dbench w/ PREEMPT-RT, (b) Keith's 8-way, and
(c) Eric's 48-core machine. I have some other ideas for how to improve things in start_this_handle(), but they're going to be tricker, and I want to do some hard testing using xfstests on a big machine to make sure this is really safe before I keep going. This has passed light testing, but I haven't had a chance to do stress tests on a large SMP machine yet. That'll come later this week, hopefully.
fs/jbd2/checkpoint.c | 2 +- fs/jbd2/commit.c | 13 +++++---- fs/jbd2/transaction.c | 69 +++++++++++++++++++++++++++--------------------- include/linux/jbd2.h | 8 +++--- 4 files changed, 51 insertions(+), 41 deletions(-)
fs/jbd2/checkpoint.c +1 -1
@@ -775,7 +775,7 @@ void __jbd2_journal_drop_transaction(journal_t *journal, transaction_t *transactJ_ASSERT (transaction->t_log_list ==NULL );J_ASSERT (transaction->t_checkpoint_list ==NULL );J_ASSERT (transaction->t_checkpoint_io_list ==NULL ); -J_ASSERT (transaction->t_updates ==0 ); +J_ASSERT (atomic_read (&transaction->t_updates) ==0 );J_ASSERT (journal->j_committing_transaction != transaction);J_ASSERT (journal->j_running_transaction != transaction);
fs/jbd2/commit.c +7 -6
@@ -417,12 +417,12 @@ void jbd2_journal_commit_transaction(journal_t *journal) stats.run.rs_locked);spin_lock (&commit_transaction->t_handle_lock); -while (commit_transaction->t_updates) { +while (atomic_read (&commit_transaction->t_updates)) {DEFINE_WAIT (wait);prepare_to_wait (&journal->j_wait_updates, &wait,TASK_UNINTERRUPTIBLE ); -if (commit_transaction->t_updates) { +if (atomic_read (&commit_transaction->t_updates)) {spin_unlock (&commit_transaction->t_handle_lock);spin_unlock (&journal->j_state_lock);schedule ();
@@ -433,7 +433,7 @@ void jbd2_journal_commit_transaction(journal_t *journal) }spin_unlock (&commit_transaction->t_handle_lock); -J_ASSERT (commit_transaction->t_outstanding_credits <= +J_ASSERT (atomic_read (&commit_transaction->t_outstanding_credits) <= journal->j_max_transaction_buffers);/*
@@ -527,11 +527,12 @@ void jbd2_journal_commit_transaction(journal_t *journal) stats.run.rs_logging = jiffies; stats.run.rs_flushing =jbd2_time_diff (stats.run.rs_flushing, stats.run.rs_logging); - stats.run.rs_blocks = commit_transaction->t_outstanding_credits; + stats.run.rs_blocks = +atomic_read (&commit_transaction->t_outstanding_credits); stats.run.rs_blocks_logged =0 ;J_ASSERT (commit_transaction->t_nr_buffers <= - commit_transaction->t_outstanding_credits); +atomic_read (&commit_transaction->t_outstanding_credits)); err =0 ; descriptor =NULL ;
@@ -616,7 +617,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)* the free space in the log, but this counter is changed * by jbd2_journal_next_log_block() also. */ - commit_transaction->t_outstanding_credits--; +atomic_dec (&commit_transaction->t_outstanding_credits);/* Bump b_count to prevent truncate from stumbling over the shadowed buffer! @@@ This can go if we ever get
fs/jbd2/transaction.c +39 -30
153 lines not on this page · raw message
include/linux/jbd2.h +4 -4
@@ -601,13 +601,13 @@ struct transaction_s* Number of outstanding updates running on this transaction * [t_handle_lock] */ -int t_updates; +atomic_t t_updates;/* * Number of buffers reserved for use by all handles in this transaction * handle but not yet modified. [t_handle_lock] */ -int t_outstanding_credits; +atomic_t t_outstanding_credits;/* * Forward and backward links for the circular list of all transactions
@@ -1258,8 +1258,8 @@ static inline int jbd_space_needed(journal_t *journal) {int nblocks = journal->j_max_transaction_buffers;if (journal->j_committing_transaction) - nblocks += journal->j_committing_transaction-> - t_outstanding_credits; + nblocks +=atomic_read (&journal->j_committing_transaction-> + t_outstanding_credits);return nblocks; }
Signature · 1 line
1.7.0.4
Quoted 10 lines · Theodore Ts'o
By using an
atomic_tfort_updatesandt_outstandingcredits, this should allow us to not need to take transactiont_handle_lockinjbd2_journal_stop().Signed-off-by "Theodore Ts'o" <[email protected]>Cc John Stultz <[email protected]>Cc Keith Maanthey <[email protected]>Cc Eric Whitney <[email protected]>---
Quoted 8 lines
It would be interesting to get some quick performance tests with and without this patch on (a) dbench w/ PREEMPT-RT, (b) Keith's 8-way, and
(c) Eric's 48-core machine. I have some other ideas for how to improve things instart_this_handle(), but they're going to be tricker, and I want to do some hard testing using xfstests on a big machine to make sure this is really safe before I keep going. This has passed light testing, but I haven't had a chance to do stress tests on a large SMP machine yet. That'll come later this week, hopefully.
So sort of quick and dirty numbers. I'd not trust them too far, but gives a basic feel for how things are doing.
So this is dbench #s on an 8-core blade:
1 2 4 8
vfs+j_state lock 401 724 1203 1142
vfs+j_state lock+atomic 408 745 1266 1263
no vfs, no ext4 patches 410 711 1071 434
no vfs, j_state lock 411 714 1113 806
no vfs, j_state lock+atomic 411 723 1149 816
Graphically:
http://sr71.net/~jstultz/dbench-scalability/graphs/2.6.33-rt-ext4-atomic/preempt-rt-ext4-dbench.png
So the vfs-scalability patchset was reverted from -rt due to some difficult stability issues that were seen in testing. Hopefully we'll be able to sort them out when -rt moves forward to 2.6.35 or later and we can use Nick's more cleaned up current queue rather then my poor forward port of his work from last September.
Anyway, I wanted to show how this patch affects dbench numbers on -rt both with and without the vfs-scalability patches and the earlier j_state lock change.
The vfs versions use the 2.6.33-rt23 kernel, and the non vfs use the 2.6.33-rt26 kernel.
Quoted 1 line
From these numbers, it looks like the atomic variables are a minor
improvement for -rt, but the improvement isn't as drastic as the earlier j_state lock change, or the vfs scalability patchset.
Didn't run into any troubles with this patch in my testing, but again, it was a fairly quick set of runs.
thanks
-john
Ted Ts'o
maintainerQuoted 3 lines · john stultz
Quoted 1 line
From these numbers, it looks like the atomic variables are a minor
improvement for -rt, but the improvement isn't as drastic as the earlier
j_statelock change, or the vfs scalability patchset.
Thanks for doing this quick test run! I was expecting to see a more dramatic difference, since the j_state_lock patch removed one of the two global locks in jbd2_journal_stop, and the t_handle_lock patch removed the second of the two global locks. But I guess the j_state_lock contention in start_this_handle() is still the dominating factor.
It's interesting that apparently the latest t_handle_lock patch doesn't seem to make much difference unless the VFS scalability patch is also applied. I'm not sure why that makes a difference, but it's nice to know that with the VFS scalability patch it does seem to help, even if it doesn't help as much as I had hoped.
OK, I guess we'll have to start working on the more aggressive scalability fix ups....
- Ted
Quoted 11 lines · Ted Ts'o
Quoted 3 lines · john stultz
Quoted 1 line
From these numbers, it looks like the atomic variables are a minor
improvement for -rt, but the improvement isn't as drastic as the earlier
j_statelock change, or the vfs scalability patchset.Thanks for doing this quick test run! I was expecting to see a more dramatic difference, since the
j_state_lockpatch removed one of the two global locks injbd2_journal_stop, and thet_handle_lockpatch removed the second of the two global locks. But I guess thej_state_lockcontention instart_this_handle()is still the dominating factor.
Quoted 5 lines
It's interesting that apparently the latest
t_handle_lockpatch doesn't seem to make much difference unless the VFS scalability patch is also applied. I'm not sure why that makes a difference, but it's nice to know that with the VFS scalability patch it does seem to help, even if it doesn't help as much as I had hoped.
Well, its likely that with the -rt kernel and without the vfs-scalability changes, we're just burning way more time on vfs lock contention then we are on anything in the ext4 code. Just a theory, but I can try to verify with perf logs if you'd like.
Quoted 2 lines
OK, I guess we'll have to start working on the more aggressive scalability fix ups....
I'm generated mainline results w/ w/o Nick's current vfs-scalability tree. So far any benefit from the atomic patch seems to be < 1% there, but I'm probably not hitting much contention at only 8 cores:
2.6.35-rc6
Throughput 2345.72 MB/sec 8 procs
Throughput 1424.11 MB/sec 4 procs
Throughput 811.371 MB/sec 2 procs
Throughput 444.129 MB/sec 1 procs
2.6.35-rc6 + atomic
Throughput 2354.66 MB/sec 8 procs
Throughput 1427.64 MB/sec 4 procs
Throughput 794.961 MB/sec 2 procs
Throughput 443.464 MB/sec 1 procs
2.6.35-rc6-vfs
Throughput 2639.04 MB/sec 8 procs
Throughput 1583.28 MB/sec 4 procs
Throughput 858.337 MB/sec 2 procs
Throughput 452.774 MB/sec 1 procs
2.6.35-rc6-vfs + atomic
Throughput 2648.42 MB/sec 8 procs
Throughput 1586.68 MB/sec 4 procs
Throughput 851.545 MB/sec 2 procs
Throughput 453.106 MB/sec 1 procs
thanks
-john
Quoted 18 lines · john stultz
Quoted 11 lines · Ted Ts'o
Quoted 3 lines · john stultz
Quoted 1 line
From these numbers, it looks like the atomic variables are a minor
improvement for -rt, but the improvement isn't as drastic as the earlier
j_statelock change, or the vfs scalability patchset.Thanks for doing this quick test run! I was expecting to see a more dramatic difference, since the
j_state_lockpatch removed one of the two global locks injbd2_journal_stop, and thet_handle_lockpatch removed the second of the two global locks. But I guess thej_state_lockcontention instart_this_handle()is still the dominating factor.Quoted 5 lines
It's interesting that apparently the latest
t_handle_lockpatch doesn't seem to make much difference unless the VFS scalability patch is also applied. I'm not sure why that makes a difference, but it's nice to know that with the VFS scalability patch it does seem to help, even if it doesn't help as much as I had hoped.
Quoted 4 lines
Well, its likely that with the -rt kernel and without the vfs-scalability changes, we're just burning way more time on vfs lock contention then we are on anything in the ext4 code. Just a theory, but I can try to verify with perf logs if you'd like.
I went ahead and generated perf data for the PREEMPT_RT cases that you can find here:
http://sr71.net/~jstultz/dbench-scalability/perflogs/2.6.33-rt-ext4-atomic/
As a reminder the 2.6.33.5-rt23 kernel includes both the vfs-scalability patches and the j_state locking change. The 2.6.33.6-rt26 kernel does not include those changes.
Quoted 1 line
From those logs you can see that the atomic change on top of the vfs
patch (ie: comparing the two 2.6.33.5-rt23 logs) pulls start_this_handle down quite a bit.
With the non-vfs scalability patched kernels, we see that the j_state lock and atomic changes pull start_this_handle out of the top contender handle, but there is still quite a large amount of contention on the dput paths.
So yea, the change does help, but its just not the top cause of contention when aren't using the vfs patches, so we don't see as much benefit at this point.
thanks
-john
Ted Ts'o
maintainerQuoted 8 lines · john stultz
With the non-vfs scalability patched kernels, we see that the
j_statelock and atomic changes pullstart_this_handleout of the top contender handle, but there is still quite a large amount of contention on the dput paths.So yea, the change does help, but its just not the top cause of contention when aren't using the vfs patches, so we don't see as much benefit at this point.
Great, thanks for uploading the lockstats. Since dbench is so metadata heavy, it makes a lot of sense that further jbd2 optimizations probably won't make much difference until the VFS bottlenecks can be solved.
Other benchmarks, such as the FFSB benchmarks used by Steven Pratt and Eric Whitney, would probably show more of a difference.
In any case, I've just sent two more patches which completely remove any exclusive spinlocks from start_this_handle() by converting j_state_lock to a rwlock_t, and dropping the need to take t_handle_lock. This will add more cache line bouncing, so on NUMA workloads this may make things worse, but I guess we'll have to see. Anyone have access to an SGI Altix? I'm assuming the old Sequent NUMA boxes are long gone by now...
- Ted
Quoted 26 lines · Ted Ts'o
Quoted 8 lines · john stultz
With the non-vfs scalability patched kernels, we see that the
j_statelock and atomic changes pullstart_this_handleout of the top contender handle, but there is still quite a large amount of contention on the dput paths.So yea, the change does help, but its just not the top cause of contention when aren't using the vfs patches, so we don't see as much benefit at this point.
Great, thanks for uploading the lockstats. Since dbench is so metadata heavy, it makes a lot of sense that further jbd2 optimizations probably won't make much difference until the VFS bottlenecks can be solved.
Other benchmarks, such as the FFSB benchmarks used by Steven Pratt and Eric Whitney, would probably show more of a difference.
In any case, I've just sent two more patches which completely remove any exclusive spinlocks from
start_this_handle()by convertingj_state_lockto arwlock_t, and dropping the need to taket_handle_lock. This will add more cache line bouncing, so on NUMA workloads this may make things worse, but I guess we'll have to see. Anyone have access to an SGI Altix? I'm assuming the old Sequent NUMA boxes are long gone by now...
Quoted 1 line
- Ted
Ted:
The 48 core system I'm running on is an eight node NUMA box with three hop worst case latency, and it tends to let you know if you're bouncing cache lines too enthusiastically. If someone's got access to a larger system with more hops across the topology, that would naturally be even better.
I'm taking my 2.6.35 ext4 baseline now. It takes me about 36 hours of running time to get in a complete set of runs, so with luck I should have data and lockstats to post in a few days.
Eric
P.S. And yes, I think I'll make a set of non-accidental no-journal runs this time as well...