OS Fall’02 Virtual Memory Operating Systems Fall 2002.

Slides:



Advertisements
Similar presentations
Multilevel Page Tables
Advertisements

Virtual Memory: Page Replacement
Chapter 8 Virtual Memory
1 Memory hierarchy and paging Electronic Computers M.
Virtual Memory Chapter 18 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi.
Chapter 8 Virtual Memory Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice.
Memory/Storage Architecture Lab Computer Architecture Virtual Memory.
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
OS Spring ‘04 Paging and Virtual Memory Operating Systems Spring 2004.
Virtual Memory Chapter 8.
Virtual Memory Chapter 8.
Memory Management (II)
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Memory Management -3 CS 342 – Operating Systems Ibrahim Korpeoglu Bilkent.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Paging and Virtual Memory. Memory management: Review  Fixed partitioning, dynamic partitioning  Problems Internal/external fragmentation A process can.
Memory Management 2010.
Virtual Memory Chapter 8.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Chapter 3.2 : Virtual Memory
1 Lecture 9: Virtual Memory Operating System I Spring 2007.
1 Chapter 8 Virtual Memory Virtual memory is a storage allocation scheme in which secondary memory can be addressed as though it were part of main memory.
Virtual Memory Chapter 8.
Virtual Memory I Chapter 8.
A. Frank - P. Weisberg Operating Systems Simple/Basic Paging.
Silberschatz, Galvin and Gagne  Operating System Concepts Segmentation Memory-management scheme that supports user view of memory. A program.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Paging. Memory Partitioning Troubles Fragmentation Need for compaction/swapping A process size is limited by the available physical memory Dynamic growth.
Topics covered: Memory subsystem CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Computer Architecture Lecture 28 Fasih ur Rehman.
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
Lecture 19: Virtual Memory
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 34 Paging Implementation.
July 30, 2001Systems Architecture II1 Systems Architecture II (CS ) Lecture 8: Exploiting Memory Hierarchy: Virtual Memory * Jeremy R. Johnson Monday.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources.
© 2004, D. J. Foreman 1 Virtual Memory. © 2004, D. J. Foreman 2 Objectives  Avoid copy/restore entire address space  Avoid unusable holes in memory.
Fall 2000M.B. Ibáñez Lecture 17 Paging Hardware Support.
8.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Paging Physical address space of a process can be noncontiguous Avoids.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Memory Management Fundamentals Virtual Memory. Outline Introduction Motivation for virtual memory Paging – general concepts –Principle of locality, demand.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Virtual Memory 1 1.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Hardware.
4.3 Virtual Memory. Virtual memory  Want to run programs (code+stack+data) larger than available memory.  Overlays programmer divides program into pieces.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Demand Paging.
Memory Management. Why memory management? n Processes need to be loaded in memory to execute n Multiprogramming n The task of subdividing the user area.
Page Table Implementation. Readings r Silbershatz et al:
Lectures 8 & 9 Virtual Memory - Paging & Segmentation System Design.
1 Lecture 8: Virtual Memory Operating System Fall 2006.
Operating Systems Session 7: – Virtual Memory organization Operating Systems.
Memory Management memory hierarchy programs exhibit locality of reference - non-uniform reference patterns temporal locality - a program that references.
Virtual Memory Chapter 8.
CS161 – Design and Architecture of Computer
ECE232: Hardware Organization and Design
CS161 – Design and Architecture of Computer
Chapter 8 Virtual Memory
Virtual Memory Chapter 8.
Lecture 10: Virtual Memory
EECE.4810/EECE.5730 Operating Systems
Computer Architecture
Translation Buffers (TLB’s)
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Translation Buffers (TLB’s)
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Computer Architecture
Translation Buffers (TLBs)
Review What are the advantages/disadvantages of pages versus segments?
Virtual Memory.
CSE 542: Operating Systems
Virtual Memory 1 1.
Presentation transcript:

OS Fall’02 Virtual Memory Operating Systems Fall 2002

OS Fall’02 Paging and Virtual Memory  Paging makes virtual memory possible Logical to physical address mapping is dynamic Processes can be broken to a number of pages that need not be mapped into a contiguous region of the main memory => It is not necessary that all of the process pages be in main memory during execution

OS Fall’02 How does this work?  CPU can execute a process as long as some portion of its address space is mapped onto the physical memory E.g., next instruction and data addresses are mapped  Once a reference to an unmapped page is generated (page fault): Put the process into blocking state Read the page from disk into the memory Resume the process

OS Fall’02 Benefits  More processes may be maintained in the main memory Better system utilization  The process size is not restricted by the physical memory size: the process memory is virtual But what is the limit anyway?

