The valid bit is used to keep track of whether the page is in or out of main memory. If the valid bit is off, then this page is not in main memory, and a page fault occurs. We now know that that page resides on disk and it will need to be swapped in.
Virtual memory can also have a twolevel page table. The first-level page table is always present, while the second- level page table is allocated on demand. There are more bits in a second- level page table to describe its properties. A few of these properties are as follows:
- The read and write permission bit tells the software developer whether the page is readable or writable, respectively.
- The execution bit indicates whether the page is executable.
- The modified bit, which is set to true, indicates that the page has been modified since the last time the bit was cleared.
The above page table manipulations begin with the CPU providing a virtual address. The Memory Management Unit (MMU) then converts this address to a physical address which is then used to access main memory. How is this accomplished? Given a virtual address, a certain number of bits, known as the virtual page number, are used as an index to access the page table, whose corresponding entry contains the physical page number. The rest of the bits of the virtual address, known as the page offset, are appended to the physical page number to form the physical address.
In an OS, each process has its own virtual address space. A virtual address space is a set of all virtual addresses. Notice in Figure 2 that the virtual addresses are mapped onto different physical addresses, which simplifies loading the program for execution. This is known as "relocation" and is one of the advantages of virtual memory. Before the concept of virtual memory came into existence, software developers had to divide programs into overlays. Overlays were mutually exclusive pieces of programs that had to be loaded and unloaded into memory under user program control. As one would imagine, this was a huge responsibility for programmers. Each overlay consisted of its own instructions and data.