Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Context switch
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Cost == Context switches are usually computationally intensive, and much of the design of operating systems is to optimize the use of context switches. Switching from one process to another requires a certain amount of time for doing the administration{{snd}} saving and loading registers and memory maps, updating various tables and lists, etc. What is actually involved in a context switch depends on the architectures, operating systems, and the number of resources shared (threads that belong to the same process share many resources compared to unrelated non-cooperating processes). For example, in the [[Linux kernel]], context switching involves loading the corresponding [[process control block]] (PCB) stored in the PCB table in the kernel stack to retrieve information about the state of the new process. CPU state information including the registers, [[Processor register|stack pointer]], and [[program counter]] as well as memory management information like [[Memory segmentation|segmentation tables]] and [[page table|page tables]] (unless the old process shares the memory with the new) are loaded from the PCB for the new process. To avoid incorrect address translation in the case of the previous and current processes using different memory, the [[translation lookaside buffer]] (TLB) must be flushed. This negatively affects performance because every memory reference to the TLB will be a miss because it is empty after most context switches.<ref>''IA-64 Linux Kernel: Design and Implementation'', [http://www.informit.com/articles/article.aspx?p=29961&seqNum=7 4.7 Switching Address Spaces]</ref><ref>''Operating Systems'', 5.6 The Context Switch, [https://books.google.com/books?id=orZ0CLxEMXEC&pg=PA118 p. 118]</ref> Furthermore, analogous context switching happens between [[user thread]]s, notably [[green thread]]s, and is often very lightweight, saving and restoring minimal context. In extreme cases, such as switching between [[goroutine]]s in [[Go (programming language)|Go]], a context switch is equivalent to a [[coroutine]] yield, which is only marginally more expensive than a [[subroutine]] call.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)