Not logged in
Log in now
Create an account
Subscribe to LWN
LWN.net Weekly Edition for May 23, 2013
An "enum" for Python 3
An unexpected perf feature
LWN.net Weekly Edition for May 16, 2013
A look at the PyPy 2.0 release
the list of locks is not static.
remember basic and line numbers? no matter how you started your numbering scheme you eventually ran into trouble.
The kernel lock validator
Posted Jun 9, 2006 4:13 UTC (Fri) by slamb (guest, #1070)
Locks which are allocated dynamically (as most locks embedded within structures
[...] should be mapped to a single key. [...] Thus, for each lock initialization, this code creates a
static variable (__key) and uses
its address as the key identifying the type of the lock. Since any particular type of lock tends to
initialized in a single place, this trick associates the same key with every lock of the same
I also work in a project which assigns ranks manually.
Disadvantage: especially given the number of locks in the Linux kernel, it'd be a large initial
effort to go through and create a ranking consistent with all the approved locking orders. (On the
other hand, not doing it probably means struggling with this list over and over without it actually
being written down anywhere.)
Advantage: you wouldn't even need to run through two code paths to know that they
can deadlock - just the one you've defined as wrong.
Advantage: it'd remove all the heaviness of the lock validator. There's no need for
the "before" and "after" lists; the rank defines them. The stack could be just a bit array - small
enough that it's probably practical to preallocate its full extent on thread creation. Thus, the lock
validator would not add potential out of memory failures, and it'd run quickly. There'd be no
reason not to always have it on.
(Actually, I'm not sure how strict the same-key locking stuff (spin_lock_nested
and such) is. To track those, a fancier stack might still be necessary.)
Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds