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.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Part IV: Memory Management
Ken Birman. How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines all.
CS 153 Design of Operating Systems Spring 2015
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.
Memory Management 2010.
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.
Chapter 7: Main Memory CS 170, Fall Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
03/22/2004CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
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/17/2008CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Chap 8 Memory Management. Background Program must be brought into memory and placed within a process for it to be run Input queue – collection of processes.
Memory Management -1 Background Swapping Memory Management Schemes
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 8 Operating Systems.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Operating Systems Chapter 8
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.
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.
1 Address Translation Memory Allocation –Linked lists –Bit maps Options for managing memory –Base and Bound –Segmentation –Paging Paged page tables Inverted.
CE Operating Systems Lecture 14 Memory management.
Chapter 4 Memory Management Virtual Memory.
1 Memory Management (b). 2 Paging  Logical address space of a process can be noncontiguous; process is allocated physical memory whenever the latter.
CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
9.1 Operating System Concepts Paging Example. 9.2 Operating System Concepts.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Hardware.
Memory Management Continued Questions answered in this lecture: What is paging? How can segmentation and paging be combined? How can one speed up address.
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.
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.
W4118 Operating Systems Instructor: Junfeng Yang.
Main Memory CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
Module 9: Memory Management
CS703 - Advanced Operating Systems
Chapter 8: Main Memory.
Chapter 8: Memory Management
Paging and Segmentation
Chapter 8: Main Memory.
Chapter 8: Main Memory.
Storage Management Chapter 9: Memory Management
Operating System Concepts
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
Chapter 8: Main Memory.
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
CS399 New Beginnings Jonathan Walpole.
Virtual Memory Hardware
Lecture 3: Main Memory.
CSE 451: Operating Systems Autumn 2005 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Chapter 8: Memory Management strategies
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 542: Operating Systems
Page Main Memory.
Presentation transcript:

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 all object files into one executable Loader: loads executable in memory ld loader Cache Compile timeruntime

3 What does process look like? heap stack code initialized data address 2^n-1 address >= 0 Process divided into segments, each has: - Code, data, heap (dynamic data) and stack (procedure calls)

4 Processes in Memory We want many of them to coexist Issues: –PowerPoint needs more memory than there is on machine? –What is visual studio tries to access 0x0005? –If PowerPoint is not using enough memory? –If OS needs to expand? OS PowerPoint Visual Studio 0x0000 0x1100 0x1210 0x2300

5 Issues Protection: Errors in process should not affect others Transparency: Should run despite memory size/location gcc virtual address CPU Load Store legal addr? Illegal? Physical address Physical memory fault data Translation box (MMU) How to do this mapping?

6 Scheme 1: Load-time Linking Link as usual, but keep list of references At load time: determine the new base address –Accordingly adjust all references (addition) Issues: handling multiple segments, moving in memory 0x1000 static a.out 0x3000 0x4000 OS jump 0x2000jump 0x5000 0x6000 jump 0x2000

7 Scheme 2: Execution-time Linking Use hardware (base + limit reg) to solve the problem –Done for every memory access –Relocation: physical address = logical (virtual) address + base –Protection: is virtual address < limit? –When process runs, base register = 0x3000, bounds register = 0x2000. Jump addr = 0x x3000 = 0x5000 0x1000 a.out 0x3000 0x4000 OS a.out jump 0x2000 0x6000 Base: 0x3000 Limit: 0x2000 MMU

8 Dynamic Translation Memory Management Unit in hardware –Every process has its own address space CPU MMU logical addrs memory Physical addrs

9 Logical and Physical Addresses Logical Address View Physical Address View MMU OS

10 Scheme 2: Discussion Pro: –cheap in terms of hardware: only two registers –cheap in terms of cycles: do add and compare in parallel Con: only one segment –prob 1: growing processes. How to expand gcc? –prob 2: how to share code and data?? how can Word copies share code? –prob 3: how to separate code and data? A solution: multiple segments –“segmentation” gcc p2 Free space p3 gcc Word2 Word1

11 Segmentation Processes have multiple base + limit registers Processes address space has multiple segments –Each segment has its own base + limit registers –Add protection bits to every segment gcc Text seg r/o Stack seg r/w 0x1000 0x3000 0x5000 0x6000 Real memory 0x2000 0x8000 0x6000 Base&Limit? How to do the mapping?

