Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is no virtual memory separate from physical memory. All reads and writes to memory must go to physical memory.</p> <p>Here is how virtual memory typically works in hardware:</p> <ul> <li>When a load or store instruction is executed, the processor first calculates the address in the virtual memory address space. (This often involves adding together the contents of processor registers and/or values encoded into the instruction itself.)</li> <li>Then the processor looks up the virtual address in tables it has. These are tables that describe the translation from virtual memory to physical memory.</li> <li>If the processor finds a match for the virtual address, it uses data in the matching table entry to change the virtual address into a physical address. (Usually, the high bits of a virtual address are a key to the table and the low bits are an offset within a page. To form the physical address, new high bits are taken from the table entry, and the same low bits are used.)</li> <li>Then the processor performs the load or store operation using the calculated physical address.</li> </ul> <p>If a virtual address is not found in the tables the processor has in its special registers, then one of several things may happen:</p> <ul> <li>Some processor models search special tables in memory (which are created and maintained by the operating system) for additional information about maps from virtual memory to physical memory.</li> <li>If the processor cannot do the above or does do a search but fails to find a match, it generates an exception. An exception stops the current program, makes some special changes inside the processor, and starts executing part of the operating system instead of the user program.</li> <li>The operating system examines the cause of the exception and decides what to do.</li> </ul> <p>The operating system typically does one of several things:</p> <ul> <li>If the reason for the exception is just that the processor did not have the appropriate table entries for the particular address the process tried to access, but that address is part of the process’ virtual address space as established by the operating system, then the operating system loads the appropriate data into the processor and resumes execution of the process.</li> <li>If the user process tried to access memory that was in its virtual address space but currently did not have a physical address, then the operating system allocates new physical memory for the process, sets up the tables to describe the new map from that part of virtual address space to the allocated physical memory, and resumes execution of the user process. (This allocation of new physical memory might involve deallocating other physical memory. Sometimes that can be done simply by unmapping pages that have not been used in a while and erasing their contents [for security]. Sometimes it requires writing the contents of pages to disk, to save them for later when they are needed again.)</li> <li>If the user process tried to access memory that was not in its virtual address space (of course, the numbers are in the space, but there might have been no allocation of virtual memory to that portion of the address space), then the system sends the process a signal, causing it to execute a signal handler for the error. If the process has no signal handler for this problem, the operating system will terminate the process.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload