1 Project: Virtual Memory Manager Lubomir Bic. 2 Assignment Design and implement a virtual memory system (VM) using segmentation and paging The system.

Slides:



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

Basic Memory Management Monoprogramming Protection Swapping Overlaying OS space User space.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
OS Fall’02 Virtual Memory Operating Systems Fall 2002.
Virtual Memory Introduction to Operating Systems: Module 9.
Segmentation and Paging Considerations
7. Physical Memory 7.1 Preparing a Program for Execution
CS 153 Design of Operating Systems Spring 2015
Memory/Storage Architecture Lab Computer Architecture Virtual Memory.
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
Memory Management and Paging CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Memory Problems Prof. Sin-Min Lee Department of Mathematics and Computer Sciences.
Chapter 3.2 : Virtual Memory
Translation Buffers (TLB’s)
Virtual Memory. Why do we need VM? Program address space: 0 – 2^32 bytes –4GB of space Physical memory available –256MB or so Multiprogramming systems.
Chapter 9 Virtual Memory Produced by Lemlem Kebede Monday, July 16, 2001.
CS 241 Section Week #12 (04/22/10).
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
1 Project: File System Textbook: pages Lubomir Bic.
Virtual Memory Chantha Thoeun. Overview  Purpose:  Use the hard disk as an extension of RAM.  Increase the available address space of a process. 
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
CS333 Intro to Operating Systems Jonathan Walpole.
Lecture 21 Last lecture Today’s lecture Cache Memory Virtual memory
Computer Architecture Lecture 28 Fasih ur Rehman.
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.
IT253: Computer Organization
Computer Architecture Lecture 26 Fasih ur Rehman.
Fall 2000M.B. Ibáñez Lecture 17 Paging Hardware Support.
CE Operating Systems Lecture 14 Memory management.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Demand Paging.
Demand Paging Reference Reference on UNIX memory management
Memory Management Continued Questions answered in this lecture: What is paging? How can segmentation and paging be combined? How can one speed up address.
1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
CS203 – Advanced Computer Architecture Virtual Memory.
1 Contents Memory types & memory hierarchy Virtual memory (VM) Page replacement algorithms in case of VM.
CS161 – Design and Architecture of Computer
Memory: Page Table Structure
Translation Lookaside Buffer
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Lecture 11 Virtual Memory
Memory Hierarchy Ideal memory is fast, large, and inexpensive
Virtual Memory Chapter 7.4.
ECE232: Hardware Organization and Design
CS161 – Design and Architecture of Computer
Day 21 Virtual Memory.
Demand Paging Reference Reference on UNIX memory management
Day 22 Virtual Memory.
Demand Paging Reference Reference on UNIX memory management
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
EECE.4810/EECE.5730 Operating Systems
Virtual Memory 4 classes to go! Today: Virtual Memory.
Page Replacement.
Virtual Memory فصل هشتم.
Translation Lookaside Buffer
Practical Session 9, Memory
Translation Buffers (TLB’s)
Virtual Memory Overcoming main memory size limitation
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Contents Memory types & memory hierarchy Virtual memory (VM)
CSE451 Virtual Memory Paging Autumn 2002
Translation Buffers (TLB’s)
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Computer Architecture
Paging and Segmentation
CS703 - Advanced Operating Systems
Translation Buffers (TLBs)
Operating Systems: Internals and Design Principles, 6/E
Review What are the advantages/disadvantages of pages versus segments?
Presentation transcript:

1 Project: Virtual Memory Manager Lubomir Bic

2 Assignment Design and implement a virtual memory system (VM) using segmentation and paging The system manages the necessary segment and page tables in a simulated main memory It accepts VA’s and translates them into PA’s It also utilizes a translation look-aside buffer (TLB) to make the translation process more efficient

3 Segmentation with Paging

4 Organization of the VM system There is only a single process and hence a single ST Each ST entry points to a PT Each PT entry points to a program/data page A VA is an integer (32 bits), divided into s, p, w. –|s|=9, i.e., ST size is 512 words (int) –|p|=10, i.e., PT size is 1024 words –|w|=9, i.e., page size is 512 words –The leading 4 bits of the VA are unused.

