Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel.

Similar presentations


Presentation on theme: "Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel."— Presentation transcript:

1 Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel Memory Other Considerations Operating-System Examples

2 Memory Hierarchy of a Modern Computer System Take advantage of the principle of locality to –Present as much memory as in the cheapest technology –Provide access at speed offered by the fastest technology On-Chip Cache Registers Control Datapath Secondary Storage (Disk) Processor Main Memory (DRAM) Second Level Cache (SRAM) 1 10,000,000 Speed (ns):10-100100 GSize (bytes):K-MM Tertiary Storage (Tape) 10,000,000,000 T

3 Demand Paging Modern programs require a lot of physical memory But they don’t use all their memory all of the time –90-10 rule: programs spend 90% of their time in 10% of their code –Wasteful to require all of user’s code to be in memory Solution: use main memory as cache for disk

4 Virtual Memory Requirement that instructions be in physical memory to be executed seems both necessary and reasonable However, this is also unfortunate, since it limits the size of a program to the size of physical memory Virtual memory strategies allow a process to use the CPU when only part of its address space is loaded in the primary memory Only part of the program needs to be in memory for execution Logical address space can therefore be much larger than physical address space Virtual memory can be implemented via –Demand paging –Demand segmentation

5 Virtual Memory The ability to execute a program that is only partially in memory has many benefits –Program is no longer constrained by amount of physical memory that is available. Users can write programs for an extremely large virtual address space, simplifying the programming task –Because each user could take less physical memory, more programs can be run at the same time, thus increasing CPU utilization and throughput –Less I/O needed to load or swap each user program into memory

6 Virtual Memory

7 Virtual-address Space

8 Demand Paging Bring a page into memory only when it is needed –Less I/O needed –Less memory needed –More users Page is needed  reference to it –invalid reference  abort –not-in-memory  bring to memory

9 Valid-Invalid Bit With each page table entry a valid–invalid bit is associated –1  in-memory –0  not-in-memory Initially valid–invalid bit is set to 0 on all entries Example of a page table snapshot During address translation, if valid–invalid bit in page table entry is 0  page fault 1 1 1 1 0 0 0  Frame #valid-invalid bit page table

10 Valid-Invalid Bit

11 Page Fault If we guess right and page in all and only those pages that are actually needed, the process will run exactly as though we had brought in all pages While the process executes and accesses pages that are memory resident, execution proceeds normally But what happens if the process tries to access a page that was not brought into memory? –Access to a page marked invalid in the page table causes a page-fault trap

12 Page Fault OS looks at another table to decide –Invalid reference  abort –Just not in memory Get empty frame Swap page into frame Reset tables, validation bit = 1 Restart instruction

13 Steps in Handling a Page Fault

14 Performance of Demand Paging Page Fault Rate 0  p  1 –if p = 0 no page faults –if p = 1, every reference is a fault Effective Access Time (EAT) EAT = (1 – p) memory access time + p (page fault overhead + [swap page out] + swap page in + restart overhead) page fault time

15 Demand Paging Example Memory access time = 200 nanoseconds Average page-fault service time = 8 milliseconds EAT = (1 – p) x 200 + p (8 milliseconds) = (1 – p x 200 + p x 8,000,000 = 200 + p x 7,999,800 If one access out of 1,000 causes a page fault, then EAT = 8.2 microseconds. This is a slowdown by a factor of 40!!

16 Demand Paging Algorithms Two basic types of demand paging algorithms –A static demand paging algorithm allocates a fixed number of page frames to a process when it is created. Thus, a process is allocated a fixed amount of memory when it is started and it is assumed that the amount needed does not change during the computation –Thus, memory allocation is not adjusted, even if the process passes through phases in which it requires a large physical address space or its memory requirements are modest –A dynamic demand paging algorithm adjusts the memory allocation to match the process’s needs as they change –We are going to look at static demand paging algorithms first

17 Page Replacement The replacement policy determines which page should be removed from primary memory if all page frames are full Use modify (dirty) bit to reduce overhead of page transfers – only modified pages are written to disk Page replacement completes separation between logical memory and physical memory – large virtual memory can be provided on a smaller physical memory

18 Basic Page Replacement 1.Find the location of the desired page on disk 2.Find a free frame 1.If there is a free frame, use it 2.If there is no free frame, use a page replacement algorithm to select a victim frame 3.Read the desired page into the (newly) free frame. Update the page and frame tables 4.Restart the process

19 Page Replacement

20 Process Creation Virtual memory allows other benefits during process creation: - Copy-on-Write - Memory-Mapped Files (later)

21 Copy-on-Write Copy-on-Write (COW) allows both parent and child processes to initially share the same pages in memory If either process modifies a shared page, only then is the page copied COW allows more efficient process creation as only modified pages are copied Free pages are allocated from a pool of zeroed- out pages

22 Before Process 1 Modifies Page C

23 After Process 1 Modifies Page C


Download ppt "Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel."

Similar presentations


Ads by Google