1 Virtual Memory vs. Physical Memory So far, all of a job’s virtual address space must be in physical memory However, many parts of programs are never.

Slides:



Advertisements
Similar presentations
Chapter 4 Memory Management Basic memory management Swapping
Advertisements

Virtual Memory (Chapter 4.3)
Module 10: Virtual Memory
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Page Replacement Algorithms
Paging: Design Issues. Readings r Silbershatz et al: ,
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
Virtual Memory Operating System Concepts chapter 9 CS 355
Virtual Memory. 2 What is virtual memory? Each process has illusion of large address space –2 32 for 32-bit addressing However, physical memory is much.
Page 15/4/2015 CSE 30341: Operating Systems Principles Allocation of Frames  How should the OS distribute the frames among the various processes?  Each.
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
9.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory OSC: Chapter 9. Demand Paging Copy-on-Write Page Replacement.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
Module 9: Virtual Memory
Module 10: Virtual Memory Background Demand Paging Performance of Demand Paging Page Replacement Page-Replacement Algorithms Allocation of Frames Thrashing.
Virtual Memory Background Demand Paging Performance of Demand Paging
Virtual Memory Introduction to Operating Systems: Module 9.
Segmentation and Paging Considerations
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Virtual Memory.
Operating System Support Focus on Architecture
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 9: Virtual Memory Background.
Chapter 10: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 10: Virtual Memory.
Virtual Memory and Paging J. Nelson Amaral. Large Data Sets Size of address space: – 32-bit machines: 2 32 = 4 GB – 64-bit machines: 2 64 = a huge number.
Computer Organization and Architecture
Virtual Memory CSCI 444/544 Operating Systems Fall 2008.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
Memory Management 2 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
Layers and Views of a Computer System Operating System Services Program creation Program execution Access to I/O devices Controlled access to files System.
Operating Systems ECE344 Ding Yuan Page Replacement Lecture 9: Page Replacement.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Virtual Memory.
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
Page 19/17/2015 CSE 30341: Operating Systems Principles Optimal Algorithm  Replace page that will not be used for longest period of time  Used for measuring.
Review of Memory Management, Virtual Memory CS448.
Chapter 5 Operating System Support. Outline Operating system - Objective and function - types of OS Scheduling - Long term scheduling - Medium term scheduling.
Lecture Topics: 11/17 Page tables TLBs Virtual memory flat page tables
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory.
Operating Systems CMPSC 473 Virtual Memory Management (3) November – Lecture 20 Instructor: Bhuvan Urgaonkar.
Demand Paged Virtual Memory Andy Wang Operating Systems COP 4610 / CGS 5765.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Page Replacement Allocation of.
Virtual Memory. Background Virtual memory is a technique that allows execution of processes that may not be completely in the physical memory. Virtual.
Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 9: Virtual Memory.
Virtual Memory The memory space of a process is normally divided into blocks that are either pages or segments. Virtual memory management takes.
Lecture Topics: 11/24 Sharing Pages Demand Paging (and alternative) Page Replacement –optimal algorithm –implementable algorithms.
Silberschatz, Galvin and Gagne  Operating System Concepts Virtual Memory Virtual memory – separation of user logical memory from physical memory.
1 Virtual Memory. Cache memory: provides illusion of very high speed Virtual memory: provides illusion of very large size Main memory: reasonable cost,
NETW3005 Virtual Memory. Reading For this lecture, you should have read Chapter 9 (Sections 1-7). NETW3005 (Operating Systems) Lecture 08 - Virtual Memory2.
1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
Operating Systems ECE344 Ding Yuan Page Replacement Lecture 9: Page Replacement.
Virtual Memory. 2 Last Week Memory Management Increase degree of multiprogramming –Entire process needs to fit into memory Dynamic Linking and Loading.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Background Virtual memory – separation of user logical memory.
COS 318: Operating Systems Virtual Memory Paging.
SLC/VER1.0/OS CONCEPTS/OCT'99
Logistics Homework 5 will be out this evening, due 3:09pm 4/14
Operating Systems Virtual Memory Alok Kumar Jagadev.
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual-Memory Management
What Happens if There is no Free Frame?
5: Virtual Memory Background Demand Paging
Chapter 9: Virtual Memory
Demand Paged Virtual Memory
Chapter 9: Virtual Memory
Operating Systems CMPSC 473
Page Allocation and Replacement
Module 9: Virtual Memory
Virtual Memory.
CSE 542: Operating Systems
Presentation transcript:

1 Virtual Memory vs. Physical Memory So far, all of a job’s virtual address space must be in physical memory However, many parts of programs are never accessed –Unlikely error conditions –Wasted malloc/new –Large arrays Large startup cost on a context switch –Must load all of program into physical memory –Limits degree of multiprogramming

