lkml.org 
[lkml]   [2011]   [Sep]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH RFC] lockdep: Update documentation for lock-class leak detection
There are a number of bugs that can leak lock classes, which will
eventually exhaust the maximum number (currently 8191). However,
the documentation does not tell you how to track down the leakers.
This commit addresses this shortcoming.

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>

diff --git a/Documentation/lockdep-design.txt b/Documentation/lockdep-design.txt
index abf768c..24bfd9f 100644
--- a/Documentation/lockdep-design.txt
+++ b/Documentation/lockdep-design.txt
@@ -221,3 +221,55 @@ when the chain is validated for the first time, is then put into a hash
table, which hash-table can be checked in a lockfree manner. If the
locking chain occurs again later on, the hash table tells us that we
dont have to validate the chain again.
+
+Troubleshooting:
+----------------
+
+The validator tracks a maximum of MAX_LOCKDEP_KEYS number of lock classes.
+Exceeding this number will trigger the following lockdep warning:
+
+ (DEBUG_LOCKS_WARN_ON(id >= MAX_LOCKDEP_KEYS))
+
+By default, MAX_LOCKDEP_KEYS is currently set to 8191, and typical
+desktop systems have less than 1,000 lock classes, so this warning
+normally results from lock-class leakage. Such leakage can result
+from the following:
+
+1. Repeated module loading and unloading while running the validator.
+ The issue here is that each load of the module will create a
+ new set of lock classes for that module's locks, and module
+ unloading cannot remove old classes. Therefore, if that module
+ is loaded and unloaded repeatedly, the number of lock classes
+ will eventually reach the maximum.
+
+2. Dynamically allocating and freeing structures containing fields
+ of type "struct lock_class_key". Again, the fact that old
+ lock classes cannot be reused means that repeating allocation/free
+ cycles for long enough will cause the number of lock classes to
+ eventually reach the maximum.
+
+One might argue that the validator should be modified to allow lock
+classes to be reused. However, if you are tempted to make this argument,
+first review the code and think through the changes that would be
+required, keeping in mind that the lock classes to be removed are likely
+to be linked into the lock-dependency graph. This turns out to be a
+harder to do than to say.
+
+But if you run out of lock classes, the next question is what are the
+offending lock classes. First, the following command gives you the
+number of lock classes currently in use along with the maximum:
+
+ grep "lock-classes" /proc/lockdep_stats
+
+This command gets the following output on a modest Power system:
+
+ lock-classes: 748 [max: 8191]
+
+If the number allocated (748 above) increases continually over time,
+then there is likely a leak. The following command can be used to
+identify the leaking lock classes:
+
+ grep "BD" /proc/lockdep
+
+Run the command and save the output, then compare against the output
+from a later run of this command to identify the leakers.

\
 
 \ /
  Last update: 2011-09-28 20:15    [W:0.048 / U:0.684 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site