8/25/2014cse410-26-memory © 2006-07 Perkins, DW Johnson and University of Washington1 Memory Management CSE 410, Spring 2008 Computer Systems

Slides:



Advertisements
Similar presentations
Chapter 7 Memory Management
Advertisements

Memory.
Part IV: Memory Management
Memory Protection: Kernel and User Address Spaces  Background  Address binding  How memory protection is achieved.
CSS430 Memory Management Textbook Ch8
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 13: Main Memory (Chapter 8)
Operating Systems Lecture Notes Memory Management Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
CS 311 – Lecture 21 Outline Memory management in UNIX
Modified from Silberschatz, Galvin and Gagne Lecture 16 Chapter 8: Main Memory.
CS 104 Introduction to Computer Science and Graphics Problems
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 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
MEMORY MANAGEMENT By KUNAL KADAKIA RISHIT SHAH. Memory Memory is a large array of words or bytes, each with its own address. It is a repository of quickly.
Lecture 9: SHELL PROGRAMMING (continued) Creating shell scripts!
Operating System Concepts
Silberschatz, Galvin and Gagne  Operating System Concepts Multistep Processing of a User Program User programs go through several steps before.
Main Memory. Background Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are only.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 8: Main Memory.
Memory Management. Process must be loaded into memory before being executed. Memory needs to be allocated to ensure a reasonable supply of ready processes.
Chapter 8 Memory Management Dr. Yingwu Zhu. Outline Background Basic Concepts Memory Allocation.
8.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 8: Memory-Management Strategies Objectives To provide a detailed description.
Chapter 4 Storage Management (Memory Management).
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.
Lecture Topics: 11/17 Page tables TLBs Virtual memory flat page tables
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Silberschatz and Galvin  Operating System Concepts Module 8: Memory Management Background Logical versus Physical Address Space Swapping Contiguous.
CE Operating Systems Lecture 14 Memory management.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Memory Management Operating Systems CS550. Memory Manager Memory manager - manages allocation and de-allocation of main memory Plays significant impact.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 31 Memory Management.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Memory and Addressing It all starts.
8.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Fragmentation External Fragmentation – total memory space exists to satisfy.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 8: Main Memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition, Chapter 8: Memory- Management Strategies.
Main Memory CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
Main Memory Management
Chapter 8: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
Operating System Concepts
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
Memory Management-I 1.
Main Memory Background Swapping Contiguous Allocation Paging
Memory Management Tasks
Chapter 8: Memory management
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
Lecture 3: Main Memory.
Chapter 8: Memory Management strategies
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
COMP755 Advanced Operating Systems
CSE 542: Operating Systems
Page Main Memory.
Presentation transcript:

8/25/2014cse memory © Perkins, DW Johnson and University of Washington1 Memory Management CSE 410, Spring 2008 Computer Systems

8/25/2014cse memory © Perkins, DW Johnson and University of Washington2 Readings and References Reading »Chapter 9, Operating System Concepts, Silberschatz, Galvin, and Gagne Other Readings »P&H: »P&H CDA-AQA:

8/25/2014cse memory © Perkins, DW Johnson and University of Washington3 Review: Program Memory Addresses Program addresses are fixed at the time the source file is compiled and linked Small, simple systems can use program addresses as the physical address in memory Modern systems usually much more complex »program address space very large »other programs running at the same time »operating system is in memory too

8/25/2014cse memory © Perkins, DW Johnson and University of Washington4 heap program stack physical memory program addresses physical addresses Direct Physical Addressing

8/25/2014cse memory © Perkins, DW Johnson and University of Washington5 Physical Addresses Address generated by the program is the same as the address of the actual memory location Simple approach, but lots of problems »Only one process can easily be in memory at a time »There is no way to protect the memory that the process isn't supposed to change (ie, the OS or other processes) »A process can only use as much memory as is physically in the computer »A process occupies all the memory in its address space, even if most of that space is never used 2 GB for the program and 2 GB for the system kernel