2 Demand Paging: Using Main Memory as a Cache for the Disk Allow Virtual Memory > Physical Memory –Many advantages Larger degree of multiprogramming Can write programs for large virtual memories –Ex: on Sparc, 32 bit virtual addresses Can use 4GB of virtual address space Physical memory typically MB Warning: needs to be implemented efficiently

3 Translating Virtual Addresses to Physical Addresses Modify page table –Add valid/invalid bit Program still generate virtual addresses –Now look up physical frame and check valid bit –If invalid (“page fault”) means 1 of 2 things Address is illegal => kill of thread Address is legal but on disk => get it.

4 What happens on a page fault? Trap to OS –Get a free physical frame (may need to reclaim) –If frame has been modified, schedule disk write –Invalidate that address space’s page table entry –Schedule disk read (note: takes long time) –Update this address space’s page table entry –Queue thread on disk queue –Context switch to new thread –(when disk read done move waiting thread to ready queue)

5 How does TLB affect things? First check in TLB If not there, trap to OS OS checks its page tables –If in memory, load page tables entry into TLB –If not in memory, page fault

6 One detail left out: transparency When faulting thread finally rescheduled: –must restart instruction Instruction has never completed –Hardware must save enough state What instruction was, complete state Same as info saved on regular context switch Hardware designers can make life difficult –Both CISC and RISC machines

7 Page Replacement – Choosing a page to evict 3 kinds of page faults –Compulsory – when first access –Capacity – just don’t have enough room –Conflict – due to no-optimal page replacement Only kind OS have impact on Need to choose some policy –Have as few page faults as possible

8 Replacement Policy 1: MIN Replace page fault that will be used furthest in the future –Analogous to Shortest Job First in scheduling Optimal but no way to implement Can’t predict reference patterns in general –Good for comparison

9 Replacement Policies 2 and 3 Random: –Simple to implement in hardware. –Doesn’t perform especially well FIFO –Replace oldest page –Fair – let every page live in memory for the same amount of time, then toss it. –As with scheduling, not a good policy – throws out heavily-used pages with same frequency as lightly- used pages

10 Page Replace 4: LRU (Least Recently Used) Approximation to MIN Throw out page that: –Has not been used for longest time Not identical to MIN (why?) How to implement?

11 LRU Approximations Too expensive to implement exact LRU –Require hardware support (unusual) Implement approximate LRU –Additional reference bits –Second chance –Enhanced second chance

12 Belady’s Anomoly Adding more physical frames better, right? Not necessarily –FIFO can be worse ! –LRU and MIN are always better, however Contents of memory with N frames is subset of contents of memory with N+1 frame

13 Advanced Paging Issues Swap Area Transparency Core Map Global vs. Local Replacement Thrashing Prepaging.

14 Swap Area “Swap Space” – special area on disk –Dedicated to holding an entire address space One swap file per address space –Limits size of virtual memory –Managed differently than rest of disk Know where data will go; can make disk access very fast

15 More on Transparency Executing an instruction has several steps –Instruction Fetch –Instruction Decode –Execute Page fault can happen at fetch or execute –So in general, just restart whole instruction Block copies are a problem, as is autoincrement

16 Recall: Core Map Maps physical frame to virtual page Very useful in page replacement –Just scan through each frame –Wouldn’t want to go through every single address space, because could be many –What about sharing? One physical frame can be used by several address spaces

17 Global vs. Local Replacement Should OS reclaim a)Most appropriate frame being used by the faulting address space? (“local replacement”) b)Most appropriate frame in memory? (“global replacement”) Better throughput with global replacement One hog can ruin everything, however.

18 Thrashing Pages replaced when still needed –Thread can spend more time page faulting than getting any useful work done Very common on timesharing systems –Ex: log more and more users into the system, eventually: total # of pages needed > total # of pages available Adding more processes can actually decrease CPU utilization Need to figure out needs of a process

19 Dealing with Thrashing Working Set (Denning, MIT, mid-60’s) –Informally, collection of pages process is using right now –Formally, set of pages job has referenced in last T seconds –How do we pick T? 1 page fault = 10 msec 10 msec = 2 million instruction –So T needs to be a lot bigger than 1 million instructions Approx. Impl: timer interrupt, reference bit

20 Working set (cont.) Balance set –OS monitors each process, allocates enough physical frame for each process If all fits? Done If not? Throw out fat cats. Bring them back eventually What if T is too big? –Waste memory; too few programs in memory What if T is too small? –thrashing

21 Other Paging Issues Prepaging –Bring in working set along with new process –Is it really worth it? Program structure –Writing stupid programs => slow execution –Dynamic data structures