Slide 11-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Slide 11-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11.
11 Memory Management The External View of the Memory Manager Hardware Application Program Application Program File MgrDevice MgrMemory Mgr Process Mgr.
Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.
Slide 11-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11.
ITEC 352 Lecture 27 Memory(4). Review Questions? Cache control –L1/L2  Main memory example –Formulas for hits.
Slide 11-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter Memory Management.
Memory Management Chapter 7.
CS 311 – Lecture 21 Outline Memory management in UNIX
Memory Management. Managing Memory … The Simplest Case The O/S User Program 0 0xFFF … * Early PCs and Mainframes * Embedded Systems One user program at.
1 CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania, Fall 2002 Lecture Note: Memory Management.
Modified from Silberschatz, Galvin and Gagne Lecture 16 Chapter 8: Main Memory.
CS 104 Introduction to Computer Science and Graphics Problems
Memory Management CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Memory Management Chapter 5.
Modified from Silberschatz, Galvin and Gagne Lecture 15 Chapter 8: Main Memory.
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.
A. Frank - P. Weisberg Operating Systems Real Memory Management.
Operating System Concepts
Silberschatz, Galvin and Gagne  Operating System Concepts Multistep Processing of a User Program User programs go through several steps before.
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 9 – Real Memory Organization and Management Outline 9.1 Introduction 9.2Memory Organization.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
Tutorial 6 Memory Management
Tutorial 7 Memory Management presented by: Antonio Maiorano Paul Di Marco.
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.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 8: Main Memory.
Swapping and Contiguous Memory Allocation. Multistep Processing of a User Program User programs go through several steps before being run. Program components.
Memory Management. Process must be loaded into memory before being executed. Memory needs to be allocated to ensure a reasonable supply of ready processes.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 8: Memory Management Strategies.
8.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 8: Memory-Management Strategies Objectives To provide a detailed description.
Memory Management.
Chapter 4 Storage Management (Memory Management).
Operating Systems Memory management. Memory Management List of Topics 1. Memory Management 2. Memory In Systems Design 3. Binding Times 4. Introduction.
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.
Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
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.
Silberschatz and Galvin  Operating System Concepts Module 8: Memory Management Background Logical versus Physical Address Space Swapping Contiguous.
Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
Basic Memory Management 1. Readings r Silbershatz et al: chapters
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
CSC 360, Instructor Kui Wu Memory Management I: Main Memory.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 31 Memory Management.
Memory Management Chapter 5 Advanced Operating System.
2010INT Operating Systems, School of Information Technology, Griffith University – Gold Coast Copyright © William Stallings /2 Memory Management.
COMP 3500 Introduction to Operating Systems Memory Management: Part 1 Dr. Xiao Qin Auburn University Slides.
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.
Main Memory CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
Chapter 8: Main Memory.
Chapter 8 Main Memory.
Main Memory Management
Outline Memory management Segmentation Paging Introduction
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.
Multistep Processing of a User Program
Memory management Igor Radovanović.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
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.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
OPERATING SYSTEMS MEMORY MANAGEMENT BY DR.V.R.ELANGOVAN.
Presentation transcript:

Slide 11-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11

Slide 11-2 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter Memory Management

Slide 11-3 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 The External View of the Memory Manager Hardware Application Program Application Program File MgrDevice MgrMemory Mgr Process Mgr UNIX File MgrDevice MgrMemory Mgr Process Mgr Windows VMQuery() VirtualFree() VirtualLock() ZeroMemory() VirtualAlloc() sbrk() exec() getrlimit() shmalloc()

Slide 11-4 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective Today’s memory manager: –Allocates primary memory to processes –Maps process address space to primary memory –Minimizes access time using cost-effective memory configuration –May use static or dynamic techniques

Slide 11-5 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Storage Hierarchies Less Frequently Used Information More Frequently Used Information

Slide 11-6 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 The Basic Memory Hierarchy CPU Registers Primary Memory (Executable Memory) e.g. RAM Secondary Memory e.g. Disk or Tape More Frequently Used Information Less Frequently Used Information

Slide 11-7 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Contemporary Memory Hierarchy & Dynamic Loading CPU Registers “Main” Memory Rotating Magnetic Memory Optical Memory Sequentially Accessed Memory L1 Cache Memory L2 Cache Memory Secondary Primary (Executable) Larger storage Faster access

Slide 11-8 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Exploiting the Hierarchy Upward moves are (usually) copy operations –Require allocation in upper memory –Image exists in both higher & lower memories Updates are first applied to upper memory Downward move is (usually) destructive –Destroy image in upper memory –Update image in lower memory Place frequently-used info high, infrequently-used info low in the hierarchy Reconfigure as process changes phases

