Home > Archive > Unix Programming > August 2005 > context switching
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Roman Mashak 2005-08-19, 4:18 pm |
| Hello, All!
I wonder why is context switching operation is considered to be heavy?
Please, recommend a good resource explaning this.
Thanks.
With best regards, Roman Mashak. E-mail: mrv@tusur.ru
| |
| vindhya 2005-08-19, 4:18 pm |
|
Roman Mashak wrote:
> Hello, All!
>
> I wonder why is context switching operation is considered to be heavy?
> Please, recommend a good resource explaning this.
> Thanks.
>
> With best regards, Roman Mashak. E-mail: mrv@tusur.ru
Every process created has its own stack space. During context switching
CPU is passed from one process to another. Now if you have multiple
processes running and OS wants to do context switching then the stack
space allotted for running process is backed up and put to sleep or
whatever(whch doesnt require utilization of CPU). The fresh stack is
loaded for the new process. Hence it is considered as heavy.
In contrast threads spawned from same parent use same memory space so
thread switching doesnt require the storage of stack for each thread
when switching or pre-emption happens. Hence it is called light weight.
| |
| Måns Rullgård 2005-08-19, 4:18 pm |
| "vindhya" <manish.sing@gmail.com> writes:
> Roman Mashak wrote:
>
> Every process created has its own stack space. During context switching
> CPU is passed from one process to another. Now if you have multiple
> processes running and OS wants to do context switching then the stack
> space allotted for running process is backed up and put to sleep or
> whatever(whch doesnt require utilization of CPU). The fresh stack is
> loaded for the new process. Hence it is considered as heavy.
The stack is not copied. The expensive part of a context switch is
the memory map replacing, and the cache and TLB misses that follow.
The content of the registers is also swapped, but that is a lot
cheaper. Switching between threads is usually cheaper, since they
have the same memory map, and only the registers need to be updated.
--
Måns Rullgård
mru@inprovide.com
| |
| Ulrich Hobelmann 2005-08-19, 4:18 pm |
| Måns Rullgård wrote:
> The stack is not copied. The expensive part of a context switch is
> the memory map replacing, and the cache and TLB misses that follow.
I think the cost is mostly the TLB being replaced. Most modern
architectures cache physical memory, not virtual mem, so even after
context switching the cache could remain intact, if the cache can hold
several processes' working set at once.
> The content of the registers is also swapped, but that is a lot
> cheaper. Switching between threads is usually cheaper, since they
> have the same memory map, and only the registers need to be updated.
Yep.
--
I believe in Karma. That means I can do bad things to people
all day long and I assume they deserve it.
Dogbert
|
|
|
|
|