How does the system select the correct page table?

Focus on single-processor computer systems. When the process is created, as far as I know, a page table is configured that maps virtual addresses to the address space of physical memory. Each process gets its own page table stored in the kernel address space. But how does the MMU select the right page of the table for the process, since not only one process is running, and there will be many context switches?

Any help is appreciated!

Best, Simon

+6
source share
2 answers

Processors have a privileged register called the base page table register (PTBR), on x86 it has CR3 . When switching context, the OS changes the PTBR value so that the processor now knows which page table to use. In addition to PTBR, many modern processors have the concept of an address space number (ASN). Processes are assigned an address space number (from a restricted pool), and this ASN is also set in a register in the context switch. This ASN is used as part of the TLB mapping and allows the use of TLB entries from multiple address spaces. Only when reusing the ASN is it necessary to clear the TLB, and then only for entries matching the ASN. Most x86 implementations are rougher than this, and there is the concept of global pages (for shared libraries and shared data).

+13
source

MMU in this case does not completely know what a process is. An operating system that tracks process processes generates a page table for each process, as you say, as they are created. The context switching process is as follows:

  • The operating system tells MMU to use the page table located at the physical address 0xFOO

  • The operating system programs a programmable interrupt timer (PIT) to trigger a hardware interrupt after milliseconds of BAR.

  • The operating system restores the state of the process (processor registers, program counter, etc.) and jumps to the correct address.

  • The process starts until the PIT causes an interrupt.

  • The operating system procedure for handling the PIT interrupt then saves the program state (registers, etc.), uses the scheduling algorithm to determine the next process to start (in the simple case, a circular linked list), then it starts in step 1.

Hope this resolves any doubts that may arise. Short answer: MMU is an agnostic process and does not know what a process is.

+2
source

Source: https://habr.com/ru/post/917358/


All Articles