From: Waiman Long <longman@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Will Deacon <will.deacon@arm.com>
Cc: linux-kernel@vger.kernel.org,
Bart Van Assche <bvanassche@acm.org>,
Waiman Long <longman@redhat.com>
Subject: [PATCH v2 2/6] locking/lockdep: Throw away all lock chains with zapped class
Date: Mon, 16 Dec 2019 10:15:13 -0500 [thread overview]
Message-ID: <20191216151517.7060-3-longman@redhat.com> (raw)
In-Reply-To: <20191216151517.7060-1-longman@redhat.com>
If a lock chain contains a class that is zapped, the whole lock chain is
now invalid. There is no point in keeping a partial chain behind hoping
it can be useful. So just dump the corresponding chain_hlocks entries for
now. A latter patch will try to reuse the freed chain_hlocks entries.
This patch also changes the type of nr_chain_hlocks to unsigned integer
to be consistent with the other counters.
Signed-off-by: Waiman Long <longman@redhat.com>
---
kernel/locking/lockdep.c | 36 ++++--------------------------
kernel/locking/lockdep_internals.h | 4 ++--
kernel/locking/lockdep_proc.c | 2 +-
3 files changed, 7 insertions(+), 35 deletions(-)
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index c8d0374101b0..30ebfe4978d5 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -2624,8 +2624,8 @@ check_prevs_add(struct task_struct *curr, struct held_lock *next)
struct lock_chain lock_chains[MAX_LOCKDEP_CHAINS];
static DECLARE_BITMAP(lock_chains_in_use, MAX_LOCKDEP_CHAINS);
-int nr_chain_hlocks;
static u16 chain_hlocks[MAX_LOCKDEP_CHAIN_HLOCKS];
+unsigned int nr_chain_hlocks;
struct lock_class *lock_chain_get_class(struct lock_chain *chain, int i)
{
@@ -4770,57 +4770,29 @@ static void remove_class_from_lock_chain(struct pending_free *pf,
struct lock_class *class)
{
#ifdef CONFIG_PROVE_LOCKING
- struct lock_chain *new_chain;
- u64 chain_key;
int i;
for (i = chain->base; i < chain->base + chain->depth; i++) {
if (chain_hlocks[i] != class - lock_classes)
continue;
- /* The code below leaks one chain_hlock[] entry. */
- if (--chain->depth > 0) {
- memmove(&chain_hlocks[i], &chain_hlocks[i + 1],
- (chain->base + chain->depth - i) *
- sizeof(chain_hlocks[0]));
- }
/*
* Each lock class occurs at most once in a lock chain so once
* we found a match we can break out of this loop.
*/
- goto recalc;
+ goto free_lock_chain;
}
/* Since the chain has not been modified, return. */
return;
-recalc:
- chain_key = INITIAL_CHAIN_KEY;
- for (i = chain->base; i < chain->base + chain->depth; i++)
- chain_key = iterate_chain_key(chain_key, chain_hlocks[i]);
- if (chain->depth && chain->chain_key == chain_key)
- return;
+free_lock_chain:
/* Overwrite the chain key for concurrent RCU readers. */
- WRITE_ONCE(chain->chain_key, chain_key);
+ WRITE_ONCE(chain->chain_key, INITIAL_CHAIN_KEY);
/*
* Note: calling hlist_del_rcu() from inside a
* hlist_for_each_entry_rcu() loop is safe.
*/
hlist_del_rcu(&chain->entry);
__set_bit(chain - lock_chains, pf->lock_chains_being_freed);
- if (chain->depth == 0)
- return;
- /*
- * If the modified lock chain matches an existing lock chain, drop
- * the modified lock chain.
- */
- if (lookup_chain_cache(chain_key))
- return;
- new_chain = alloc_lock_chain();
- if (WARN_ON_ONCE(!new_chain)) {
- debug_locks_off();
- return;
- }
- *new_chain = *chain;
- hlist_add_head_rcu(&new_chain->entry, chainhashentry(chain_key));
#endif
}
diff --git a/kernel/locking/lockdep_internals.h b/kernel/locking/lockdep_internals.h
index a31d16fd3c43..5dec0fe12507 100644
--- a/kernel/locking/lockdep_internals.h
+++ b/kernel/locking/lockdep_internals.h
@@ -128,14 +128,14 @@ extern unsigned long nr_zapped_classes;
extern unsigned long nr_list_entries;
long lockdep_next_lockchain(long i);
unsigned long lock_chain_count(void);
-extern int nr_chain_hlocks;
extern unsigned long nr_stack_trace_entries;
extern unsigned int nr_hardirq_chains;
extern unsigned int nr_softirq_chains;
extern unsigned int nr_process_chains;
-extern unsigned int max_lockdep_depth;
+extern unsigned int nr_chain_hlocks;
+extern unsigned int max_lockdep_depth;
extern unsigned int max_bfs_queue_depth;
#ifdef CONFIG_PROVE_LOCKING
diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
index d98d349bb648..4c7dc0a8935d 100644
--- a/kernel/locking/lockdep_proc.c
+++ b/kernel/locking/lockdep_proc.c
@@ -271,7 +271,7 @@ static int lockdep_stats_show(struct seq_file *m, void *v)
#ifdef CONFIG_PROVE_LOCKING
seq_printf(m, " dependency chains: %11lu [max: %lu]\n",
lock_chain_count(), MAX_LOCKDEP_CHAINS);
- seq_printf(m, " dependency chain hlocks: %11d [max: %lu]\n",
+ seq_printf(m, " dependency chain hlocks: %11u [max: %lu]\n",
nr_chain_hlocks, MAX_LOCKDEP_CHAIN_HLOCKS);
#endif
--
2.18.1
next prev parent reply other threads:[~2019-12-16 15:16 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-16 15:15 [PATCH v2 0/6] locking/lockdep: Reuse zapped chain_hlocks entries Waiman Long
2019-12-16 15:15 ` [PATCH v2 1/6] locking/lockdep: Track number of zapped classes Waiman Long
2020-01-13 14:55 ` Peter Zijlstra
2020-01-13 14:58 ` Waiman Long
2020-01-13 16:02 ` Bart Van Assche
2019-12-16 15:15 ` Waiman Long [this message]
2020-01-13 15:18 ` [PATCH v2 2/6] locking/lockdep: Throw away all lock chains with zapped class Peter Zijlstra
2020-01-13 15:44 ` Waiman Long
2020-01-13 16:05 ` Bart Van Assche
2020-01-13 16:15 ` Waiman Long
2019-12-16 15:15 ` [PATCH v2 3/6] locking/lockdep: Track number of zapped lock chains Waiman Long
2019-12-16 15:15 ` [PATCH v2 4/6] locking/lockdep: Reuse freed chain_hlocks entries Waiman Long
2020-01-13 15:51 ` Peter Zijlstra
2020-01-13 16:04 ` Waiman Long
2020-01-13 15:58 ` Peter Zijlstra
2020-01-13 16:24 ` Waiman Long
2020-01-14 9:46 ` Peter Zijlstra
2020-01-14 19:16 ` Waiman Long
2020-01-15 10:44 ` Peter Zijlstra
2020-01-15 19:26 ` Waiman Long
2020-01-13 15:59 ` Peter Zijlstra
2020-01-13 16:03 ` Waiman Long
2019-12-16 15:15 ` [PATCH v2 5/6] locking/lockdep: Decrement irq context counters when removing lock chain Waiman Long
2020-01-14 9:53 ` Peter Zijlstra
2020-01-14 15:04 ` Waiman Long
2019-12-16 15:15 ` [PATCH v2 6/6] locking/lockdep: Display irq_context names in /proc/lockdep_chains Waiman Long
2020-01-06 15:54 ` [PATCH v2 0/6] locking/lockdep: Reuse zapped chain_hlocks entries Waiman Long
2020-01-06 16:50 ` Peter Zijlstra
2020-01-06 16:52 ` Waiman Long
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=20191216151517.7060-3-longman@redhat.com \
--to=longman@redhat.com \
--cc=bvanassche@acm.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=will.deacon@arm.com \
/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