diff --git a/Documentation/locking/lockdep-design.rst b/Documentation/locking/lockdep-design.rst index 82f36cab61bd..3bdc7a515df1 100644 --- a/Documentation/locking/lockdep-design.rst +++ b/Documentation/locking/lockdep-design.rst @@ -231,6 +231,31 @@ Note: When changing code to use the _nested() primitives, be careful and check really thoroughly that the hierarchy is correctly mapped; otherwise you can get false positives or false negatives. +Pseudo locks +------------ + +Lockdep can detect some situations which lead to a deadlock by using +a pseudo lock. One such example is fs_reclaim. In this situation, +the deadlock is:: + + mutex_lock(A); + kmalloc(n, GFP_KERNEL); + (memory allocation enters filesystem reclaim) + mutex_lock(A); + +If every filesystem reclaim took mutex A, and every call to kmalloc() +entered filesystem reclaim, lockdep would find this deadlock immediately +and there would be no need for this special case. However, most memory +allocations will not enter reclaim at all, let alone filesystem reclaim, +and not all filesystem reclaim paths take the same set of locks. So we +introduce a pseudo lock called fs_reclaim which is acquired for every +memory allocation which might call fs reclaim. + +Previously, we used to treat fs reclaim as its own context like hardirq +and softirq context, but it is more efficient for lockdep to treat it as +a pseudo lock. This approach can be used for other pseudo locks without +needing to add more locking contexts. + Annotations -----------