1
$\begingroup$

Imagine we are running a program on a modern operating system, such as Linux or Windows. After running for some time, the program's time slice is up. A different program (process) starts to run again. That is, we have had a context switch. During a context switch, does the MMU have to be updated?

Maybe what I am really asking is, is the virtual page table in the MMU apply to every process or just the process that is currently running.

$\endgroup$

1 Answer 1

0
$\begingroup$

Sorry for the late answer. The Memory Management Unit doesn't hold page tables. It holds a TLB (Translation Lookaside Buffer). The TLB holds translations of virtual addresses to physical addresses that were done recently. It isn't managed by the OS (like any cache) but can be flushed by loading the CR3 register on x86.

I don't know if you are familiar with x86. The x86 computers have timers that throw interrupts. When a timer interrupt happens, the OS will give a time slice to another process and reschedule the timer. To change process, the OS will change the CR3 register to point to a new PML4 (first level of page table on x86-64). When it does that, the TLB is flushed by the processor. It thus allows to remain consistent.

Every core of the processor runs only one process/thread and, yes, every core has its own CR3 register. When the context switch occurs, the new process has its own page tables and they are swapped simply by reloading CR3. The page tables are stored in RAM and managed by the OS.

Hope this clears any misconceptions you have.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.