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
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?
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)
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
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
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
Frame-allocation algorithm determines :
Page-replacement algorithm
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)
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
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:
WSSi(working set of Process Pi ) = total number of pages referenced in the most recent Working-Set (varies in time)