Slide 11-9 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Background

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Binding of instructions and Data to Memory

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Address Binding CNTD Source program references data and instructions using identifiers (e.g. variable names etc.) Compiler translates source program into object module. A collection of object modules is combined using a link editor to produce an absolute module. –Can compiler/linker generate physical addresses? –Actual physical addresses are not known yet. Why Not? –Link editor produce re-locatable code: all addresses are relative to memory address 0 ==> compile-time binding

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Address Binding CNTD When module is loaded in memory for execution the loader, knowing where module is to be loaded in memory, can set the addresses at load time to produce the executable image of the module with physical addresses ==> load time binding – What if module is swapped out of memory? Dynamic Binding: binding is delayed until execution time. At load time, each identifier is associated a relative address. Physical address is computed at execution time by hardware.

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Address Space vs Primary Memory Mapped to object other than memory Process Address Space Hardware Primary Memory

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Creating an Executable Program Source code Source code Compile time: Translate elements Load time: Allocate primary memory Adjust addresses in address space Copy address space from secondary to primary memory Loader Process address space Primary memory C Reloc Object code Reloc Object code Link Edit Link Edit Library code Library code Other objects Other objects Secondary memory Link time: Combine elements

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 A Sample Code Segment... static int gVar;... int proc_a(int arg){... gVar = 7; put_record(gVar);... }

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 The Relocatable Object module Code Segment Relative AddressGenerated Code entryproc_a load=7, R1 0224storeR1, push call‘put_record’ External reference table ‘put_record’ External definition table ‘proc_a’ (symbol table) (last location in the code segment) Data Segment Relative AddressGenerated variable space [Space for gVar variable] (last location in the data segment)

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 The Absolute Program Code Segment Relative AddressGenerated Code 0000(Other modules) entryproc_a load=7, R1 1224storeR1, push call (End of proc_a)... (Other modules) 2334entryput_record (optional symbol table) (last location in the code segment) Data Segment Relative AddressGenerated variable space [Space for gVar variable] (last location in the data segment)

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 The Program Loaded at Location 4000 Relative AddressGenerated Code 0000(Other process’s programs) 4000(Other modules) entryproc_a [Space for gVar variable] load=7, R1 5224storeR1, push call (End of proc_a)... (Other modules) 6334entryput_record (optional symbol table) (last location in the code segment) 7000(first location in the data segment) [Space for gVar variable] (Other process’s programs)

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 C-Style Memory Layout Text Segment Initialized Part Data Segment Initialized Part Data Segment Uninitialized Part Data Segment Uninitialized Part Data Segment Heap Storage Stack Segment Environment Variables, … Environment Variables, …

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Program and Process Address Spaces Absolute Program Address Space 0 4GB 3GB Process Address Space Supervisor Process Address Space User Process Address Space Primary Memory

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Multiprogramming Memory Support Operating System Process 1 Process 3 Process 0 Process 1 Unused In Use 0 A B C D E F G H R0R0 R1R1 R2R2 R3R3 R4R4

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Static Memory Allocation Operating System Process 3 Process 0 Process 2 Process 1 Unused In Use Issue: Need a mechanism/policy for loading p i ’s address space into primary memory pipi

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Fixed-Partition Memory Mechanism Operating System Region 3 Region 2 Region 1 Region 0N0N0 N1N1 N2N2 N3N3 pipi p i needs n i units nini

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Fixed-Partition Memory Best-Fit Operating System Region 3 Region 2 Region 1 Region 0N0N0 N1N1 N2N2 N3N3 pipi Internal Fragmentation Loader must adjust every address in the absolute module when placed in memory

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Fixed-Partition Memory Worst-Fit Operating System Region 3 Region 2 Region 1 Region 0N0N0 N1N1 N2N2 N3N3 pipi

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Fixed-Partition Memory First-Fit Operating System Region 3 Region 2 Region 1 Region 0N0N0 N1N1 N2N2 N3N3 pipi

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Fixed-Partition Memory Next-Fit Operating System Region 3 Region 2 Region 1 Region 0N0N0 N1N1 N2N2 N3N3 pipi P i+1

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Variable Partition Memory Operating System Operating System Process 0 Process 6 Process 2 Process 5 Process 4 Compaction moves program in memory Operating System Process 0 Process 6 Process 2 Process 5 Process 4 External fragmentation Operating System Process 0 Process 1 Process 2 Process 3 Process 4 Loader adjusts every address in every absolute module when placed in memory

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Cost of Moving Programs load R1, 0x F Program loaded at 0x F Program loaded at 0x04000 Must run loader over program again! Consider dynamic techniques

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Moving an Executable Image Executable Program Executable Program Loader Executable Image Executable Image Executable Image Executable Image

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Dynamic Memory Allocation Could use dynamically allocated memory Process wants to change the size of its address space –Smaller  Creates an external fragment –Larger  May have to move/relocate the program Allocate “holes” in memory according to –Best- /Worst- / First- /Next-fit

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Dynamic Address Binding All addresses to data and instructions are made relative to beginning of the module i.e. as if process address space starts at physical address 0. Hardware provides a base register (also called a relocation register). When process is switched to CPU the base register is loaded with the initial address of the module. At run time:

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Dynamic Address Relocation CPU 0x x MAR load R1, 0x x12010 Program loaded at 0x10000  Relocation Register = 0x10000 Program loaded at 0x04000  Relocation Register = 0x04000 Relocation Register Relative Address We never have to change the load module addresses!

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Multiple Segment Relocation Registers CPU Relative Address Code Register + MAR 0x12010 Stack Register Data Register

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Runtime Bound Checking CPU Relative Address Relocation Register + MAR Limit Register <  Interrupt Bound checking is inexpensive to add Provides excellent memory protection

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Special Case: Swapping Special case of dynamic memory allocation Suppose there is high demand for executable memory Equitable policy might be to time-multiplex processes into the memory (also space-mux) Means that process can have its address space unloaded when it still needs memory –Usually only happens when it is blocked

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Swapping Image for p j Image for p i Swap p i out Swap p j in

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Sharing a Portion of the Address Space Process 1 Process 2 Address Space for Process 2 Address Space for Process 1 Primary Memory

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Figure 11 ‑ 26: Multiple Segments Relocation Limit Relocation Limit CPU Executing Process 1 CPU Executing Process 2 Primary Memory Shared Private to Process 1 Private to Process 2

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11 Memory Mgmt Strategies Fixed-Partition used only in batch systems Variable-Partition used everywhere (except in virtual memory) Swapping systems –Popularized in timesharing –Relies on dynamic address relocation –Now dated Dynamic Loading (Virtual Memory) –Exploit the memory hierarchy –Paging -- mainstream in contemporary systems –Segmentation -- the future