Memory Management: Overlays and Virtual Memory. Agenda Overview of Virtual Memory –Review material based on Computer Architecture and OS concepts Credits.

Slides:



Advertisements
Similar presentations
Virtual Memory In this lecture, slides from lecture 16 from the course Computer Architecture ECE 201 by Professor Mike Schulte are used with permission.
Advertisements

Part IV: Memory Management
Memory Management: Overlays and Virtual Memory
EECS 470 Virtual Memory Lecture 15. Why Use Virtual Memory? Decouples size of physical memory from programmer visible virtual memory Provides a convenient.
COMP381 by M. Hamdi 1 Virtual Memory. COMP381 by M. Hamdi 2 Virtual Memory: The Problem For example: MIPS64 is a 64-bit architecture allowing an address.
16.317: Microprocessor System Design I
Carnegie Mellon 1 Virtual Memory: Concepts : Introduction to Computer Systems 15 th Lecture, Oct. 14, 2010 Instructors: Randy Bryant and Dave O’Hallaron.
CS 153 Design of Operating Systems Spring 2015
CS 333 Introduction to Operating Systems Class 11 – Virtual Memory (1)
Computer ArchitectureFall 2008 © CS : Computer Architecture Lecture 22 Virtual Memory (1) November 6, 2008 Nael Abu-Ghazaleh.
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.
Memory Management 2010.
Chapter 3.2 : Virtual Memory
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.
CS 333 Introduction to Operating Systems Class 9 - Memory Management
Computer Organization and Architecture
CS 333 Introduction to Operating Systems Class 9 - Memory Management Jonathan Walpole Computer Science Portland State University.
CS 241 Section Week #12 (04/22/10).
Virtual Memory By: Dinouje Fahih. Definition of Virtual Memory Virtual memory is a concept that, allows a computer and its operating system, to use a.
Computer Organization and Architecture Operating System Support Chapter 8.
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
CSE378 Virtual memory.1 Evolution in memory management techniques In early days, single program ran on the whole machine –used all the memory available.
CS 346 – Chapter 8 Main memory –Addressing –Swapping –Allocation and fragmentation –Paging –Segmentation Commitment –Please finish chapter 8.
Review of Memory Management, Virtual Memory CS448.
CS333 Intro to Operating Systems Jonathan Walpole.
Chapter 8 Memory Management Dr. Yingwu Zhu. Outline Background Basic Concepts Memory Allocation.
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.
Operating Systems ECE344 Ding Yuan Paging Lecture 8: Paging.
Operating Systems COMP 4850/CISG 5550 Page Tables TLBs Inverted Page Tables Dr. James Money.
Address Translation. Recall from Last Time… Virtual addresses Physical addresses Translation table Data reads or writes (untranslated) Translation tables.
Virtual Memory Lei Li CS147.
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.
1 Memory Management. 2 Fixed Partitions Legend Free Space 0k 4k 16k 64k 128k Internal fragmentation (cannot be reallocated) Divide memory into n (possible.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Hardware.
Introduction to Virtual Memory and Memory Management
Operating Systems Unit 7: – Virtual Memory organization Operating Systems.
Paging (continued) & Caching CS-3013 A-term Paging (continued) & Caching CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern.
MS108 Computer System I Lecture 11 Virtual Memory Prof. Xiaoyao Liang 2015/5/22 1.
Introduction: Memory Management 2 Ideally programmers want memory that is large fast non volatile Memory hierarchy small amount of fast, expensive memory.
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.
Lab4: Virtual Memory CS 3410 : Computer System Organization & Programming Spring 2015.
Carnegie Mellon 1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Virtual Memory: Concepts Slides adapted from Bryant.
Carnegie Mellon Introduction to Computer Systems / Spring 2009 March 23, 2009 Virtual Memory.
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.
CDA 5155 Virtual Memory Lecture 27. Memory Hierarchy Cache (SRAM) Main Memory (DRAM) Disk Storage (Magnetic media) CostLatencyAccess.
Chapter 2 Memory and process management
Memory COMPUTER ARCHITECTURE
CS161 – Design and Architecture of Computer
CSE 120 Principles of Operating
CSE 153 Design of Operating Systems Winter 2018
Lecture 28: Virtual Memory-Address Translation
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
CS399 New Beginnings Jonathan Walpole.
Virtual Memory Hardware
Translation Lookaside Buffer
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 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Evolution in memory management techniques
CS703 - Advanced Operating Systems
CSE 153 Design of Operating Systems Winter 2019
Evolution in memory management techniques
Evolution in memory management techniques
Virtual Memory 1 1.
Presentation transcript:

Memory Management: Overlays and Virtual Memory

Agenda Overview of Virtual Memory –Review material based on Computer Architecture and OS concepts Credits –The material in this slide set is mainly created by Profs. Raj Rajkumar and Professor Priya Narasimhan from ECE Dept at Carnegie Mellon

How Does a Program Start Running? x0000 0x3fff RAM CPU’s Program Counter is then set to the starting address of the program and the program begins execution. OS (loader) copies a program from permanent storage into RAM ­ on PCs and workstations, the “operating system” copies the program (bits) from disk.

What if the program is too big? Some machines won't let you run the program –Original DOS –Why this limitation? x0000 0x3fff RAM

Solution: Only Load Part of the Program One option: programmer breaks code into pieces that fit into RAM Pieces, called overlays, are loaded and unloaded by the program Does not require OS help RAM 0xff 0x00 0x00ff 0x0000 0x01ff 0x0100 load one overlay and run until other overlay is needed Program

ARM Linker Supports Overlays Overlay manager loads an overlay segment when it is not in RAM Supports Static and Dynamic Overlays Static overlays –One root segment –2 or more memory partitions (1 for the root partition which is always in RAM) –Within each partition, any number of overlay segments –Only 1 overlay segment can be in a partition at a given time –Application writer specifies what is in each partition and segment root segment 2_12_22_32_4 1_11_21_31_4 low address high address segments 1_1.. 1_4 share the same memory area so do segments 2_1.. 2_4

What Happens if... A function in one overlay calls a function in another ­ and vice-versa RAM 0xff 0x00 0x00ff 0x0000 0x01ff 0x0100 define foo2(){ call foo1(); } define foo1(){ call foo2(); } both segments statically allocated to the same physical partition

Dynamic Overlay Include re-location information with each overlay segment Have overlay manager allocate memory for an overlay segment when it is first loaded Load and unload overlay segments by explicit calls to overlay manager Each overlay segment is given its own name ­ linker links each as if it were in its own partition

Problems with Overlays Difficult for programmer to manage Not general ­ management of resources (RAM) is an operating system issue –But many embedded systems do not have the space or power for a “real” OS

Solution: Virtual Memory What is virtual memory? –Technique that allows execution of a program that may not completely reside in memory (RAM) Allows the computer to “fake”' a program into believing that its memory space is larger than physical RAM Why is VM important? –Cheap ­ no longer have to buy lots of RAM –Removes burden of memory resource management from the programmer –Other benefits...

How Does VM Work ? Two memory “spaces” –Virtual memory space ­ what the program “sees” –Physical memory space ­ what the program runs in (size of RAM) On program startup –OS copies program into RAM –If there is not enough RAM, OS stops copying program and starts it running with only a portion of the program loaded in RAM –When the program touches a part of the program not in physical memory (RAM), OS catches the memory abort (called a page fault) and copies that part of the program from disk into RAM –In order to copy some of the program from disk to RAM, OS must evict parts of the program already in RAM OS copies the evicted parts of the program back to disk

Example: Virtual and Physical Address Spaces Virtual Address Space Physical Address Space bne 0x00 add r10,r1,r2 sub r3,r4,r1 sw r5,0x0c 0x00 0x04 0x08 0x0C 0x10 0x14 0x18 0x1C 0x00 0x04 0x08 0x0C add r1,r2,r3 sub r2,r3,r4 lw r2, 0x04 mult r3,r4,r5 add r1,r2,r3 sub r2,r3,r4 lw r2, 0x04 mult r3,r4,r5

Example (con'td): Need VA­to­PA mappings bne 0x00 add r10,r1,r2 sub r3,r4,r1 sw r5,0x0c 0x00 0x04 0x08 0x0C 0x10 0x14 0x18 0x1C 0x00 0x04 0x08 0x0C add r1,r2,r3 sub r2,r3,r4 lw r2, 0x04 mult r3,r4,r5 add r1,r2,r3 sub r2,r3,r4 lw r2, 0x04 mult r3,r4,r5 Virtual Address Space Physical Address Space VA->PA

Example (con'td): After handling a page fault bne 0x00 add r10,r1,r2 sub r3,r4,r1 sw r5,0x0c 0x00 0x04 0x08 0x0C 0x10 0x14 0x18 0x1C 0x00 0x04 0x08 0x0C add r1,r2,r3 sub r2,r3,r4 lw r2, 0x04 mult r3,r4,r5 bne 0x00 sub r2,r3,r4 lw r2, 0x04 mult r3,r4,r5 Virtual Address Space Physical Address Space VA->PA

Example (con'td): After a second page fault bne 0x00 add r10,r1,r2 sub r3,r4,r1 sw r5,0x0c 0x00 0x04 0x08 0x0C 0x10 0x14 0x18 0x1C 0x00 0x04 0x08 0x0C add r1,r2,r3 sub r2,r3,r4 lw r2, 0x04 mult r3,r4,r5 bne 0x00 add r1,r2,r3 lw r2, 0x04 mult r3,r4,r5 Virtual Address Space Physical Address Space VA->PA

Basic VM Algorithm Program asks for virtual address Computer translates virtual address (VA) to physical address (PA) Computer reads PA from RAM, returning it to program 0x00 0x04 0x08 0x0C add r1,r2,r3 sub r2,r3,r4 lw r2, 0x04 mult r3,r4,r5 RAM VA->PA Processor (running program) Instructions (or data) Virtual address

Page Tables Table which holds VA ­> PA translations is called the page table In our current scheme, each word is translated from a virtual address to a physical address –How big is the page table? 0x00 0x04 0x08 0x0C add r1,r2,r3 sub r2,r3,r4 lw r2, 0x04 mult r3,r4,r5 RAM VA->PA Processor (running program) Instructions (or data) Virtual address

Real Page Tables Instead of the fine­grained VM where any virtual word can map to any RAM word location, partition memory into chunks called pages –Typical page size today is 4 or 8 KBytes This reduces the number of VA­> PA translation entries –Only one translation per page –For a 4 KByte page, that's one VA­> PA translation for every 1,024 words Within a page, the virtual address == physical address Virtual Page NumberPage Offset Physical Page #Page Offset Translation Virtual Address Physical Address

Virtual Pages & Physical Page Frames 0x7fff 0x6fff 0x5fff 0x4fff 0x3fff 0x2fff 0x1fff 0x0fff 0x0000 0x3fff 0x2fff 0x1fff 0x0fff 0x0000 Virtual Address Space Physical Address Space virtual page 0x000 to 0xfff = 4KB physical page frame

Page Frames Every address within a virtual page maps to the same location within a physical page frame –In other words, bottom log 2(page size in bytes) is not translated

Page Table Entries A real page table entry (PTE) contains a number of fields –Physical page number –Access control bits (e.g., writeable bit) –Status bits (e.g., accessed and dirty bits) –MMU control bits (e.g., cacheable and bufferable bits) Why is the virtual page number not in the page table entry? Physical Page Number (PPN)Access Control StatusMMU 2356

Interactions with Instruction/Data Cache Page table entry has bits to determine if region is –cacheable vs. uncacheable –write­through vs. write­back –Why control caching? –Some regions, such as for memory­mapped I/O devices, should not be cached. Why? Because cache doesn't know if I/O device register has changed value

Interactions with Write Buffer Page table entry has bits to determine if region –Allows write buffer to buffer writes Why would one not want to buffer writes? –Possible problems with memory­mapped I/O devices that require a write to complete before subsequent commands (instructions) are issued

Two­level Page Tables Virtual Address page directory page table page frame data

ARM MMU Complex VM and protection mechanisms Presents 4 GB address space (why?) Memory granularity: 3 options supported –1MB sections –Large pages (64 KBytes) ­ access control within a large page on 16 KBytes –Small pages (4 KBytes) ­ access control within a large page on 1 Kbytes Puts processor in Abort Mode when virtual address not mapped or permission check fails Change pointer to page tables (called the translation table base, in ARM jargon) to change virtual address space –useful for context switching of processes

Example: Single-Level Page Table Virtual Address page table page frame data value = y y 2 20 entries 32 bits 2 12 entries Size of page table = 2 20 * 32 bits = 4 Mbytes value = x x 8 bits Size of page = 2 12 * 8 bits = 4 Kbytes + Base of frame offset

Single-Level Page Table Assumptions –32-bit virtual addresses –4 Kbyte page size = 2 12 bytes –32-bit address space How many virtual page numbers? –2 32 / 2 12 = 2 20 = 1,048,576 virtual page numbers = number of entries in the page table If each page table entry occupies 4 bytes, how much memory is needed to store the page table? –2 20 entries * 4 bytes = 2 22 bytes = 4 Mbytes

Example: Two­level Page Table Virtual Address page directory page table page frame data value = z value = y y 2 10 entries 32 bits Size of page directory = 2 10 * 32 bits = 4 Kbytes value = x x z 2 10 entries Size of page table = 2 10 * 32 bits = 4 Kbytes 2 12 entries 8 bits Size of page = 2 12 * 8 bits = 4 Kbytes + + Base of page table +

Two-Level Page Table Assumptions –2 10 entries in page directory (= max number of page tables) –2 10 entries in page table –32 bits allocated for each page directory entry –32 bits allocated for each page table entry How much memory is needed? –Page table size = 2 10 entries * 32 bits = 2 12 bytes = 4 Kbytes –Page directory size = 2 10 entries * 32 bits = 2 12 bytes = 4 Kbytes

Two-Level Page Table Small (typical) system –One page table might be enough Page directory size + Page table size = 8 Kbytes of memory would suffice for virtual memory management –How much physical memory could this one page table handle? Number of page tables * Number of page table entries * Page size = 1 * 2 10 * 2 12 bytes = 4 Mbytes Large system –You might need the maximum number of page tables Max number of page tables * Page table size = 2 10 directory entries * 2 12 bytes = 2 22 bytes = 4 Mbytes of memory would be needed for virtual memory management –How much physical memory could these 2 10 page tables handle? Number of page tables * Number of page table entries * Page size = 2 10 * 2 10 * 2 12 bytes = 4 Gbytes

Summary of Lecture How do programs run in memory? –What happens on “overflows”? –Memory Overlays static overlays and dynamic overlays Problems with overlays Virtual Memory (VM) –What is VM? –How does VM work? –Virtual address to physical address mappings –Page faults –VM Schemes page tables virtual pages and physical page frames page table entries interactions with the rest of the system two-level page tables