Add Jan Kara's "avoid unnecessary transaction stalls during writeback"
[ext4-patch-queue.git] / jbd2-fix-lockdep-splat-with-generic-270
blob2ce44e0cacac6f8d26214cee022f2cc7f7c8e4c6
1 jbd2: Fix lockdep splat with generic/270 test
3 From: Jan Kara <jack@suse.cz>
5 I've hit a lockdep splat with generic/270 test complaining that:
7 3216.fsstress.b/3533 is trying to acquire lock:
8  (jbd2_handle){++++..}, at: [<ffffffff813152e0>] jbd2_log_wait_commit+0x0/0x150
10 but task is already holding lock:
11  (jbd2_handle){++++..}, at: [<ffffffff8130bd3b>] start_this_handle+0x35b/0x850
13 The underlying problem is that jbd2_journal_force_commit_nested()
14 (called from ext4_should_retry_alloc()) may get called while a
15 transaction handle is started. In such case it takes care to not wait
16 for commit of the running transaction (which would deadlock) but only
17 for a commit of a transaction that is already committing (which is safe
18 as that doesn't wait for any filesystem locks).
20 In fact there are also other callers of jbd2_log_wait_commit() that take
21 care to pass tid of a transaction that is already committing and for
22 those cases, the lockdep instrumentation is too restrictive and leading
23 to false positive reports. Fix the problem by calling
24 jbd2_might_wait_for_commit() from jbd2_log_wait_commit() only if the
25 transaction isn't already committing.
27 Fixes: 1eaa566d368b214d99cbb973647c1b0b8102a9ae
28 Signed-off-by: Jan Kara <jack@suse.cz>
29 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
30 ---
31  fs/jbd2/journal.c | 15 ++++++++++++++-
32  1 file changed, 14 insertions(+), 1 deletion(-)
34 diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
35 index 5adc2fb62b0f..9410ec462ba6 100644
36 --- a/fs/jbd2/journal.c
37 +++ b/fs/jbd2/journal.c
38 @@ -691,8 +691,21 @@ int jbd2_log_wait_commit(journal_t *journal, tid_t tid)
39  {
40         int err = 0;
42 -       jbd2_might_wait_for_commit(journal);
43         read_lock(&journal->j_state_lock);
44 +#ifdef CONFIG_PROVE_LOCKING
45 +       /*
46 +        * Some callers make sure transaction is already committing and in that
47 +        * case we cannot block on open handles anymore. So don't warn in that
48 +        * case.
49 +        */
50 +       if (tid_gt(tid, journal->j_commit_sequence) &&
51 +           (!journal->j_committing_transaction ||
52 +            journal->j_committing_transaction->t_tid != tid)) {
53 +               read_unlock(&journal->j_state_lock);
54 +               jbd2_might_wait_for_commit(journal);
55 +               read_lock(&journal->j_state_lock);
56 +       }
57 +#endif
58  #ifdef CONFIG_JBD2_DEBUG
59         if (!tid_geq(journal->j_commit_request, tid)) {
60                 printk(KERN_ERR
61 -- 
62 2.12.0