Process switching in two steps 1. Switch the page directory to use the new address space
2. Switch between the kernel stack and the hardware context.
For Linux, the most important difference between threads and processes is the address space.
For thread switching, the 1th step is not required, and the 2nd is the process and thread switching. So obviously process switching costs a lot
One of the main differences between thread context switching and process context switching is that the switching of virtual memory space for threads is still the same, but process switching is different. The processing of both context switches is done through the operating system kernel. The most significant performance loss associated with this switching process of the kernel is to switch the contents of the register out.
Another hidden loss is that context switching disrupts the processor's caching mechanism. Simply put, once the context is switched, all memory addresses that have been cached in the processor are invalidated for a moment. Another notable difference is that when you change the virtual memory space, the processed page table buffers (processor ' s translation lookaside buffer (TLB)) or the equivalent of the God horse thing will be all refreshed, This will cause memory access to be quite inefficient over time. However, this problem does not occur during thread switching.