5 Organization of the VM system Each ST entry can have three types of entry: –-1: PT is currently not resident in PM (page fault) –0: corresponding PT does not exist read: error; write: create blank PT –f: PT starts at physical address f (address, not frame #) Each PT entry can also have three types of entry: –-1: page is currently not resident in PM (page fault) –0: corresponding page does not exist read: error; write: create blank page –f: page starts at physical address f

6 Organization of PM PM is represented as an array of integers –each corresponds to one addressable memory word PM is divided into frames of size 512 words (integers) –consequently, ST occupies one frame –each PT occupies two (consecutive) frames –each program/data page occupies one frame PA consists of 1024 frames (=array of 524,288 int, =2MB) –Consequently the size of PA is 19 bit ST always resides in frame 0 and is never paged out A page may be placed into any free frame A PT may be placed into any pair of consecutive free frames

Organization of PM Operating Systems 7 s PM[s] … p ST w PM[PM[s]+p] … … PT page PM[s] accesses the ST –If the entry is >0 then it points to a resident PT PM[PM[s]+p] accesses the PT –If the entry is >0 then it points to a resident page All ST/PT entries are multiples of 512 (fame size)

8 Organization of PM A bit map is used to keep track of free/occupied frames The bit map consists of 1024 bits (one per frame) It can be implemented as an array of 32 integers Normally this would be maintained inside the PM but in this project it may be implemented as a separate data structure

Address Translation Process Break each VA into s, p, w For read access: –If ST or PT entry is -1 then output “pf” (page fault) and continue with next VA –If ST or PT entry is 0 then output “error” and continue with next VA –Otherwise output PA = PM[PM[s] + p] + w Operating Systems 9 s PM[s] … p ST w PM[PM[s]+p] … … PT page

Address Translation Process For write access: –If ST or PT entry is -1 then output “pf” –If ST entry is 0 then allocate new blank PT (all zeroes) update the ST entry accordingly continue with the translation process; Operating Systems 10 s PM[s] … p ST w PM[PM[s]+p] … … PT page

Address Translation Process For write access (cont.): –if PT entry is 0 then create a new blank page update the PT entry accordingly continue with the translation process –Otherwise output the corresponding PA Operating Systems 11 s PM[s] … p ST w PM[PM[s]+p] … … PT page

Initialization of PM Read init file: s 1 f 1 s 2 f 2 … s n f n p 1 s 1 f 1 p 2 s 2 f 2 … p m s m f m s i f i : PT of segment s i starts at address f i –If f i = ‒ 1 then the corresponding PT is not resident –Example: : PT of seg 15 starts at address : PT of seg 9 is not resident p j s j f j : page p j of segment s j starts at address f j –If f i = ‒ 1 then the corresponding page is not resident –Example: : page 7 of seg 13 starts at : page 8 of seg 13 is not resident Operating Systems 12

Initialization of PM Initialize PM as follows: –Read s i f i pairs and make corresponding entries in ST –Read p j s j f j triples and make entries in the PT’s –Create bitmap to show which frames are free Note: each f is a PA, not just a frame number!! Operating Systems 13

Running the VM Translations Read input file: o 1 VA 1 o 2 VA 2 … o n VA n –each o i is either a 0 (read) or 1 (write) –each VA i is a positive integer (virtual address) For each o i VA i pair attempt to translate the VA to PA Write results into an output file Operating Systems 14

The TLB Size: 4 lines LRU: int 0:3 0: least recently accessed sp: int f: int (starting frame address, not frame #) Operating Systems 15

Running Translations with TLB Break VA into sp and w Search TLB for match on sp If TLB hit: –use f from TLB to form PA = f+w –update LRU fields as follows: assume the match is in line k, then: decrement all LRU values greater than LRU[k] by 1 set LRU[k] = 3 Operating Systems 16

Running Translations with TLB If TLB miss: –resolve VA as before –in case of error or page fault, no change to TLB –if a valid PA is derived then TLB is updated as follows: select line with LRU = 0 and set this LRU = 3 replace sp field of that line with the new sp value replace f field of that line with PM[PM[s] + p] decrement all other LRU values by 1 Operating Systems 17

18 The Bit Map (pg 217) Creating a new page or PT requires searching and updating the BM BM size: # of bits needed = # of page frames represent bit map as an array of int (32 bits each): BM[n] How to set, reset, and search for bits in BM? prepare a mask array: MASK[32] –diagonal contains “1”, all other fields are “0” –use bit operations (bitwise or/and) to manipulate bits

19 The Bit Map MASK (assume 16 bits only to simplify presentation) 010… 1010… 20010… … …… 150 … 01 to set bit i of BM[j] to “1”: BM[j] = BM[j] | MASK[i]

20 The Bit Map how to create MASK? MASK[0] = 0x8000 ( ) MASK[1] = 0x4000 ( ) MASK[2] = 0x2000 ( ) MASK[3] = 0x1000 ( ) MASK[4] = 0x0800 ( ) … MASK[15] = 0x0001 ( ) another approach: MASK[15] = 1; MASK[i] = MASK[i+1] <<

21 The Bit Map to set a bit to “0”: –create MASK2, where MASK2[i] = ~MASK[i] e.g.,  set bit i of BM[j] to “0”: BM[j] = BM[j] & MASK2[i]

22 The Bit Map to search for a bit equal to “0” in BM: for (i=0; … /* search BM from the beginning for (j=0; … /* check each bit in BM[i] for “0” test = BM[i] & MASK[j]) if (test == 0) then bit j of BM[i] is “0”; stop search

23 Summary of tasks Design and implement a VM memory system using segmentation and paging as described above. Design and implement a TLB to speed up the address translation process Design and implement a driver program that initializes the system from a given input file. It then reads another input file and, for each VA, attempts to translate it to the corresponding PA. It outputs the result of each address translation into a new file. Submit documentation Schedule testing