Absolute Code 8/25/2014cse memory © Perkins, DW Johnson and University of Washington6 Compile time: if it can be known in advance the starting address of a program in memory, then absolute code can be generated..com-format programs (MSDOS) Output: a.exe, a.o, or an object module Q:In a multiprogrammed environment, can I run two of these synchronously? Q: Can I relocate this code (say, to coalesce memory gaps when dealing with fragmentation)

8/25/2014cse memory © Perkins, DW Johnson and University of Washington7 heap program stack physical memory heap program stack heap program stack program addresses physical addresses memory mapping disk Memory Mapping

Address Binding 8/25/2014cse memory © Perkins, DW Johnson and University of Washington8 Symbolic Addresses Relocatable Code Absolute Code Loader produces the final address binding(no dynamic relocation) Run-time environment produces the final address binding (with dynamic relocation)

Intro to Address Bindings 8/25/2014cse memory © Perkins, DW Johnson and University of Washington9 Compiler/assembler Symbolic -> Absolute Symbolic -> Relocatable Loader Relocatable-> final binding Runtime environment Relocatable-> final binding

Address Generation and Binding 8/25/2014cse memory © Perkins, DW Johnson and University of Washington10 Source code produces symbolic addresses Array1, x, y, count An abstraction offered to us by our assembler A compiler will bind these symbolic addresses to Absolute addresses Symbolic address was x, absolute (physical address) is 0x04 Relocatable addresses Symbolic address was x, relocatable address is “16 bytes from the beginning of this file”

Address Transformations 8/25/2014cse memory © Perkins, DW Johnson and University of Washington11 Load Time Loader: ties in other libraries and… If we couldn’t deduce our starting address statically, our compiler would generate instead relocatable code “14 bytes from the beginning of this file” All address bindings would be delayed until loading, at which point a starting offset defines every address in the program (like absolute).

Final Address Binding 8/25/2014cse memory © Perkins, DW Johnson and University of Washington12 Done at runtime Rather than x, which is our second word in the data section, we might call it “+4bytes from start” If the starting address isn’t known in advance, then the relocatable->logical binding is delayed… Binding at run time, if to be dynamically relocated during execution This more complex binding scheme is the only in which the logical address space and the physical address space differ!

Relocatable Code 8/25/2014cse memory © Perkins, DW Johnson and University of Washington13 An O.S. today will dynamically relocate processes from one section of the memory space to another. Delay binding of the relocatable addresses till runtime Addresses up to this stage will be in some intermediary form, and then will be bound dynamically MS-DOS, x86: 4 relocation registers

8/25/2014cse memory © Perkins, DW Johnson and University of Washington14 Virtual Addresses The program addresses are now considered to be “virtual addresses” »Aka, logical addresses The memory management unit (MMU) translates the program addresses to the real physical addresses of locations in memory The user program never sees the real physical address – always a logical address »A program can create a pointer to 0x05 and store to that location in memory, read from it, etc.

Logical Memory V.S. Physical Memory The concept of a logical address space that is mapped (bound) to a physical address space is central to good memory management. Really, this is just another abstraction in which we decouple our program’s internal addresses from the physical array (with physical addresses) that defines main memory. It’s the job of the MMU (memory mapping hardware) to sustain this illusion, providing a reliable function whose input is the program’s logical address and whose output is the corresponding physical address 8/25/2014cse memory © Perkins, DW Johnson and University of Washington15

8/25/2014cse memory © Perkins, DW Johnson and University of Washington16 Physical Memory Layout Contiguous Allocation »Each process gets a single range of addresses »Single-partition allocation one process resident at a time »Multiple-partition allocation multiple processes resident at a time Noncontiguous allocation »Paging, segmentation, or a combination

8/25/2014cse memory © Perkins, DW Johnson and University of Washington17 OS Edit unused 0x0000 0xFFFF Uniprogramming without Protection Application always runs at the same place in physical memory Process can access all memory even OS »program bug crashes the machine MS-DOS

8/25/2014cse memory © Perkins, DW Johnson and University of Washington18 Solitaire OS Word unused 0x0000 0xFFFF 0x7000 Multiprogramming without Protection When a program is loaded the linker-loader translates a program's memory accesses (loads, stores, jumps) to where it will actually be running in memory »Still no protection Once was very common Windows 3.1, Mac OS  9

