linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Ted Tso <tytso@mit.edu>
Cc: linux-ext4@vger.kernel.org, Eryu Guan <eguan@redhat.com>,
	Jan Kara <jack@suse.cz>
Subject: [PATCH 3/4] jbd2: Move lockdep tracking to journal_s
Date: Thu, 16 Jun 2016 12:42:15 +0200	[thread overview]
Message-ID: <1466073736-30447-4-git-send-email-jack@suse.cz> (raw)
In-Reply-To: <1466073736-30447-1-git-send-email-jack@suse.cz>

Currently lockdep map is tracked in each journal handle. To be able to
expand lockdep support to cover also other cases where we depend on
transaction commit and where handle is not available, move lockdep map
into struct journal_s. Since this makes the lockdep map shared for all
handles, we have to use rwsem_acquire_read() for acquisitions now.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/jbd2/journal.c     |  4 ++++
 fs/jbd2/transaction.c | 11 +++--------
 include/linux/jbd2.h  | 16 ++++++++++++----
 3 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index b31852f76f46..208e4058040b 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -1091,6 +1091,7 @@ static void jbd2_stats_proc_exit(journal_t *journal)
 
 static journal_t * journal_init_common (void)
 {
+	static struct lock_class_key jbd2_trans_commit_key;
 	journal_t *journal;
 	int err;
 
@@ -1126,6 +1127,9 @@ static journal_t * journal_init_common (void)
 
 	spin_lock_init(&journal->j_history_lock);
 
+	lockdep_init_map(&journal->j_trans_commit_map, "jbd2_handle",
+			 &jbd2_trans_commit_key, 0);
+
 	return journal;
 }
 
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index 41249538c047..c0065040c5be 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -382,13 +382,11 @@ repeat:
 	read_unlock(&journal->j_state_lock);
 	current->journal_info = handle;
 
-	lock_map_acquire(&handle->h_lockdep_map);
+	rwsem_acquire_read(&journal->j_trans_commit_map, 0, 0, _THIS_IP_);
 	jbd2_journal_free_transaction(new_transaction);
 	return 0;
 }
 
-static struct lock_class_key jbd2_handle_key;
-
 /* Allocate a new handle.  This should probably be in a slab... */
 static handle_t *new_handle(int nblocks)
 {
@@ -398,9 +396,6 @@ static handle_t *new_handle(int nblocks)
 	handle->h_buffer_credits = nblocks;
 	handle->h_ref = 1;
 
-	lockdep_init_map(&handle->h_lockdep_map, "jbd2_handle",
-						&jbd2_handle_key, 0);
-
 	return handle;
 }
 
@@ -672,7 +667,7 @@ int jbd2__journal_restart(handle_t *handle, int nblocks, gfp_t gfp_mask)
 	if (need_to_start)
 		jbd2_log_start_commit(journal, tid);
 
-	lock_map_release(&handle->h_lockdep_map);
+	rwsem_release(&journal->j_trans_commit_map, 1, _THIS_IP_);
 	handle->h_buffer_credits = nblocks;
 	ret = start_this_handle(journal, handle, gfp_mask);
 	return ret;
@@ -1750,7 +1745,7 @@ int jbd2_journal_stop(handle_t *handle)
 			wake_up(&journal->j_wait_transaction_locked);
 	}
 
-	lock_map_release(&handle->h_lockdep_map);
+	rwsem_release(&journal->j_trans_commit_map, 1, _THIS_IP_);
 
 	if (wait_for_commit)
 		err = jbd2_log_wait_commit(journal, tid);
diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
index efb232c5f668..f6232b28eadc 100644
--- a/include/linux/jbd2.h
+++ b/include/linux/jbd2.h
@@ -491,10 +491,6 @@ struct jbd2_journal_handle
 
 	unsigned long		h_start_jiffies;
 	unsigned int		h_requested_credits;
-
-#ifdef CONFIG_DEBUG_LOCK_ALLOC
-	struct lockdep_map	h_lockdep_map;
-#endif
 };
 
 
@@ -1035,6 +1031,18 @@ struct journal_s
 
 	/* Precomputed journal UUID checksum for seeding other checksums */
 	__u32 j_csum_seed;
+
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+	/*
+	 * Lockdep entity to track transaction commit dependencies. Handles
+	 * hold this "lock" for read, when we wait for commit, we acquire the
+	 * "lock" for writing. This matches the properties of jbd2 journalling
+	 * where the running transaction has to wait for all handles to be
+	 * dropped to commit that transaction and also acquiring a handle may
+	 * require transaction commit to finish.
+	 */
+	struct lockdep_map	j_trans_commit_map;
+#endif
 };
 
 /* journal feature predicate functions */
-- 
2.6.6


  parent reply	other threads:[~2016-06-16 10:42 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-16 10:42 [PATCH 0/4] ext4: Fix deadlock during page writeback Jan Kara
2016-06-16 10:42 ` [PATCH 1/4] " Jan Kara
2016-06-30 15:05   ` Theodore Ts'o
2016-07-01  9:09     ` Jan Kara
2016-07-01 16:53       ` Theodore Ts'o
2016-07-01 17:40         ` Jan Kara
2016-07-01 21:26           ` Theodore Ts'o
2016-07-04 14:00             ` Jan Kara
2016-07-04 15:20               ` Theodore Ts'o
2016-07-04 15:47                 ` Jan Kara
2016-07-05  2:43                   ` Theodore Ts'o
2016-07-06  7:04                     ` Jan Kara
2016-07-04 14:14             ` Theodore Ts'o
2016-07-04 15:51               ` Jan Kara
2016-07-05  3:38                 ` Theodore Ts'o
2016-07-06  7:51                   ` Jan Kara
2016-07-06 12:35                     ` Theodore Ts'o
2016-07-06 12:52                       ` Jan Kara
2016-07-06 14:27                         ` Theodore Ts'o
2016-07-06 14:41                           ` Jan Kara
2016-06-16 10:42 ` [PATCH 2/4] jbd2: Move lockdep instrumentation for jbd2 handles Jan Kara
2016-06-30 15:34   ` Theodore Ts'o
2016-06-16 10:42 ` Jan Kara [this message]
2016-06-16 11:42   ` [PATCH 3/4] jbd2: Move lockdep tracking to journal_s kbuild test robot
2016-06-30 15:40   ` Theodore Ts'o
2016-06-16 10:42 ` [PATCH 4/4] jbd2: Track more dependencies on transaction commit Jan Kara
2016-06-30 15:45   ` Theodore Ts'o

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=1466073736-30447-4-git-send-email-jack@suse.cz \
    --to=jack@suse.cz \
    --cc=eguan@redhat.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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).