Virtual Memory 1 Chapter 13. Virtual Memory Introduction Demand Paging Hardware Requirements 4.3 BSD Virtual Memory 4.3 BSD Memory Management Operations.

Slides:



Advertisements
Similar presentations
Tutorial 8 March 9, 2012 TA: Europa Shang
Advertisements

Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
CSCC69: Operating Systems
G Robert Grimm New York University Virtual Memory.
Paging 1 CS502 Spring 2006 Paging CS-502 Operating Systems.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
EECS 470 Virtual Memory Lecture 15. Why Use Virtual Memory? Decouples size of physical memory from programmer visible virtual memory Provides a convenient.
OS Fall’02 Virtual Memory Operating Systems Fall 2002.
Virtual Memory Chapter 18 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi.
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.
Memory Management (II)
Memory Management Policies: UNIX
Paging and Virtual Memory. Memory management: Review  Fixed partitioning, dynamic partitioning  Problems Internal/external fragmentation A process can.
Introduction to Kernel
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
Chapter 3.2 : Virtual Memory
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
Virtual Memory Management B.Ramamurthy. Paging (2) The relation between virtual addresses and physical memory addres- ses given by page table.
1 Virtual Memory Management B.Ramamurthy Chapter 10.
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
CSE451 Introduction to Operating Systems Spring 2007 Module 12 Memory Management Hardware Support Gary Kimura & Mark Zbikowski April 27, 2007.
Memory Management From Chapter 4, Modern Operating Systems, Andrew S. Tanenbaum.
Operating Systems Chapter 8
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
1 Memory Management 4.1 Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms 4.5 Modeling page replacement algorithms.
Chapter 4 Memory Management Virtual Memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory.
Memory Management Fundamentals Virtual Memory. Outline Introduction Motivation for virtual memory Paging – general concepts –Principle of locality, demand.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Page Replacement Allocation of.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 9: Virtual Memory.
Paging (continued) & Caching CS-3013 A-term Paging (continued) & Caching CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern.
Lecture Topics: 11/24 Sharing Pages Demand Paging (and alternative) Page Replacement –optimal algorithm –implementable algorithms.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Demand Paging.
Processes and Virtual Memory
Demand Paging Reference Reference on UNIX memory management
1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
COS 318: Operating Systems Virtual Memory Design Issues.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 4.
Virtual Memory 1 Computer Organization II © McQuain Virtual Memory Use main memory as a “cache” for secondary (disk) storage – Managed jointly.
CS203 – Advanced Computer Architecture Virtual Memory.
CS161 – Design and Architecture of Computer
Introduction to Kernel
Chapter 2: The Linux System Part 4
Memory Management Paging (continued) Segmentation
CS161 – Design and Architecture of Computer
Chapter 9: Virtual Memory
Structure of Processes
Chapter 9: Virtual-Memory Management
Page Replacement.
Memory Management Paging (continued) Segmentation
Main Memory Background Swapping Contiguous Allocation Paging
CSE 451: Operating Systems Autumn 2005 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 451: Operating Systems Autumn 2004 Page Tables, TLBs, and Other Pragmatics Hank Levy 1.
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Computer Architecture
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 451: Operating Systems Winter 2005 Page Tables, TLBs, and Other Pragmatics Steve Gribble 1.
Virtual Memory Lecture notes from MKP and S. Yalamanchili.
CSE 542: Operating Systems
Memory Management Paging (continued) Segmentation
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
Structure of Processes
CSE 542: Operating Systems
Presentation transcript:

Virtual Memory 1 Chapter 13. Virtual Memory Introduction Demand Paging Hardware Requirements 4.3 BSD Virtual Memory 4.3 BSD Memory Management Operations

Virtual Memory 2 Introduction Memory management unit (MMU) –Responsible for getting data to and from main memory Virtual memory –The notion of an address space as distinct from memory locations –Translation tables –Page-based

Virtual Memory 3 Introduction (cont) Memory management in the Stone Age –Software overlay –Swapping –Demand paging –Segmentation

Virtual Memory 4 Demand Paging Primary goal –To allow a process to run in a virtual address space –To perform translations from virtual to physical addresses transparently to the process Functional requirements –Address space management fork( ), exec( ) –Address translation Virtual address  Virtual page number + offset

