Slide 12-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 12 Virtual Memory.

Slides:



Advertisements
Similar presentations
Slide 11-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter Memory Management.
Advertisements

Caching and Virtual Memory. Main Points Cache concept – Hardware vs. software caches When caches work and when they don’t – Spatial/temporal locality.
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
Module 10: Virtual Memory Background Demand Paging Performance of Demand Paging Page Replacement Page-Replacement Algorithms Allocation of Frames Thrashing.
Virtual Memory Introduction to Operating Systems: Module 9.
Lecture 34: Chapter 5 Today’s topic –Virtual Memories 1.
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Lecture 11: Memory Management
CS 104 Introduction to Computer Science and Graphics Problems
Virtual Memory. Names, Virtual Addresses & Physical Addresses Source Program Absolute Module Name Space P i ’s Virtual Address Space P i ’s Virtual Address.
1 Lecture 9: Virtual Memory Operating System I Spring 2007.
CSI 400/500 Operating Systems Spring 2009 Lecture #9 – Paging and Segmentation in Virtual Memory Monday, March 2 nd and Wednesday, March 4 th, 2009.
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
Maninder Kaur VIRTUAL MEMORY 24-Nov
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Virtual Memory.
Caching and Virtual Memory. Main Points Cache concept – Hardware vs. software caches When caches work and when they don’t – Spatial/temporal locality.
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
Operating Systems Chapter 8
MEMORY MANAGEMENT Presented By:- Lect. Puneet Gupta G.P.C.G. Patiala.
Chapter 10 Memory Management Part_1. 2 Overview Basic Concepts The major tasks of the memory manger are the allocation and deallocation of main memory.
Virtual Memory. 2 Virtual Memory Manager Provides abstraction of physical memory Creates virtual address space in secondary memory and then “automatically”
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
Memory Management Techniques
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.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Virtual Memory. Background Virtual memory is a technique that allows execution of processes that may not be completely in the physical memory. Virtual.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
“ Memory Management Function ” Presented By Lect. Rimple Bala GPC,Amritsar 1.
Virtual Memory The memory space of a process is normally divided into blocks that are either pages or segments. Virtual memory management takes.
CSC 360, Instructor: Kui Wu Memory Management II: Virtual Memory.
Memory Management & Virtual Memory © Dr. Aiman Hanna Department of Computer Science Concordia University Montreal, Canada.
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.
1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
1 Contents Memory types & memory hierarchy Virtual memory (VM) Page replacement algorithms in case of VM.
Virtual Memory Chapter 8.
UNIT–IV: Memory Management
ITEC 202 Operating Systems
Memory Management Ch.7 and Ch.8.
Operating Systems: A Modern Perspective, Chapter 12
Operating Systems: A Modern Perspective, Chapter 12
Virtual Memory © 2004, D. J. Foreman.
Lecture 10: Virtual Memory
Module 9: Virtual Memory
You can pick up your graded Homework #3 now or after class
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
Chapter 9: Virtual-Memory Management
Page Replacement.
Memory Management & Virtual Memory
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
Main Memory Background Swapping Contiguous Allocation Paging
Contents Memory types & memory hierarchy Virtual memory (VM)
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
Memory Management.
Lecture 9: Caching and Demand-Paged Virtual Memory
Virtual Memory © 2004, D. J. Foreman.
CSE 542: Operating Systems
Module 9: Virtual Memory
COMP755 Advanced Operating Systems
Virtual Memory.
Chapter 8 & 9 Main Memory and Virtual Memory
CSE 542: Operating Systems
Module IV Memory Organization.
Presentation transcript:

Slide 12-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter Virtual Memory

Slide 12-2 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Virtual Memory Organization Memory Image for p i Secondary Memory Primary Memory

Slide 12-3 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Names, Virtual Addresses & Physical Addresses Source Program Absolute Module Name Space P i ’s Virtual Address Space P i ’s Virtual Address Space Executable Image Physical Address Space Physical Address Space B t : Virtual Address Space  Physical Address Space

Slide 12-4 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Locality Address space is logically partitioned –Text, data, stack –Initialization, main, error handle Different parts have different reference patterns: Address Space for p i Initialization code (used once) Code for  1 Code for  2 Code for  3 Code for error 1 Code for error 2 Code for error 3 Data & stack 30% 20% 35% 15% <1% Execution time

Slide 12-5 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Virtual Memory Every process has code and data locality –Code tends to execute in a few fragments at one time –Tend to reference same set of data structures Dynamically load/unload currently-used address space fragments as the process executes Uses dynamic address relocation/binding –Generalization of base-limit registers –Physical address corresponding to a compile- time address is not bound until run time

Slide 12-6 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Virtual Memory (cont) Since binding changes with time, use a dynamic virtual address map, B t Virtual Address Space BtBt

Slide 12-7 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Virtual Memory Virtual Address Space for p i Virtual Address Space for p j Virtual Address Space for p k Secondary Memory Complete virtual address space is stored in secondary memory Primary Memory 0 n-1 Physical Address Space Fragments of the virtual address space are dynamically loaded into primary memory at any given time Each address space is fragmented