OS Fall’02 Why is this practical?  Observation: Program branching and data access patterns are not random  Principle of locality: program and data references tend to cluster => Only a fraction of the process virtual address space need to be resident to allow the process to execute for sufficiently long

OS Fall’02 Virtual memory implementation  Efficient run-time address translation Hardware support, control data structures  Fetch policy Demand paging: page is brought into the memory only when page-fault occurs Pre-paging: pages are brought in advance  Page replacement policy Which page to evict when a page fault occurs?

OS Fall’02 Thrashing  A condition when the system is engaged in moving pages back and forth between memory and disk most of the time  Bad page replacement policy may result in thrashing  Programs with non-local behavior

OS Fall’02 Address translation  Virtual address is divided into page number and offset  Process page table maintains mappings of virtual pages onto physical frames Each process has its own unique page table Virtual Address Page NumberOffset

OS Fall’02 Forward-mapped page tables (FMPT)  Page table entry (PTE) structure  Page table is an array of the above Index is the virtual page number PM Frame Number Other Control Bits Page Table Frame # Page # P: present bit M: modified bit

OS Fall’02 Address Translation using FMPT ProgramPagingMain Memory Virtual address Register Page Table Page Frame Offset P# Frame # Page Table Ptr Page #OffsetFrame #Offset +

OS Fall’02 Handling large address spaces  One level FMPT is not suitable for large virtual address spaces 32 bit addresses, 4K (2 12 ) page size, 2 32 / 2 12 = 2 20 entries ~4 bytes each => 4Mbytes resident page table per process! What about 64 bit architectures??  Solutions: multi-level FMPT Inverted page tables (IPT)

OS Fall’02 Multilevel FMPT  Use bits of the virtual address to index a hierarchy of page tables  The leaf is a regular PTE  Only the root is required to stay resident in main memory Other portions of the hierarchy are subject to paging as regular process pages

OS Fall’02 Two-level FMPT page number page offset pipi p2p2 d 10 12

OS Fall’02 Two-level FMPT

OS Fall’02 Inverted page table (IPT)  A single table with one entry per physical page  Each entry contains the virtual address currently mapped to a physical page (plus control bits)  Different processes may reference the same virtual address values Address space identifier (ASID) uniquely identifies the process address space

OS Fall’02 Address translation with IPT  Virtual address is first indexed into the hash anchor table (HAT)  The HAT provides a pointer to a linked list of potential page table entries  The list is searched sequentially for the virtual address (and ASID) match  If no match is found -> page fault

OS Fall’02 Address translation with IPT Virtual address page number offset hash + HAT base register ASID register page number ASID Frame# IPT + IPT base register frame number HAT

OS Fall’02 Translation Lookaside Buffer (TLB)  With VM accessing a memory location involves at least two intermediate memory accesses Page table access + memory access  TLB caches recent virtual to physical address mappings ASID or TLB flash is used to enforce protection

OS Fall’02 TLB internals  TLB is associative, high speed memory Each entry is a pair (tag,value) When presented with an item it is compared to all keys simultaneously If found, the value is returned; otherwise, it is a TLB miss Expensive: number of typical TLB entries: Do not confuse with memory cache!

OS Fall’02 Address translation with TLB

OS Fall’02 Bits in the PTE: Present (valid)  Present (valid) bit Indicates whether the page is assigned to frame or not Invalid page can be not a part of any memory segment A reference to an invalid page generates page fault which is handled by the operating system

OS Fall’02 Bits in PTE: modified, used  Modified (dirty) bit Indicates whether the page has been modified Unmodified pages need not be written back to the disk when evicted  Used bit Indicates whether the page has been accessed recently Used by the page replacement algorithm

OS Fall’02 Bits in PTE  Access permissions bit indicates whether the page is read-only or read-write  UNIX copy-on-write bit Set whether more than one process shares a page If one of the processes writes into the page, a separate copy must first be made for all other processes sharing the page Useful for optimizing fork()

OS Fall’02 Protection with VM  Preventing processes from accessing other process pages  Simple with FMPT Load the process page table base address into a register upon context switch  ASID with IPT

OS Fall’02 Segmentation with paging  Segmentation simplifies protection and sharing, enforce modularity, but prone to external fragmentation  Paging transparent, eliminates ext. fragmentation, allows for sophisticated memory management  Segmentation and paging can be combined

OS Fall’02 Address translation Main Memory Page Frame Offset Paging Page Table P# + Frame #Offset Seg Table Ptr + S # SegmentationProgram Segment Table Seg #Page #Offset

OS Fall’02 Page size considerations  Small page size better approximates locality large page tables inefficient disk transfer  Large page size internal fragmentation  Most modern architectures support a number of different page sizes  a configurable system parameter

OS Fall’02 Next: Page replacement