Virtual Memory 5 Demand Paging (cont) –Physical memory management –Memory protection –Memory sharing –Monitoring system load –Other facilities Memory-mapped files Dynamically linked shared libraries etc.

Virtual Memory 6 Demand Paging (cont) executable file main memory swap area on disk text and initialized data uninitialized data pages zero-filled on first access stack and heap pages allocated on first access dirty pages saved initialized data subsequent faults on outswapped pages Page swapping

Virtual Memory 7 Demand Paging (cont) Translation maps hardware address translations address space map physical memory map backup store map process + virtual page number physical page number Data page fault

Virtual Memory 8 Demand Paging (cont) Page replacement policies –Local v.s. global replacement policy –Locality of reference –Concept of working set –Least recently used (LRU) policy

Virtual Memory 9 Hardware Requirements MMU –Translation of virtual addresses –Using page tables or TLBs Page table entry –Physical page frame number –Protection information –a valid bit –a modified bit –a referenced bit

Virtual Memory 10 Hardware Requirements (cont) Page table –Hardware-prescribed –Located in main memory –MMU uses only the active tables, whose locations are loaded in h/w page table registers –Typically, on a uniprocessor, there are two active page tables - one for kernel and one for the currently running process –Paging the page table to reduce the required memory

Virtual Memory 11 Hardware Requirements (cont) Address translation may fail for three reasons –Bounds error –Validation error –Protection error MMU caches –A high-speed cache that is searched before each memory access –Translation lookaside buffer (TLB)

Virtual Memory 12 Hardware Requirements (cont) Intel x86 –Unix implementations on the x86 hides the notion of segmentation from user processes, who see a flat address space –Two-level page table –4k byte page size –Control register CR3 stores the physical page number of the current page directory –CR3 register needs to be reset on each context switch

Virtual Memory 13 Hardware Requirements (cont) –Page table entry Physical page number, protection field Valid, referenced, and modified bit –x86 supports 4 privilege levels of which UNIX uses only two –The kernel runs in the innermost ring, which is the most privileged –User code runs in the outermost, least privileged ring

Virtual Memory 14 Address Translation on Intel x86 CR3 PFN PFN DIRPAGEOFFSET PFNOFFSET page directory of current process one of the page tables of current process virtual address physical address

Virtual Memory 15 Intel x86 Page Table Entry PFN PFNPage Frame Number DDirty AAccessed (Referenced) UUser (0) / Supervisor (1) WRead (0) / Write (1) PPresent (valid) DAUWP 5210

Virtual Memory BSD Target platform: VAX-11 –Several BSD-based implementations emulate the VAX memory architecture in software, including its address space layout and page table entry format Core map –Describes physical memory Page tables –Describe virtual memory

Virtual Memory BSD (cont) Disk maps –Describe the swap areas Resource maps –Manage allocation of resources such as page tables and swap space

Virtual Memory BSD Physical Memory nonpaged pool error buffer paged pool cmap[ ] (in nonpaged pool)

Virtual Memory BSD Physical Memory (cont) Core map: struct cmap –Is a kernel data structure, allocated at boot time and resident in the nonpaged pool –One entry for each frame in the paged pool Core map entry –Name –Text page cache –Synchronization

Virtual Memory BSD Physical to Virtual address Translation type = data owner VPN … type = data owner VPN … cmap[ ] proc[ ] text[ ] page table page table

Virtual Memory BSD Address Space Uses VAX-11 address space model –32-bit machine with 512-byte page size –4 Giga byte address space is divided into four regions of equal size –P0 Program region Text and data section of the process

Virtual Memory BSD Address Space (cont) –P1 Control region User stack, u area, kernel stack –S0 System region Kernel text and data –4th region Reserved and not supported by current VAX h/w

Virtual Memory BSD Page Tables Single system page table –Map the kernel text and data Each process has two page tables to map its P0 and P1 –Mapped by a set of contiguous PTEs in the Userptmap section of the system page table State of a particular page of a process –Resident The page is in physical memory, and the page table entry contains its physical page frame number