Slide 12-8 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Paging A page is a fixed size, 2 h, block of virtual addresses A page frame is a fixed size, 2 h, block of physical memory (the same size as a page) When a virtual address, x, in page i is referenced by the CPU –If page i is loaded at page frame j, the virtual address is relocated to page frame j –If page is not loaded, the OS interrupts the process and loads the page into a page frame

Slide 12-9 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Page-Based Address Translation Let N = {d 0, d 1, … d n-1 } be the pages Let M = {b 0, b 1, …, b m-1 } be page frames Virtual address, i, satisfies 0  i<G= 2 g+h Physical address, k = U2 h +V (0  V<G= 2 h ) –U is page frame number –V is the line number within the page – B t :[0:G-1]   {  } –Since every page is size c=2 h page number = U =  i/c  line number = V = i mod c

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Modeling Page Behavior Let R = r 1, r 2, r 3, …, r i, … be a page reference stream –r i is the i th page # referenced by the process –The subscript is the virtual time for the process Given a page frame allocation of m, the memory state at time t, S t (m), is set of pages loaded –S t (m) = S t-1 (m)  X t - Y t X t is the set of fetched pages at time t Y t is the set of replaced pages at time t

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Static Allocation, Demand Paging Number of page frames is static over the life of the process Fetch policy is demand Since S t (m) = S t-1 (m)  {r t } - {y}, the replacement policy must choose y -- which uniquely identifies the paging policy

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Address Translation with Paging Page #Line # Virtual Address g bits h bits BtBt Missing Page Frame #Line # j bitsh bits Physical Address MAR CPU Memory “page table”

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Random Replacement Replaced page, y, is chosen from the m loaded page frames with probability 1/m Let page reference stream,  R = Frame No knowledge of R  not perform well Easy to implement 13 page faults

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Belady’s Optimal Algorithm Replace page with maximal forward distance: y t = max xeS t-1(m) FWD t (x) Let page reference stream,  R = Frame

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Belady’s Optimal Algorithm Replace page with maximal forward distance: y t = max xeS t-1(m) FWD t (x) Let page reference stream,  R = Perfect knowledge of R  perfect performance Impossible to implement 10 page faults Frame

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Least Recently Used (LRU) Replace page with maximal forward distance: y t = max xeS t-1(m) BKWD t (x) Let page reference stream,  R = Frame BKWD 4 (2) = 3 BKWD 4 (0) = 2 BKWD 4 (3) = 1

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Least Recently Used (LRU) Replace page with maximal forward distance: y t = max xeS t-1(m) BKWD t (x) Let page reference stream,  R = Frame Backward distance is a good predictor of forward distance -- locality

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Least Frequently Used (LFU) Replace page with minimum use: y t = min xeS t-1(m) FREQ(x) Let page reference stream,  R = Frame FREQ 4 (2) = 1 FREQ 4 (0) = 1 FREQ 4 (3) = 1

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Least Frequently Used (LFU) Replace page with minimum use: y t = min xeS t-1(m) FREQ(x) Let page reference stream,  R = Frame FREQ 6 (2) = 2 FREQ 6 (1) = 1 FREQ 6 (3) = 1

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 First In First Out (FIFO) Replace page that has been in memory the longest: y t = max xeS t-1(m) AGE(x) Let page reference stream,  R = Frame

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 First In First Out (FIFO) Replace page that has been in memory the longest: y t = max xeS t-1(m) AGE(x) Let page reference stream,  R = Frame AGE 4 (2) = 3 AGE 4 (0) = 2 AGE 4 (3) = 1

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Stack Algorithms Some algorithms are well-behaved Inclusion Property: Pages loaded at time t with m is also loaded at time t with m+1 Frame Frame LRU

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Stack Algorithms Some algorithms are well-behaved Inclusion Property: Pages loaded at time t with m is also loaded at time t with m+1 FIFO Frame Frame

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Windows NT Paging System Primary Memory Virtual Address Space Supv space User space Paging Disk (Secondary Memory) 2.Lookup (Page i, Addr k) 3.Translate (Page i, Addr k) to (Page Frame j, Addr k) 4.Reference (Page Frame j, Addr k) 1.Reference to Address k in Page i (User space)

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Windows Address Translation Page DirectoryPage TableByte Index Virtual page numberLine number Page Directory Page Tables Target Page Target Byte c b a A C B

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Linux Virtual Address Translation

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Segment Address Translation B t : segments x offsets  physical address  {  } B t (i, j) = k S : segments  segment addresses B t ( S (segName), j) = k N : offset names  offset addresses B t ( S (segName), N (offsetName)) = k Read implementation in Section 12.6

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 Address Translation in Segmentation S N segment #offset BtBt Missing segment LimitBaseP Limit Relocation + ? To Memory Address Register

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 NT Memory-mapped Files Memory mapped files Memory mapped files Executable memory Secondary memory Ordinary file Open the file Create a section object (that maps file) Identify point in address space to place the file Section object

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 12 NT Memory-mapped Files(2)