Kernel developers are expected to identify and solve the synchronization problems raised interleaving by kernel control paths. However, avoiding race conditions is a hard task because it requires a clear understanding of how the various components of the kernel interact. To give a feeling of what’s really inside the kernel code, let’s mention a few typical usages of the synchronization primitives defined in this chapter.
Reference counters are widely used inside the kernel to avoid race
conditions due to the concurrent allocation and releasing of a
resource. A reference counter
is just an
counter associated with a specific resource like a memory page, a
module, or a file. The counter is atomically incremented when a
kernel control path starts using the resource, and it is decremented
when a kernel control path finishes using the resource. When the
reference counter becomes zero, the resource is not being used, and
it can be released if necessary.
In earlier Linux kernel versions, a global kernel lock (also known as big kernel lock , or BKL) was widely used. In Version 2.0, this lock was a relatively crude spin lock, ensuring that only one processor at a time could run in Kernel Mode. The 2.2 kernel was considerably more flexible and no longer relied on a single spin lock; rather, a large number of kernel data structures were protected by specialized spin locks. The global kernel lock, on other ...