8/25/2014cse memory © Perkins, DW Johnson and University of Washington19 Multiprogramming with Protection Restrict what a program can do by restricting what it can touch User process is restricted to its own memory space »can't crash OS »can't crash other process How? »"All problems can be solved with another level of indirection"

8/25/2014cse memory © Perkins, DW Johnson and University of Washington20 Simple Translation: Base/Bounds Each process has a base register »added to every memory reference Each process has a bounds register »no memory reference allowed beyond here Word Solitaire OS base reg =0x base reg =0x bounds reg =0x bounds reg =0x700000

8/25/2014cse memory © Perkins, DW Johnson and University of Washington21 Base/Bounds Word references 0x004FF00 - valid Solitaire references 0x1100C0 - error Virtual Address + > Base register Bounds register Physical Address ERROR! yes Word Solitaire OS base reg =0x base reg =0x bounds reg =0x bounds reg =0x700000

8/25/2014cse memory © Perkins, DW Johnson and University of Washington22 Fragmentation OS P1 P2 P3 OS P1 P3 OS P1 P3 P4 OS P3 P4 OS P3 P4 P5 OS P1 OS P1 P2 OS P3 P4 P5 P6 compaction Over time unused memory is spread out in small pieces »external fragmentation Rearrange memory to make room for the next program »compaction = lots of copying (expensive) »change base/bounds registers for moved programs

8/25/2014cse memory © Perkins, DW Johnson and University of Washington23 Base/bounds Evaluation Advantages of base/bounds »process can't crash OS or other processes »can move programs around and change base register »can change program memory allocation by changing bounds register Problems with base/bounds »external fragmentation »can't easily share memory between processes »programs are limited to amount of physical memory »doesn’t improve support for sparse address spaces

Paging Divide a process's virtual address space into fixed- size chunks (called pages) Divide physical memory into pages of the same size Any virtual page can be located at any physical page Translation box converts from virtual pages to physical pages Translation Virtual Page # Physical Page # 0x0000 0x6000 0x0000 0x4000 0x0000 0xE000

8/25/2014cse memory © Perkins, DW Johnson and University of Washington25 Paging and Fragmentation No external fragmentation because all pages are the same size »don’t have to rearrange pages Sometimes there is internal fragmentation because a process doesn’t use a whole page »some space wasted at the end of a page »better than external fragmentation

8/25/2014cse memory © Perkins, DW Johnson and University of Washington26 Page Tables Page Table Virtual Page # Physical page # virtual address VPN Offset physical address PPN Offset A page table maps virtual page numbers to physical page numbers Lots of different types of page tables »arrays, lists, hashes

Flat Page Table A flat page table uses the VPN to index into an array What's the problem? VPN PPN Page Table VPNOffset 4100 Memory

8/25/2014cse memory © Perkins, DW Johnson and University of Washington28 Flat Page Table Evaluation Very simple to implement Don't work well for sparse address spaces »code starts at 0x , stack starts at 0x7FFFFFFF With 4K pages, this requires 1M entries per page table »must be kept in main memory (can't be put on disk) 64-bit addresses are a nightmare (4 TB) Addressing page tables in kernel virtual memory reduces the amount of physical memory used

8/25/2014cse memory © Perkins, DW Johnson and University of Washington29 Multi-level Page Tables Use multiple levels of page tables »each page table entry points to another page table »the last page table contains the physical page numbers (PPN) The VPN is divided into »Index into level 1 page »Index into level 2 page »…

Multi-level Page Tables L1 Page Table NO VPNOffset Memory L2Page Tables

8/25/2014cse memory © Perkins, DW Johnson and University of Washington31 Multi-Level Evaluation Only allocate as many page tables as we need--works with the sparse address spaces Only the top page table must be in pinned in physical memory Each page table usually fills exactly 1 page so it can be easily moved to/from disk Requires multiple physical memory references for each virtual memory reference »TLB masks most of this

Inverted Page Tables Inverted page tables hash the VPN to get the PPN Requires O(1) lookup Storage is proportional to number of physical pages being used not the size of the address space Hash Table VPN Offset Inverted Page Table Memory