12 Types of Segments Each “file” of a program (or library) typically results in –An associated code segment (instructions) –The “initialized” data segment for that code –The zeroed part of the data segment (“bss”) Programs also have –One heap segment – grows “upward” –A stack segment for each active thread (grows down; all but first have a size limit)

13 Lots of Segments Bottom line: a single process might have a whole lot of active segments! –And it can add them while it runs, for example by linking to a DLL or forking a thread –Address space is a big range with chunks of data separated by gaps It isn’t uncommon for a process on a modern platform to have hundreds of segments in memory…

14 Mapping Segments Segment Table –An entry for each segment –Is a tuple Each memory reference indicates segment and offset Virtual addr Seg# offset Seg table Prot base len r 0x mem seg x1000 ? yes no fault

15 Segmentation Example If first two bits are for segments, next 12 for offset where is 0x0240? 0x1108? 0x265c? 0x3002? 0x1700? Seg base bounds rw 0 0x4000 0x6ff x0000 0x4ff x3000 0xfff x4000 0x3000 0x2000 0x1500 0x1000 0x0700 0x0000 logical physical 0x4700 0x4000 0x3000 0x500 0x0

16 Segmentation: Discussion Advantages: –Allows multiple segments per process –Easy to allow sharing of code –Do not need to load entire process in memory Disadvantages: –Extra translation overhead: Memory & speed –An entire segment needs to reside contiguously in memory!  Fragmentation

17 Fragmentation “The inability to use free memory” External Fragmentation: –Variable sized pieces  many small holes over time Internal Fragmentation: –Fixed sized pieces  internal waste if entire piece is not used gcc emacs doom stack allocated Unused (“internal fragmentation”) External fragmentation Word ??

18 Paging Divide memory into fixed size pieces –Called “frames” or “pages” Pros: easy, no external fragmentation gcc emacs internal frag Pages typical: 4k-8k

19 Mapping Pages If 2 m virtual address space, 2 n page size  (m - n) bits to denote page number, n for offset within page Translation done using a Page Table Virtual addr VPN page offset (12bits) page table Prot VPN PPN r 3 1 mem seg 128 0x1000 ((1<<12)|128) “invalid” ?PPN

20 Paging: Hardware Support Entire page table (PT) in registers –PT can be huge ~ 1 million entries Store PT in main memory –Have PTBR point to start of PT –Con: 2 memory accesses to get to any physical address Use Translation Lookaside Buffers (TLB): –High speed associative memory –Basically a cache for PT entries

21 Paging: Discussion Advantages: –No external fragmentation –Easy to allocate –Easy to swap, since page size usually same as disk block size Disadvantages: –Space and speed One PT entry for every page, vs. one entry for contiguous memory for segmentation 0xFFFF0x0000 Page table B=0x0,len=0xffff

22 Size of the page Small page size: –High overhead: What is size of PT if page size is 512 bytes, and 32-bit addr space? Large page size: –High internal fragmentation page size Internal frag & writeback cost Overhead & locality More

23 Paging + Segmentation Paged segmentation –Handles very long segments –The segments are paged Segmented Paging –When the page table is very big –Segment the page table –Let’s consider System 370 (24-bit address space) Seg #page # (8 bits)page offset (12 bits) (4 bits)

24 Segmented Paging Example Base bound prot 0x2000 0x14 R 0x0000 0x00 0x1000 0x0d RW Segment table 0x001f 0x0011 0x2020 … 0x0003 0x002a 0x0013 0x2000 … 0x000c 0x0007 0x1020 … 0x004 0x00b 0x006 0x1000 Table entry addresses Page table (2-byte entries) 0x read? 0x104c84 read? 0x read? 0x write? Seg 2: page 2, 0x1004, addr = 0x4016 Seg 1: page 4, protection error Seg 0, page 0x11, addr = 0x1f424 Seg 2, page 0x10, bounds violation Seg 2: page 2, 0x1004, addr = 0x4016 Seg 1: page 4, protection error Seg 0, page 0x11, addr = 0x1f424 Seg 2, page 0x10, bounds violation

25 Handling PT size Segmented Paging removes need for contiguous alloc OS maintains one copy of PT for every process –And a global copy of all frames Other approaches: –Hierarchical Paging: Page the page table –Hashed Page Table: Each entry maps to linked list of pages –Inverted Page Table: Map from Frame to (VA, process) instead of VA to frame per process