Week 7 Flashcards
Suppose we have the following.
010101
What is the virtual address?
What is the virtual page number?
What is the offset?
Virtual Address: 21
Virtual page number: 1
Offset: 5
What are the steps for converting a virtual address into a physical address?
- Encode the physical frame number
- Encode the physical page offset
How does the OS find a free page?
One option is to keep a free list of available pages.
Because the pages are all the same size, the OS can just grab the first page in the list.
How does the OS keep track of which process is using which physical page?
Using a per process data structure called a page table.
What are some pros of paging?
We don’t have to allocate a physical page for all virtual pages in the address space. (use a valid bit to keep track)
We can use protection bits to mark pages as readable, writeable or executable.
We can swap pages from memory to disk and back again, allowing us to support address spaces larger than physical memory.
Different processes can share pages.
What is a linear page table?
Each row in this table is a page table entry describing the mapping for a single page.
Each page table entry stores the information necessary for translation: physical frame number, protection bits, present bit, valid bit, etc.
What are some cons of paging?
Memory waste. Hundreds of MBs across all processes. We need to put this information in memory.
More memory accesses. Translation is slow. Hardware must look up the correct page table entry before it can translate a virtual address.
Complexity. Swapping pages in and out means more complexity and performance challenges.
PAGING PRACTICE
Assume we are given a virtual address. How do we calculate the cirtual page number?
Zero out everything but the VPN bits using a logical & operation with a bit mask.
Use a shift to move the VPN over
VPN = (VirtualAddress & VPN_MASK) >> SHIFT
PAGING PRACTICE
How do we calculate offset?
Mask out everything but the offset bits
Offset = VirtualAddress & OFFSET_MASK
How do we find the correct page table entry in a linear page table?
First we find the page table index. This is the same as the virtual page number.
Second we account for the page table entry size and where the page table starts in memory. The page table base register (PTBR) stores the base address of the page table.
PTE_Addr = (VPN * sizeof(PTE) + PTBR
PAGING PRACTICE
How do we check for error conditions?
Raise segmentation fault if PTE is not valid.
~~~
PTE.Valid == False
~~~
Raise protection fault if memory access violates protection bits
~~~
CanAccess(PTE.ProtectBits) == False
~~~
PAGING PRACTICE
How can we calculate the physical address now that we know the physical page number?
PhysAddr = (PTE.PFN << PFN_SHIFT) | Offset
What is the approach for TLBs?
Cache recent translations in the translation look aside buffer (TLB) to avoid costly accesses to the page table.
The TLB stores VPN | PFN | other bits
What happens on a TLB hit?
Fast if the TLB already has the translation for the virtual page number, we can directly access the physical memory.
Who handles the TLB miss?
Hardware managed. Requires knowledge of page table location and the format of the page table entries.
software (OS) managed: hardware jumps to a trap handler and the OS handles the TLB miss, updating the TLB. (more flexible than just using software).