Presentation on theme: "Virtual Memory Why? The need of memory more than the available physical memory. Process 1 Process 3 Process 4 Process 2 Physical Memory."— Presentation transcript:
Virtual Memory Why? The need of memory more than the available physical memory. Process 1 Process 3 Process 4 Process 2 Physical Memory
Memory Limits for Windows Releases http://msdn.microsoft.com/en-us/library/windows/desktop/aa366778(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/windows/desktop/aa366778(v=vs.85).aspx
Max. memory per a process http://msdn.microsoft.com/en-us/library/windows/desktop/aa366778(v=vs.85).aspx#memory_limits
Max. memory per a VM (.NET or Java) Max. memory per a single object max 2GB (.NET) 32-bit 64-bit version object Array 2GB With.NET 4.5, 10 years memory limit of 2 GB is over Java.NET memory limit virtual machine limit C/C++ system call
No corresponding physical memory Virtual memory (a process) code data heap stack Virtual Memory pp. 359 As stack and heap grow, more pages will be allocated and mapped to physical memory.
Demand Paging Demand paging = lazy swapping pp. 361 The OS only swaps a page into memory when it is required by a process Swap-in algorithm swap-in (memory ) swap-out lazy intelligent speculative
Page Fault pp. 363 Locality of Reference memory access random page virtual memory
Copy-on-Write pp. 368 Make another copy of page C when a process writes. After forking. Parent and child share the same copy.
Demand paging requires 1) frame-allocation algorithm 2) page-replacement algorithm Reference string To know the number of page faults, you need to know the number of max frames. max. frame per process page victim page fault maximum frame max = 2 page fault, max = 3
load M executable code 2 frame frame M
Max. frame per process Frequency page fault
Page Replacement Algo. (summary) 1)FIFO page replacement - Beladys anomaly 2)Optimal page replacement - Replace the page that will not be used for the longest period of time. - Similar to SJF, requiring future knowledge. 3)Least-recently-used (LRU) page replacement - Counter, equip a counter for each entry in page table - Stack, move the referenced page to TOS 4)LRU-approximation page replacement - Additional-reference-bits algorithm - Second-chance algorithm - Enhanced second-chance algorithm
5)Counting-based page replacement - Least frequently used (LFU) page-replacement algorithm - Most frequently used (MFU) page-replacement algorithm 6)Page-buffering algorithms ( ) Page Replacement (cont.) A process Max. #frames = 3 Pool of free frames HD frame Step 1 Step 2 Delay writing out or do it when CPU is idle. Increase response time. not recently as the previous Page fault, not choose a victim, borrow a frame
Beladys anomaly (undesired characteristics)
Using frame number n if n is in stack move n to TOS else push n
LSB Additional-reference-bits algorithm MSB 0 Each page has a corresponding 8-bit register. If the page is accessed, MSB is set to 1. Every 100 ms, shift-right (÷2) all registers. The page with the lowest number is the LRU page. Shift right (less registers than counter) ( 100ms ) 8 counter page A10000000 10000000 …. 01000000 page B00000000 10000000 …. 01000000 Page A is older but as time passed no difference between A and B. access A access B 100ms Example 1000 0000 100ms 0100 0000 100ms 0010 0000 access 1010 0000 100ms 0101 0000 Counting is more expensive then shifting access A access B
FIFO + Second Chance ReferencedSet ref. bit to 1 1Give the second chance, clear 0Replace Step 1. FIFO 2. ref bit = 0, victim ref bit = 1, clear 3. ( second chance ) 4. victim new page victim FIFO If a page is used often enough to keep its reference bit set, it will never been replaced. Advance pointer and clear reference bits Current pointer Victim Clear Load new page, set ref bit to 1 move to the end of Q
Enhanced second-chance algorithm (modify bit) modify bit 0 = not modified 1 = modified (0, 0)neither recently used nor modified – best page to replace (0, 1)not recently used but modified – not quite as good and need writing disk (1, 0)recently used but clean – probably will be used again soon (1, 1)recently used and modified – used again soon and need writing disk last choice first choice We may have to scan the circular queue several times. The major diff. with second chance algo. is the preference to reduce I/O traffic.
Allocation of Frames 1)Minimum number of frames - Instruction set architecture: add a1 a2 a3min = 3 ld r1 a4min = 1 2)Allocation algorithms - Equal allocation process - Proportional allocation memory process
Global vs. Local allocation 1)Local allocation - a process uses max frames. - when requesting a free frame, choose a victim from its own set of allocated frame. 2)Global allocation - choose a victim from the set of all frames, even if that frame is currently allocated to some other process.
Thrashing Definition: high paging activity. #process ready queue 1 process CPU idle I/O process execute process frame OS predict thrashing degree of multiprogramming predict working set model
Working-Set Model Working set = set of pages in the most recent page references. Demand P1 WSS = 8, P2 WSS = 6 = 8 + 6 =14 demand > supply (allocated frames) frame process (equal or proportional) frame degree of multiprogramming process ready queue
Working sets and page fault rates working set page fault process working set page fault working set frame transition working set working process 1 1 2 1 3 1 2 3 1 2 3 2 1 2 3 2 1 4 5 4 6 5 5 6 6 4 5 4 4 4
Homework Page faults / sec time 1.Thrashing or 2.Moving from a working set to another working set ? Hint: ? assume page fault rate t 2 t1t1 t2t2 page fault