Virtual Memory Flashcards
(42 cards)
Virtual Memory
A memory management method where computers use secondary memory to compensate for the scarcity of physical memory
Methods of handling Virtual Memory
- Paging
- Segmentation
Paging
1- Divide physical memory into fixed-sized blocks called frames where Size
is power of 2, between 512 bytes and 16 Mbytes
2- Divide logical memory into blocks of same size called pages
3- To run a program of size N pages, need to find N free frames and load program
4- Set up a page table to translate logical to physical addresses
5- Still have Internal fragmentation
Address generated by CPU is divided into?
- Page number (p) – used as an index into a page table which contains base address of each page in physical memory
- Page offset (d) – combined with base address to define the physical memory address that is sent to the memory unit
page number page offset
—————
|p | d|
—————
m -n n
For given logical address space 2^m and page size 2^n
Suppose that VA i = 3257, and Page size c is 100, find:
-Page number
-Line # (Offset)
- Page number:
└ i/c (p) ┘-> └ 3257/100 ┘= 32 - Line # (Offset): i/c = 3257%100 = 57
map 32 to the frame # and add 57 to get physical address
Estimate Internal Fragmentation if:
- Page size = 2,048 bytes
- Process size = 72,766 bytes
- 35 pages + 1,086 bytes
- Internal fragmentation of 2,048 - 1,086 = 962 bytes
What is the worst case fragmentation
1 frame – 1 byte
On average fragmentation = XX of frame size?
1 / 2
If (only) 32 bits are used with 4KB pages, a page table may have?
2^20 entries
Page Fault
If we try to address a virtual address that is not in the RAM
Page fault handling process
- Page Fault Trap: The CPU detects a page fault while trying to access a memory page that isn’t currently in RAM. This triggers a page fault exception, which transfers control to the operating system.
- Page Table Lookup: The operating system looks up the page table to determine the location of the required page in secondary storage, such as a disk.
-Fetch Page from Secondary Storage: The OS initiates a process to fetch the required page from secondary storage into an available page frame in RAM. This involves reading the page data from disk into a free page frame.
-Update Page Table: Once the page is successfully brought into RAM, the operating system updates the page table to reflect the new location of the page in physical memory. This includes updating the page table entry with the physical address of the page frame where the page now resides.
-Resume Process Execution: Finally, the operating system restarts the interrupted memory access instruction that caused the page fault. With the required page now available in RAM, the process can proceed as expected, accessing the data it needs from memory.
Demand Paging
A process in which data is moved from secondary memory to RAM on a demand basis
Page Replacement
Prevent over-allocation of memory by modifying page-fault service routine to include page replacement
How does page replacement reduce soverhead of page transfers
Use modify (dirty) bit to reduce overhead of page transfers – only modified pages are written to disk
Basic Page Replacement steps
- Find the location of the desired page on disk.
- Find a free frame:
- If there is a free frame, use it
- If there is no free frame, use a page replacement algorithm to select a victim frame
- Write victim frame to disk if dirty - Bring the desired page into the (newly) free frame; update the page and frame tables
- Continue the process by restarting the instruction that caused the trap
Frame-allocation algorithm determines :
- How many frames to give each process
- Which frames to replace
Page-replacement algorithm
- Want lowest page-fault rate on both first access and re-access
Static paging
Allocate fixed number of frames to the process
* Use these frames as long they are free
* If no free frame, then select a victim page and swap
* Page reference stream:
ω = r1, r4, r8, r6, r4, …..
* Let St (m) is the set of pages loaded in the m frames of memory at virtual time t
* St(m) = St-1(m) Ս Xt- Yt
Belady’s Optimal Algorithm (OPT)
- Replace page that will not be used for longest period of time
Least Recently Used (LRU) Algorithm
*Use past knowledge rather than future
* Replace page that has not been used in the most amount of time
* Associate time of last use with each page
Stack Algorithm
- An algorithm is considered as a stack algorithm iff it keeps all pages with smaller number of allocated frames when it gets more frames allocated
- LRU and OPT are cases of stack algorithms that don’t have Belady’s Anomaly
- Use Of A Stack to Record Most Recent Page References
First-In-First-Out (FIFO) Algorithm
The operating system keeps track of all pages in the memory in a queue, the oldest page is in the front of the queue. When a page needs to be replaced page in the front of the queue is selected for removal
Working-Set:
- working-set window = a fixed number of page references
Example: 10,000 instructions
WSSi(working set of Process Pi ) = total number of pages referenced in the most recent Working-Set (varies in time)
- if Working-Set too small will not encompass entire locality
- if Working-Set too large will encompass several localities
- if Working-Set =inf –> will encompass entire program