Symmetric Multiprocessing UNIX

The introduction of SMP hardware and SMP-based UNIX implementations resulted in a completely new set of locking primitives and removal of the old sleep(), wakeup(), and spl() primitives. With an SMP implementation, multiple threads of control can be executing the same piece of kernel code on different processors at the same time. More importantly, these threads can be accessing the same data structures at the same time.

Early SMP implementations were based around a global kernel lock. Each time a process entered the kernel it grabbed the kernel lock and ran in an environment similar to the UP kernels described above. Any other processes entering the kernel were required to sleep until the first processes released the kernel lock. For environments where most work was performed in user space with little I/O, this worked well. However, these environments are not very representative of most real world applications.

Over the years, these coarse grain locks were replaced by a much finer grain locking model. Imagine any number of threads running in the kernel at the same time. Accessing kernel structures in a read-only manner is fine. However, any time a kernel structure needs to be modified you must bear in mind that while the structure, a linked list for example, is in the process of changing, another thread may be in the process of reading the structure. This is obviously undesirable because the reader might see a corrupt linked list, access NULL pointers, ...

Get UNIX Filesystems: Evolution, Design, and Implementation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.