1 jbd2: calculate statistics without holding j_state_lock and j_list_lock
3 The two hottest locks, and thus the biggest scalability bottlenecks,
4 in the jbd2 layer, are the j_list_lock and j_state_lock. This has
5 inspired some people to do some truly unnatural things[1].
7 [1] https://www.usenix.org/system/files/conference/fast14/fast14-paper_kang.pdf
9 We don't need to be holding both j_state_lock and j_list_lock while
10 calculating the journal statistics, so move those calculations to the
11 very end of jbd2_journal_commit_transaction.
13 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
15 diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
16 index 765b31d..af36252 100644
17 --- a/fs/jbd2/commit.c
18 +++ b/fs/jbd2/commit.c
19 @@ -1083,24 +1083,7 @@ restart_loop:
20 atomic_read(&commit_transaction->t_handle_count);
21 trace_jbd2_run_stats(journal->j_fs_dev->bd_dev,
22 commit_transaction->t_tid, &stats.run);
25 - * Calculate overall stats
27 - spin_lock(&journal->j_history_lock);
28 - journal->j_stats.ts_tid++;
29 - if (commit_transaction->t_requested)
30 - journal->j_stats.ts_requested++;
31 - journal->j_stats.run.rs_wait += stats.run.rs_wait;
32 - journal->j_stats.run.rs_request_delay += stats.run.rs_request_delay;
33 - journal->j_stats.run.rs_running += stats.run.rs_running;
34 - journal->j_stats.run.rs_locked += stats.run.rs_locked;
35 - journal->j_stats.run.rs_flushing += stats.run.rs_flushing;
36 - journal->j_stats.run.rs_logging += stats.run.rs_logging;
37 - journal->j_stats.run.rs_handle_count += stats.run.rs_handle_count;
38 - journal->j_stats.run.rs_blocks += stats.run.rs_blocks;
39 - journal->j_stats.run.rs_blocks_logged += stats.run.rs_blocks_logged;
40 - spin_unlock(&journal->j_history_lock);
41 + stats.ts_requested = (commit_transaction->t_requested) ? 1 : 0;
43 commit_transaction->t_state = T_COMMIT_CALLBACK;
44 J_ASSERT(commit_transaction == journal->j_committing_transaction);
45 @@ -1157,4 +1140,21 @@ restart_loop:
46 spin_unlock(&journal->j_list_lock);
47 write_unlock(&journal->j_state_lock);
48 wake_up(&journal->j_wait_done_commit);
51 + * Calculate overall stats
53 + spin_lock(&journal->j_history_lock);
54 + journal->j_stats.ts_tid++;
55 + journal->j_stats.ts_requested += stats.ts_requested;
56 + journal->j_stats.run.rs_wait += stats.run.rs_wait;
57 + journal->j_stats.run.rs_request_delay += stats.run.rs_request_delay;
58 + journal->j_stats.run.rs_running += stats.run.rs_running;
59 + journal->j_stats.run.rs_locked += stats.run.rs_locked;
60 + journal->j_stats.run.rs_flushing += stats.run.rs_flushing;
61 + journal->j_stats.run.rs_logging += stats.run.rs_logging;
62 + journal->j_stats.run.rs_handle_count += stats.run.rs_handle_count;
63 + journal->j_stats.run.rs_blocks += stats.run.rs_blocks;
64 + journal->j_stats.run.rs_blocks_logged += stats.run.rs_blocks_logged;
65 + spin_unlock(&journal->j_history_lock);