I'm calling you on "Caller Locks"
I'm calling you on "Caller Locks"
Posted Jul 4, 2009 0:51 UTC (Sat) by neilbrown (subscriber, #359)In reply to: I'm calling you on "Caller Locks" by prl
Parent article: Linux kernel design patterns - part 3
I do have a vague memory of a well known kernel developer - with 4 initials - saying something about a preference for caller-locks, but I cannot find it and so am left without the protection of "proof by authority".
I would still maintain that in the context of generic data structures provided by a library, the evidence within the kernel is in favour of caller-locking rather than callee locking, but is an unjustifiable step to claim that it is, therefore, preferred.
In a different context, there is plenty of evidence that callee locking is preferred. There has recently been more work towards removing the BKL, and some of this has involved pushing the locking down from caller to callee, and actually changing a locking style seems to suggest a strong preference.
This is quite a different context though. The callee is not a distinct library routine that will be called from a number of places (each with different SMP-safety requirements), but is one of a number of per-device implementations of a common interface (e.g. ioctl). So instead of one function called from lots of places, you have lots of functions called from one place. Having callee locking in this case is good as it provides the callee with more control of locking, including the choice not to lock at all.
I think your example concerning multi-core devices lines up with the second scenario, and they both fit under the "midlayer mistake" pattern to some extent.
Under that pattern, the subsystem should be given as much control as possible, not having anything imposed on it by any midlayer - and in particular not having any locking imposed on it.
So maybe what I really wanted to say is that for a library interface it is usually best to choose caller-locking, while for a subsystem interface, it is usually best to choose callee-locking. At least, that is what 10 minutes of thought leads me to. I wonder if it is possible to come up with a strong definition of the difference between a "library" interface and a "subsystem" interface...
Thanks for your challenge, I really appreciate it!