0
votes

I think I'm missing a fundamental concept of how the OS manages memory.

  • OS is responsible for keeping track of what parts of physical memory are free.
  • OS creates and manages page tables, which have mappings between virtual to physical addresses.
  • For each instruction that specifies a virtual address, the hardware reads the page table to get the corresponding physical address. One way the hardware may know the location of the current page table is by a register that the OS updates.

This makes sense for how processes access memory. However, I don't understand how the OS itself accesses memory.

Assuming it uses the same instructions, the hardware would still be translating from virtual addresses to physical? Is there, for example, a known physical location for a page table for the OS itself? I know the question is murky, having trouble even understanding what to ask.

2
"Assuming it uses the same instructions, the hardware would still be translating from virtual addresses to physical?" yes. "Is there, for example, a known physical location for a page table for the OS itself?" yes.Alex Hoppus

2 Answers

1
votes

At some point there has to be a page table in a physical location. The method used for this depends upon the processor.

Let me give a simple example based upon the VAX processor. Suppose you divide the logical address space into a system range shared by all processes and a user range that is unique to each process. Then give each of those ranges its own page table.

Now you can place the user page table in the system address range of the logical address space.

If you access memory in the user space, you go to page table that the system finds at a logical address in the system space, that the processor then had to translate into a physical address using the page table for the system space; a two level translation.

If you use logical addresses for the the system space page table then you'd have no way of translating those into physical addresses. Instead, the local of the system page table is defined using physical addresses.

Another approach would be to define all page tables using physical addresses.

0
votes

I don't understand how the OS itself accesses memory.

Think of the operating system as a process. The OS basically is a process, just like other processes, with elevated privileges. Whenever the OS wants to use eome memory location,it uses page tables for virtual to physical address translation, just like other processes would.

Think of it this way: Every process has a page table of its own, the same goes for the OS. The OS remembers the location of these page tables in the control structures associated with each process (e.g. the PCB), and for the currently running process the address (physical pointer) to the page table is kept in hardware (for the x86 architecture this is in control register 4 (CR4)). On x86, whenever the OS switches the running process it changes the value in CR4 so that the address points to the correct page table (its own if it switches to itself).

However, this is greatly simplified in modern operating systems, where the kernel (the OS) is mapped into the memory space of all processes, so that the kernel can run whenever it wants without having to switch page tables (which is costly). The pages in a process' page table belonging to the kernel are restricted to the process, and only accessible once the kernel takes control to do some management task.