Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign up为什么说linux系统相对其他系统,上下文切换时间短? #467
Comments
|
好想知道你在哪里看到的,上下文切换在相同的design和algorithm下难道不是拼硬件么? |
|
|
找到了以下三段话。问题应该在于多线程的实现不同。Unix-like是kernel-based process, 不共享内存;而Linux使用clone,共享内存空间。这意味着在context switch的时候减少了内存置换。 Context Switching leads to an overhead cost because of TLB flushes, sharing the cache between multiple tasks, running the task scheduler etc. Context switching between two threads of the same process is faster than between two different processes as threads have the same virtual memory maps. Because of this TLB flushing is not required. While many Unix-Like OS use kernel threads for process context switching, Linux uses kernel threads only for executing some kernel code periodically. Most of the UNIX-like operating systems LWP (read light weight process) are kernel thread based, while on the other hand Linux handles them a bit differently. In linux, LWP are created by calling the clone() function which leads to creation of separate processes. Same task can also be carried out with fork() function but clone() lets recently created processes share their memory, address space etc. Their working in shared environment gave them a name “threads”. Hence, multi-threading is supported by both of them but they differ in internal handling of it. |


为什么说linux系统相对其他系统,上下文切换时间短?