We now examine how kernel control paths can be interleaved while avoiding race conditions among shared data. Table 5-2 lists the synchronization techniques used by the Linux kernel. The "Scope" column indicates whether the synchronization technique applies to all CPUs in the system or to a single CPU. For instance, local interrupt disabling applies to just one CPU (other CPUs in the system are not affected); conversely, an atomic operation affects all CPUs in the system (atomic operations on several CPUs cannot interleave while accessing the same data structure).
Table 5-2. Various types of synchronization techniques used by the kernel
Duplicate a data structure among the CPUs
Atomic read-modify-write instruction to a counter
Avoid instruction reordering
Local CPU or All CPUs
Lock with busy wait
Lock with blocking wait (sleep)
Lock based on an access counter
Local interrupt disabling
Forbid interrupt handling on a single CPU
Local softirq disabling
Forbid deferrable function handling on a single CPU
Lock-free access to shared data structures through pointers
Let's now briefly discuss each synchronization technique. In the later section "Synchronizing Accesses to Kernel Data Structures," we show how these synchronization techniques can be combined to effectively protect kernel data ...