Giant lock

From HandWiki
Short description: Lock used in computer kernels

In operating systems, a giant lock, also known as a big-lock or kernel-lock, is a lock that may be used in the kernel to provide concurrency control required by symmetric multiprocessing (SMP) systems.

A giant lock is a solitary global lock that is held whenever a thread enters kernel space and released when the thread returns to user space; a system call is the archetypal example. In this model, threads in user space can run concurrently on any available processors or processor cores, but no more than one thread can run in kernel space; any other threads that try to enter kernel space are forced to wait. In other words, the giant lock eliminates all concurrency in kernel space.

By isolating the kernel from concurrency, many parts of the kernel no longer need to be modified to support SMP. However, as in giant-lock SMP systems only one processor can run the kernel code at a time, performance for applications spending significant amounts of time in the kernel is not much improved.[1] Accordingly, the giant-lock approach is commonly seen as a preliminary means of bringing SMP support to an operating system, yielding benefits only in user space. Most modern operating systems use a fine-grained locking approach.

Linux

The Linux kernel had a big kernel lock (BKL) since the introduction of SMP, until Arnd Bergmann removed it in 2011 in kernel version 2.6.39,[2][3] with the remaining uses of the big lock removed or replaced by finer-grained locking. Linux distributions at or above CentOS 7, Debian 7 (Wheezy) and Ubuntu 11.10 are therefore not using BKL.

(As of September 2022), Linux kernel still has console_lock which is sometimes referred as BKL and its removal is in progress.[4][5]

BSD

(As of July 2019), OpenBSD and NetBSD are still using the spl (Unix) family of primitives to facilitate synchronisation of critical sections within the kernel,[6][7][8] meaning that many system calls may inhibit SMP capabilities of the system, and, according to Matthew Dillon, the SMP capabilities of these two systems cannot be considered modern.[9]

FreeBSD still has support for the Giant mutex,[10] which provides semantics akin to the old spl interface, but performance-critical core components have long been converted to use finer-grained locking.[1]

It is claimed by Matthew Dillon that out of the open-source software general-purpose operating systems, only Linux, DragonFly BSD and FreeBSD have modern SMP support, with OpenBSD and NetBSD falling behind.[9]

The NetBSD Foundation views modern SMP support as vital to the direction of The NetBSD Project, and has offered grants to developers willing to work on SMP improvements; NPF (firewall) was one of the projects that arose as a result of these financial incentives, but further improvements to the core networking stack may still be necessary.[7][11]

See also

References

  1. 1.0 1.1 "Before & After Under The Giant Lock". FreeBSD-Hackers@ (Mailing list). FreeBSD. Retrieved 2019-07-25.
  2. "git.kernel.org: BKL: that's all folks". https://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git%3Ba%3Dcommitdiff%3Bh%3D4ba8216cd90560bc402f52076f64d8546e8aefcb. 
  3. https://kernelnewbies.org/BigKernelLock – BigKernelLock at kernelnewbies.org
  4. PATCH - fbcon: Make fbcon a built-time depency for fbdev. Daniel Vetter. June 28, 2017
  5. patch RFC 19/29 - printk: Add basic infrastructure for non-BKL consoles. Thomas Gleixner. September 11, 2022
  6. "/sys/net/if.c". OpenBSD. 2019-06-30. http://bxr.su/o/sys/net/if.c. "s = splnet();" 
  7. 7.0 7.1 "/sys/net/if.c". NetBSD. 2019-07-25. http://bxr.su/n/sys/net/if.c. "s = splnet();" 
  8. "splx(9) — modify system interrupt priority level". NetBSD, OpenBSD. http://mdoc.su/n,o/spl.9. 
  9. 9.0 9.1 Matthew Dillon (2019-07-22). "DragonFlyBSD Project Update - colo upgrade, future trends". users@ (Mailing list). DragonFly BSD. Retrieved 2019-07-25.
  10. Julian Elischer (2007). "locking(9) — kernel synchronization primitives". FreeBSD. http://bxr.su/f/share/man/man9/locking.9. "Giant is a special mutex used to protect data structures that do not yet have their own locks. Since it provides semantics akin to the old spl(9) interface, …" 
  11. "SMP Networking (aka remove the big network lock)". NetBSD. 2013-02-14. http://wiki.netbsd.org/projects/project/smp_networking/.