spinlock automatically disables preemption, which avoids deadlock caused by interrupts. when data is shared with interrupt handler, before holding spinlock we must disable interrupts. when data is shared with bottom halves, before holding spinlock we must disable bottom halves.
How do I disable preemption?
Preemption Disabling
- Because the kernel is preemptive, a process in the kernel can stop running at any instant to allow a process of higher priority to run. ...
- To solve this, kernel preemption can be disabled via preempt_disable(). ...
- The preemption count stores the number of held locks and preempt_disable() calls.
Why is spinlock bad?
The primary disadvantage of a spinlock is that, while waiting to acquire a lock, it wastes time that might be productively spent elsewhere. There are two ways to avoid this: Do not acquire the lock.