Article title: queuing spin lock for Linux kernel. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
The FIFO Ticket Spinlock is a new type of spin lock introduced in Linux kernel 2.6.25. it solves the "fairness" problem caused by disorderly competition of traditional spin locks. This article describes in detail the design principles and implementation of queuing spin locks, and compares them with similar technologies used in Windows. Finally, we discuss some possible ideas for extending the queuing spin lock.
Introduction
The spin lock is an underlying synchronization mechanism widely used in Linux kernel. A spin lock is a special lock that works in a multi-processor environment. in a single processing environment, the spin lock operation is replaced with a null operation. When a kernel execution thread on a processor applies for a spin lock, if the lock is available, the lock is obtained, and then the critical zone operation is executed to release the lock. if the lock is occupied, the thread is not going to sleep, but is waiting for the lock. once the lock is released, the first thread that perceives this information will get the lock.
For a long time, people have always focused on the security and efficiency of spin locks, while ignoring the "fairness" of spin locks. The traditional spin lock is essentially represented by an integer. The value of 1 indicates that the lock is not occupied. Due to this nature of disorderly competition, the execution thread cannot guarantee when the lock can be obtained. some threads may have to wait for a long time. With the increasing number of computer processors, this "unfair" problem will become increasingly serious.
The queuing spin lock (FIFO Ticket Spinlock) is a new type of spin lock introduced in Linux kernel 2.6.25, it solves the "unfair" problem of the traditional spin lock by saving the sequential information of the lock applied by the execution thread. The code for queuing spin locks is implemented by Linux kernel developer Nick Piggin. Currently, it is only for x86 architecture (including IA32 and x86_64). I believe it will soon be transplanted to other platforms.
[1] [2] [3] [4] [5] Next page