Virtual Memory BSD Page Tables (cont) –Fill-on-demand Fill-from-text: Text and initialized data pages are read in from the executable file upon first access Zero-fill: Uninitialized data, heap, and stack pages are created and filled with zero when required –Outswapped These pages may be recovered from their swap area locations

Virtual Memory BSD Page Tables (cont) Kernel maintains information about all nonresident pages –For swapped out pages Kernel must stores their location on the swap device –For zero-fill pages Kernel only needs to recognize them as such –For fill-from-text pages Kernel must determine their location in the filesystem

Virtual Memory BSD Page Tables (cont) Page table entry –Since all nonresident pages have the valid bit clear, other fields can be replaced by other information that tracks these pages –Kernel maintains separate swap maps to locate those pages on the swap device

Virtual Memory 27 Page Frame Number (PFN)PROT VMunused 0 valid modified Page Frame Number (PFN)PROT VM 0 valid modified (a) VAX-11 page table entry format (b) Ordinary page table entry File System Block NumberPROT V 0 0 1F 25 fill-on-demand fill-from-text (1) or zero-fill (0) (c) Fill-on-demand page table entry 4.3BSD Page Tables Entry

Virtual Memory BSD Swap Space Per region dmap structure data region swap space dmap 0 dmmin 2*dmmin 4*dmmin

Virtual Memory BSD Swap Space (cont) Text pages –Once the page is brought into memory, the fill- on-demand PTE is overwritten by the page frame number –As a result, retrieving the page from the file involving recomputing its location and perhaps, accessing one or more indirect blocks –To avoid that, such pages are saved in swap as well

Virtual Memory BSD Swap Space (cont) U area holds the maps for the data and stack region The text region swap map is part of the text structure

Virtual Memory BSD Memory Management Operations Process creation –Swap space, u area –Page tables Kernel must allocate contiguous PTEs in Userptmap to map page tables for their process –Text region The child is added to the list of processes sharing the text structure used by the parent –Data and Stack Data and stack must be copied one page at a time Copy-on-write, vfork( )

Virtual Memory BSD Memory Management Operations (cont) Page table handling –Two types of page faults validation, protection –Validation No PTE for that page (bounds error) PTE is marked invalid –Pagein( ) is called to handle the fault The faulting virtual address  PTE

Virtual Memory 33 Pagein( ) (1/2) start Fill on demand? NoYes (next page) PFN == 0? No Yes text page on hash queue? (next page) Yes No allocate new page read page from swap in transit text page? No on free list? Yes take page off free list Yes set wanted flag sleep on text struct start over when woken up set valid bit No

Virtual Memory 34 Pagein( ) (2/2) fill it with zeros Fill on demand? Yes zero-fill? Yes allocate new page mark page modified text page on hash queue? No page in buffer cache? No Read page from file Yes flush cache copy to disk Yes take page off free list (previous page)

Virtual Memory BSD Memory Management Operations (cont) Free page list –Ideally, to keep all garbage pages at the head of the free list, followed by some useful pages in LRU order –4.3BSD replaces the least recently used policy by a not recently used policy Uses referenced bit and two passes over each page VAX-11 does not support a referenced bit in the h/w, so BSD simulates the referenced bit in software Pagedaemon process is responsible for page replacement

Virtual Memory BSD Memory Management Operations (cont) Swapping –Problem of thrashing –Swapper process monitors the system load, and swap processes in and out when needed –Swapper will swap out a process in the following cases Userptmap fragmentation Memory shortfall Inactive processes

Virtual Memory BSD Memory Management Operations (cont) –Swapper performs the following task when swapping out a process Allocates swap space for the u area, kernel stack, and page tables Detach the process from its text region Save the resident data and stack on swap Release the system PTEs in Userptmap Record the swap location of the u area in the proc structure

Virtual Memory 38 Analysis of 4.3BSD No support for execution of remote programs No support for sharing of memory vfork( ) is not a true substitute for fork( ) –The lack of copy-on-write hurts the performance of Ap that rely extensively on fork No support for memory mapped files

Virtual Memory 39 Analysis of 4.3BSD (cont) Reserves enough swap space in advance to page out very single page in the process address space No support for using swap space on remote nodes