How to use the virtual memory address translation calculator
- Choose the page size and enter the virtual address width in bits.
- Enter the page table, one mapped page per line: page number, a colon and frame number. Decimal numbers and 0x hexadecimal both work.
- Enter the virtual addresses to translate, one per line.
- Read, for each address, the page number, the offset, the frame and the physical address, or a page fault when the page is not in the table.
Formula
Offset bits = log2(page size). Page number = virtual address shifted right by the offset bits.
Offset = the low offset bits of the virtual address
Physical address = (frame number shifted left by the offset bits) combined with the offset
A page that is not in the page table causes a page fault
The page table maps whole pages, so the offset is copied unchanged from the virtual address to the physical address.
4 KiB pages and the address 0x12345
With 4 KiB pages the offset takes 12 bits and a 32-bit address has 20 bits of page number, so the address space has 1,048,576 pages. The address 0x12345 has page number 0x12 and offset 0x345. If page 0x12 is in frame 0x7, the physical address is 0x7345.
The address 0x13FFF is page 0x13 with offset 0xFFF, and in frame 0x2 it becomes 0x2FFF. The address 0x15000 is page 0x15, which is not in the table, so it causes a page fault. With 1 KiB pages and 16-bit addresses, the decimal address 1500 is page 1 with offset 476, and if page 1 is in frame 0 the physical address is 0x1DC.
What the numbers mean
Virtual memory gives each program its own address space, split into pages of equal size. The operating system keeps a page table that records which frame of real memory holds each page, and the hardware translates every address on the fly. A page that is not in memory causes a fault, and the system loads it from disk before the access can finish.
Caches work with addresses in a similar way. See the cache replacement policy simulator and the binary calculator for converting addresses between bases. For byte order in memory, use the byte order swap calculator.
What is simplified
Real systems use several levels of page tables, a translation buffer to speed up lookups, and permission bits for reading, writing and running code. The page models a single flat table to show the core idea. Check that the page numbers in your table fit in the address width, which the page does for you, since a page number needs address width minus offset bits.
To see how the processor is shared among programs, try the CPU scheduling simulator.
Assumptions and limits
- One level of translation with a flat page table and a power of 2 page size.
- Addresses are decimal or 0x hexadecimal, and fit in the address width you give.
- A page missing from the table is a fault. Permissions and a translation buffer are not modeled.
- The page allows up to 200 addresses at a time.
Frequently asked questions
How do I split a virtual address?
The low bits, as many as log2 of the page size, are the offset. The remaining high bits are the page number.
How do I find the physical address?
Look up the page number in the page table to get a frame number, then put the offset after the frame number.
What is a page fault?
It happens when the page is not in physical memory. The system must bring it in before the program can continue.
Why do page sizes have to be a power of 2?
So the offset is a whole number of bits and the translation is just bit shifting and masking.