Memory Management Questions answered in this lecture: How do processes share memory? What is static relocation? What is dynamic relocation? What is segmentation?

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Part IV: Memory Management
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Memory Protection: Kernel and User Address Spaces  Background  Address binding  How memory protection is achieved.
Chapter 15 Address Translation Chien-Chung Shen CIS, UD
Memory Management Chapter 7.
OS Memory Addressing.
CS 311 – Lecture 21 Outline Memory management in UNIX
Operating Systems CMPSCI 377 Lecture 11: Memory Management
Lecture 11: Memory Management
Multiprocessing Memory Management
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 2010.
CMSC 414 Computer and Network Security Lecture 9 Jonathan Katz.
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Memory ManagementCS-502 Fall Memory Management CS-502 Operating Systems Fall 2006 (Slides include materials from Operating System Concepts, 7 th.
Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Memory Management Chapter 5.
Lecture 9: SHELL PROGRAMMING (continued) Creating shell scripts!
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Memory Management CSCI 444/544 Operating Systems Fall 2008.
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Memory Management -1 Background Swapping Memory Management Schemes
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
1 Memory Management Memory Management COSC513 – Spring 2004 Student Name: Nan Qiao Student ID#: Professor: Dr. Morteza Anvari.
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 11 Page 1 CS 111 Online Memory Management: Paging and Virtual Memory CS 111 On-Line MS Program Operating Systems Peter Reiher.
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.
PA0 due 60 hours. Lecture 4 Memory Management OSTEP Virtualization CPU: illusion of private CPU RAM: illusion of private memory Concurrency Persistence.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Processes Questions answered in this lecture: What is a process? How does the dispatcher context-switch between processes? How does the OS create a new.
Operating Systems Lecture 14 Segments Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software Engineering.
Operating System Structure A key concept of operating systems is multiprogramming. –Goal of multiprogramming is to efficiently utilize all of the computing.
12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam King,
NETW3005 Memory Management. Reading For this lecture, you should have read Chapter 8 (Sections 1-6). NETW3005 (Operating Systems) Lecture 07 – Memory.
Memory Management Continued Questions answered in this lecture: What is paging? How can segmentation and paging be combined? How can one speed up address.
8.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Fragmentation External Fragmentation – total memory space exists to satisfy.
OS Memory Addressing. Architecture CPU – Processing units – Caches – Interrupt controllers – MMU Memory Interconnect North bridge South bridge PCI, etc.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
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 Chapter 5 Advanced Operating System.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Processes Chapter 3. Processes in Distributed Systems Processes and threads –Introduction to threads –Distinction between threads and processes Threads.
W4118 Operating Systems Instructor: Junfeng Yang.
1 CMSC Memory Management (Cont’d) Segmentation, Virtual Memory OSTEP Book (See Schedule Page) Chapter
W4118 Operating Systems Instructor: Junfeng Yang.
Introduction to Operating Systems
Virtualization Virtualize hardware resources through abstraction CPU
Segmentation COMP 755.
Outline Paging Swapping and demand paging Virtual memory.
COMBINED PAGING AND SEGMENTATION
Chien-Chung Shen CIS/UD
x86 segmentation, page tables, and interrupts
Instructors: Haryadi Gunawi
Chapter 8: Main Memory.
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
The Operating System Memory Manager
Main Memory Background Swapping Contiguous Allocation Paging
Memory Management Tasks
Lecture 3: Main Memory.
Lecture 7: Flexible Address Translation
COMP755 Advanced Operating Systems
Presentation transcript:

Memory Management Questions answered in this lecture: How do processes share memory? What is static relocation? What is dynamic relocation? What is segmentation? UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department CS 537 Introduction to Operating Systems Andrea C. Arpaci-Dusseau Remzi H. Arpaci-Dusseau

Motivation for Multiprogramming Uniprogramming: One process runs at a time User Process OS Physical Memory 0 2 n -1 Stack Code Heap Address Space Disadvantages: Only one process runs at a time Process can destroy OS

Multiprogramming Goals Sharing Several processes coexist in main memory Cooperating processes can share portions of address space Transparency Processes are not aware that memory is shared Works regardless of number and/or location of processes Protection Cannot corrupt OS or other processes Privacy: Cannot read data of other processes Efficiency Do not waste CPU or memory resources Keep fragmentation low

Static Relocation Goal: Allow transparent sharing - Each address space may be placed anywhere in memory OS finds free space for new process Modify addresses statically (similar to linker) when load process OS Process 2 Process 1 Process 3 Advantages Requires no hardware support

Discussion of Static Relocation Disadvantages No protection –Process can destroy OS or other processes –No privacy Address space must be allocated contiguously –Allocate space for worst-case stack and heap –What type of fragmentation? Cannot move address space after it has been placed –May not be able to allocate new process –What type of fragmentation?

Dynamic Relocation Goal: Protect processes from one another Requires hardware support Memory Management Unit (MMU) MMU dynamically changes process address at every memory reference Process generates logical or virtual addresses Memory hardware uses physical or real addresses CPU MMU Memory Process runs here OS can control MMU Logical address Physical address

Hardware Support for Dynamic Relocation Two operating modes Privileged (protected, kernel) mode: OS runs –When enter OS (trap, system calls, interrupts, exceptions) –Allows certain instructions to be executed Can manipulate contents of MMU –Allows OS to access all of physical memory User mode: User processes run –Perform translation of logical address to physical address MMU contains base and bounds registers base: start location for address space bounds: size limit of address space

Implementation of Dynamic Relocation Translation on every memory access of user process MMU compares logical address to bounds register –if logical address is greater, then generate error MMU adds base register to logical address to form physical address basemodebounds registers 32 bits 1 bit mode = user? < bounds? no yes + base error logical address physical address

Example of Dynamic Relocation What are the physical addresses for the following 16-bit logical addresses? Process 1: base: 0x4320, bounds: 0x2220 0x0000: 0x1110: 0x3000: Process 2: base: 0x8540, bounds: 0x3330 0x0000: 0x1110: 0x3000: Operating System 0x0000:

Managing Processes with Base and Bounds Context-switch Add base and bounds registers to PCB Steps –Change to privileged mode –Save base and bounds registers of old process –Load base and bounds registers of new process –Change to user mode and jump to new process What if don’t change base and bounds registers when switch? Protection requirement User process cannot change base and bounds registers User process cannot change to privileged mode

Base and Bounds Discussion Advantages Provides protection (both read and write) across address spaces Supports dynamic relocation –Can move address spaces –Why might you want to do this??? Simple, inexpensive implementation –Few registers, little logic in MMU Fast –Add and compare can be done in parallel Disadvantages Each process must be allocated contiguously in physical memory –Must allocate memory that may not be used by process No partial sharing: Cannot share limited parts of address space

Segmentation Divide address space into logical segments Each segment corresponds to logical entity in address space –code, stack, heap Each segment can independently: be placed separately in physical memory grow and shrink be protected (separate read/write/execute protection bits)

Segmented Addressing How does process designate a particular segment? Use part of logical address –Top bits of logical address select segment –Low bits of logical address select offset within segment What if small address space, not enough bits? Implicitly by type of memory reference Special registers

Segmentation Implementation SegmentBaseBoundsR W 00x20000x06ff1 0 10x00000x04ff1 0 20x30000x0fff1 30x00000xffff0 MMU contains Segment Table (per process) Each segment has own base and bounds, protection bits Example: 14 bit logical address, 4 segments Translate logical addresses to physical addresses: 0x0240: 0x1108: 0x265c: 0x3002:

Discussion of Segmentation Advantages Enables sparse allocation of address space –Stack and heap can grow independently –Heap: If no data on free list, dynamic memory allocator requests more from OS (e.g., UNIX: malloc calls sbrk()) –Stack: OS recognizes reference outside legal segment, extends stack implicitly Different protection for different segments –Read-only status for code Enables sharing of selected segments Supports dynamic relocation of each segment Disadvantages Each segment must be allocated contiguously –May not have sufficient physical memory for large segments