# Giant lock

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Giant_lock
> Markdown URL: https://mediated.wiki/source/Giant_lock.md
> Source: https://en.wikipedia.org/wiki/Giant_lock
> Source revision: 1250701558
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{Short description|Lock used in computer kernels}}
In [operating system](/source/operating_system)s, a '''giant lock''', also known as a '''big-lock''' or '''kernel-lock''', is a [lock](/source/Lock_(computer_science)) that may be used in the [kernel](/source/kernel_(operating_system)) to provide [concurrency control](/source/concurrency_control) required by [symmetric multiprocessing](/source/symmetric_multiprocessing) (SMP) systems.

A giant lock is a solitary global lock that is held whenever a [thread](/source/Thread_(computing)) enters [kernel space](/source/user_space_and_kernel_space) and released when the thread returns to [user space](/source/user_space_and_kernel_space); a [system call](/source/system_call) is the archetypal example. In this model, threads in user space can run concurrently on any available [processors](/source/microprocessor) or [processor cores](/source/Multi-core), 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](/source/concurrency_(computer_science)) 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.{{r|rwatson2007}} 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](/source/fine-grained_locking) approach.

== Linux ==
The [Linux kernel](/source/Linux_kernel) had a big kernel lock (BKL) since the introduction of SMP, until [Arnd Bergmann](/source/Arnd_Bergmann) removed it in 2011 in kernel version 2.6.39,<ref>{{Cite web |url=https://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git%3Ba%3Dcommitdiff%3Bh%3D4ba8216cd90560bc402f52076f64d8546e8aefcb |title=git.kernel.org: ''BKL: that's all folks'' |access-date=2019-12-28 |archive-url=https://archive.today/20120720043351/http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=4ba8216cd90560bc402f52076f64d8546e8aefcb |archive-date=2012-07-20 |url-status=dead }}</ref><ref>https://kernelnewbies.org/BigKernelLock – BigKernelLock at kernelnewbies.org</ref> with the remaining uses of the big lock removed or replaced by finer-grained locking. [Linux distribution](/source/Linux_distribution)s at or above [CentOS 7](/source/CentOS), [Debian 7 (Wheezy)](/source/Debian_version_history) and [Ubuntu 11.10](/source/Ubuntu_version_history) are therefore not using BKL.

{{As of|2022|09}}, Linux kernel still has ''console_lock'' and ''rtnl_lock'', which are sometimes referred as BKL, and its removal is in progress.<ref>[https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1432794.html PATCH - fbcon: Make fbcon a built-time depency for fbdev]. Daniel Vetter. June 28, 2017</ref><ref>{{cite mailing list |url=https://lore.kernel.org/lkml/20220910222301.479172669@linutronix.de/ |title=[patch RFC 19/29] printk: Add basic infrastructure for non-BKL consoles |author=Thomas Gleixner |date=September 11, 2022 |mailing-list=linux-kernel}}</ref><ref>{{cite conference |url=https://strlen.de/talks/netdev22_rtnl.pdf |title=rtnl mutex, the network stack big kernel lock |author=Florian Westphal |date=November 2017 |conference=netdev 2.2 |location=Seoul}}</ref><ref>{{cite conference |url=https://lpc.events/event/18/contributions/1959/ |title=Per Netns RTNL |author=Kuniyuki Iwashima |conference=Linux Plumbers Conference 2024 |location=Vienna, Austria |date=September 18, 2024}}</ref>

== BSD ==
{{As of|2019|07}}, [OpenBSD](/source/OpenBSD) and [NetBSD](/source/NetBSD) are still using the [spl](/source/spl_(Unix)) family of primitives to facilitate synchronisation of critical sections within the kernel,{{r|o/net/if|n/net/if|spl.9}} meaning that many system calls may inhibit SMP capabilities of the system, and, according to [Matthew Dillon](/source/Matthew_Dillon), the SMP capabilities of these two systems cannot be considered modern.{{r|dillon2019}}

FreeBSD still has support for ''the Giant mutex'',{{r|f/locking.9}} which provides semantics akin to the old spl interface, but performance-critical core components have long been converted to use finer-grained locking.{{r|rwatson2007}}

It is claimed by [Matthew Dillon](/source/Matthew_Dillon) that out of the [open-source software](/source/open-source_software) general-purpose operating systems, only [Linux](/source/Linux), [DragonFly BSD](/source/DragonFly_BSD) and [FreeBSD](/source/FreeBSD) have modern SMP support, with [OpenBSD](/source/OpenBSD) and [NetBSD](/source/NetBSD) falling behind.{{r|dillon2019}}

The [NetBSD](/source/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)](/source/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.{{r|n/net/if|tnf/smp}}

==See also==
* [Parallel computing](/source/Parallel_computing)
* [Lock (computer science)](/source/Lock_(computer_science))
* [Global interpreter lock](/source/Global_interpreter_lock)

==References==
{{Reflist
|refs=

<ref name = "o/net/if" >{{cite web
|url = http://bxr.su/o/sys/net/if.c
|title = /sys/net/if.c
|website = BSD Cross Reference
|publisher = [OpenBSD](/source/OpenBSD)
|date = 2019-06-30
|access-date = 2019-07-25
|quote = s = splnet();
}}</ref>

<ref name = "n/net/if" >{{cite web
|url = http://bxr.su/n/sys/net/if.c
|title = /sys/net/if.c
|website = BSD Cross Reference
|publisher = [NetBSD](/source/NetBSD)
|date = 2019-07-25
|access-date = 2019-07-25
|quote = s = splnet();
}}</ref>

<ref name= spl.9 >{{cite web
|url= http://mdoc.su/n,o/spl.9
|title= splx(9) — modify system interrupt priority level
|publisher= [NetBSD](/source/NetBSD), [OpenBSD](/source/OpenBSD)
|access-date= 2019-07-25
}}</ref>

<ref name = "f/locking.9" >{{cite web
|author= Julian Elischer |year= 2007
|url= http://bxr.su/f/share/man/man9/locking.9
|title= locking(9) — kernel synchronization primitives
|website= BSD Cross Reference |publisher= [FreeBSD](/source/FreeBSD)
|access-date= 2019-07-25
|quote= 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, …
}}
*{{cite book |section=locking -- kernel synchronization primitives |title=FreeBSD Manual Pages |url=http://mdoc.su/f/locking.9}}</ref>

<ref name = rwatson2007 >{{cite mailing list
|author= Robert N M Watson |author-link= Robert Watson (computer scientist) |date= 2007-11-25
|url= https://lists.freebsd.org/pipermail/freebsd-hackers/2007-November/022368.html
|title= Before & After Under The Giant Lock
|mailing-list= FreeBSD-Hackers@ |publisher= [FreeBSD](/source/FreeBSD)
|access-date= 2019-07-25
}}</ref>

<ref name = dillon2019 >{{cite mailing list
|author= Matthew Dillon
|author-link= Matthew Dillon
|date= 2019-07-22
|url= http://lists.dragonflybsd.org/pipermail/users/2019-July/358226.html
|title= DragonFlyBSD Project Update - colo upgrade, future trends
|mailing-list= users@ |publisher= [DragonFly BSD](/source/DragonFly_BSD)
|access-date= 2019-07-25
}}</ref>

<ref name= "tnf/smp" >{{cite web
|url= http://wiki.netbsd.org/projects/project/smp_networking/
|title= SMP Networking (aka remove the big network lock)
|publisher= [NetBSD](/source/NetBSD)
|date= 2013-02-14
|access-date= 2023-03-26
|archive-url= https://web.archive.org/web/20190725193614/http://wiki.netbsd.org/projects/project/smp_networking/
|url-status= live
|archive-date= 2019-07-25
}}</ref>

}}

{{DEFAULTSORT:Giant Lock}}
Category:Concurrency control

---
Adapted from the Wikipedia article [Giant lock](https://en.wikipedia.org/wiki/Giant_lock) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Giant_lock?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
