Almost every one of the previous ten chapters has a “Misuse and Debugging” section, and the same name keeps coming up: lockdep. It is the kernel’s run-time deadlock detector, able to report a potential lock-ordering problem from a single ordinary run, even when the deadlock never actually happens. This chapter takes its engine apart to see how it manages to “know about a deadlock before it happens”.
lockdep is a sizable body of code. This chapter focuses on its core data structures and cycle-detection algorithm, anchored on kernel/locking/lockdep.c. It is enabled by CONFIG_PROVE_LOCKING, is purely a debugging facility, and is usually disabled in production kernels.
Note: lockdep is independent of any particular lock implementation. It hooks into the lock and unlock paths of every lock to record and validate on the side, so this chapter does not distinguish between lock types.