Chapter 8 Main Memory.

Slides:



Advertisements
Similar presentations
Chapter 7 Memory Management
Advertisements

Part IV: Memory Management
Memory Management Chapter 7.
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable supply of ready processes to.
Allocating Memory.
Chapter 7 Memory Management
Chapter 7 Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z. ©2009, Prentice.
CS 311 – Lecture 21 Outline Memory management in UNIX
Chapter 7 Memory Management
Memory Management Chapter 7 B.Ramamurthy. Memory Management Subdividing memory to accommodate multiple processes Memory needs to allocated efficiently.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Memory Management Chapter 5.
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 7 Memory Management
1 Lecture 8: Memory Mangement Operating System I Spring 2008.
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
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 Chapter 7.
Memory Management. Process must be loaded into memory before being executed. Memory needs to be allocated to ensure a reasonable supply of ready processes.
Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Dr.
Chapter 7 Memory Management
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
Subject: Operating System.
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.
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
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 31 Memory Management.
Memory Management Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are only storage.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
1 Memory Management n In most schemes, the kernel occupies some fixed portion of main memory and the rest is shared by multiple processes.
2010INT Operating Systems, School of Information Technology, Griffith University – Gold Coast Copyright © William Stallings /2 Memory Management.
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.
Main Memory CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
Memory Management Chapter 7.
Chapter 7 Memory Management
Memory Management Chapter 7.
Memory Management.
ITEC 202 Operating Systems
Chapter 8: Main Memory.
Real Memory Management
Main Memory Management
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.
Multistep Processing of a User Program
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
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.
Operating System Chapter 7. Memory Management
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.
Operating Systems: Internals and Design Principles, 6/E
OPERATING SYSTEMS MEMORY MANAGEMENT BY DR.V.R.ELANGOVAN.
Chapter 7 Memory Management
Page Main Memory.
Presentation transcript:

Chapter 8 Main Memory

Announcement Reading assignment: Finish reading Chapter 8.1-8.6 by next Monday

Given Credit Where It is Due Some of the lecture notes are borrowed from Dr. 柯皓仁 at National Chiao Tung University, Taiwan One slide is borrowed from Dr. Hugh C. Lauer at Worcester Polytechnic Institute I have modified them and added new slides

Process Execution Where is a process located when it is executed on a CPU? In a multiprogramming environment, there are often more than one user processes in the main memory

Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable supply of ready processes to consume available processor time

Memory Management Requirements Protection Processes should not be able to reference memory locations in another process without permission Sharing Allow several processes to access the same portion of memory E.g., if several processes are executing the same program, better to allow each process access to the same copy of the program rather than have their own separate copy

Memory Management Requirements Relocation Programmer often does not know where the program will be placed in memory when it is executed While the program is executing, it may be swapped to disk and returned to main memory at a different location (relocated) Memory references in the code must be translated to actual physical memory address

Addressing Requirement The processor hardware and operating system software must be able to translate the memory references found in the code of the program into actual physical memory addresses, reflecting the current location of the program in the main memory.

Background Program must be brought into memory and placed within a process for it to be executed Input (job) queue – collection of processes on the disk that are waiting to be brought into memory for execution User programs go through several steps before being executed

Steps for Loading a Process in Memory System Library static linking The linker combines object modules into a single executable binary file (load module) The loader places the load module in physical memory Linking: combine all the object modules of a program into a binary program image System Library dynamic linking

The Linking Function Object Modules Load Module L-1 L-1 Module A L-1 L-1 Module A CALL B Return Length L Module B CALL C Length M Module C Length N Module A JSR “L” Return Module B JSR “L+M” Module C L L+M-1 L+M L+M+N-1 Object Modules M-1 Load Module JSR: Jump to SubRoutine N-1

Address Binding – Mapping from one address space to another Address representation Source program: symbolic (such as count) After compiling: re-locatable address 14 bytes from the beginning of this module After linkage editor, loader or run-time referring: absolute address Physical memory address 2014 2000 int I; goto p1; p1 2250 250 Symbolic Address Re-locatable Address Absolute Address (Physical Memory)

Address Binding (Cont.) Address binding of instructions and data to physical memory addresses can happen at three different stages Compile time: If memory location known a priori, absolute code can be generated Must recompile code if starting location changes MS-DOS .COM-format program

Binding at Compile Time Symbolic Addresses PROGRAM JUMP i LOAD j DATA i j Source Code Absolute Addresses (Physical Memory Addresses) 1024 JUMP 1424 LOAD 2224 1424 2224 Absolute Load Module Compile Link The CPU generates the absolute addresses

Binding at Compile Time (Cont.) Absolute Addresses (Physical Memory Addresses) 1024 JUMP 1424 LOAD 2224 1424 2224 Process Image (Part) Load

Address Binding (Cont.) Address binding of instructions and data to physical memory addresses can happen at three different stages Load time: Must generate re-locatable code if memory location is not known at compile time Physical memory address is fixed at load time Must reload if starting location changes

Binding at Loader Time Symbolic Addresses Source Code PROGRAM JUMP i LOAD j DATA i j Source Code Relative (Relocatable) Addresses JUMP 400 LOAD 1200 400 1200 Relative Load Module Compile Link

Binding at Loader Time (Cont.) Absolute Addresses (Physical Memory Addresses) 1024 JUMP 1424 LOAD 2224 1424 2224 Process Image (Part) Load The CPU generates the absolute addresses

Address Binding (Cont.) Execution time: Binding delayed until run time The process can be moved during its execution from one memory segment to another The CPU generates the relative (virtual) addresses Need hardware support for address maps (e.g., base and limit registers) Most general-purpose OS use this method Relative (Relocatable) Addresses JUMP 400 LOAD 1200 400 1200 MAX =2000

Dynamic Relocation Using a Relocation Register 14000 to 14000+MAX Seen By Memory Unit Generated By CPU 0 to MAX Binding at execution time (when reference is made) Map LA to PA

Logical vs. Physical Address Space The concept of binding a logical address space to a physical address space is central to proper memory management Logical address – generated by the CPU; also referred to as virtual address Physical address – address seen by the memory unit In compile-time and load-time address-binding schemes, logical and physical addresses are the same In execution-time address-binding scheme, logical and physical addresses differ

Memory-Management Unit (MMU) Hardware device that maps virtual to physical address In the simple MMU scheme, the value in the relocation register is added to every address generated by a user process (CPU) at the time it is sent to memory The user program deals with logical addresses; it never sees the real physical addresses

Memory Management Techniques Fixed Partitioning Dynamic Partitioning Simple Paging Simple Segmentation Virtual Memory Paging Virtual Memory Segmentation

Fixed Partitioning Equal-size partitions Any process whose size is less than or equal to the partition size can be loaded into an available partition If all partitions are full, the operating system can swap a process out of a partition Equal-size partitions was used in early IBM’s OS/MFT (Multiprogramming with a Fixed number of Tasks)

Fixed Partitioning Equal-size partitions A program may not fit in a partition. Main memory use is inefficient. Any program, no matter how small, occupies an entire partition This is called internal fragmentation

Dynamic Partitioning Partitions are of variable length and number Process is allocated exactly as much memory as required, no internal fragmentation

Dynamic Partitioning

Dynamic Partitioning Eventually get holes in the memory. This is called external fragmentation

Dynamic Partitioning Must use compaction to shift processes so they are contiguous and all free memory is in one block

Dynamic Partitioning Operating system must decide which free block to allocate to a process Best-fit algorithm Chooses the block that is closest in size to the request Since the smallest block is found for process, the fragmentation of the smallest size is left Memory compaction must be done more often Algorithm speed? Fast or Slow?

Dynamic Partitioning Worst-fit algorithm First-fit algorithm Chooses the block that is largest in size First-fit algorithm Scans memory form the beginning and chooses the first available block that is large enough Fast Next-fit algorithm Scans memory from the location of the last placement and chooses the first available block that is large enough

Contiguous vs. Non-contiguous Memory Allocation The memory management techniques discussed so far all require the physical address space of a process to be contiguous Paging and Segmentation permit the physical address space of a process to be non-contiguous

Paging Partition memory into small equal fixed-size chunks and divide each process into the same size chunks The chunks of a process are called pages The chunks of memory are called frames

Paging Operating system maintains a page table for each process Contains the frame location for each page in the process Memory address consists of a page number and offset within the page

Process and Frames

Process and Frames

Page Table

Logical Addresses

Paging

Comparison What is the advantage of the paging mechanism vs. the fixed partitioning mechanism? Paging leads to smaller internal fragmentations Paging permits the physical address space of a process to be non-contiguous What is the advantage of the paging mechanism vs. the dynamic partitioning mechanisms? Paging has no external fragmentation

In-Class Exercise Consider a simple paging system with the following parameters: 232 bytes of physical memory; page size of 210 bytes; 216 pages of logical address space. A. how many bits are in a logical address? B. how many bytes in a frame? C. how many bits in the physical address specify the frame? D. how many entries in the page table? E. how many bits in each page table entry? Assume each page table entry contains a valid/invalid bit.

In-Class Exercise Consider a simple paging system with the following parameters: 232 bytes of physical memory; page size of 210 bytes; 216 pages of logical address space. A. how many bits are in a logical address? (26) B. how many bytes in a frame? (210) C. how many bits in the physical address specify the frame? (22) D. how many entries in the page table? (216) E. how many bits in each page table entry? Assume each page table entry contains a valid/invalid bit. (23)

Memory Management Techniques Fixed Partitioning Dynamic Partitioning Simple Paging Simple Segmentation Virtual Memory Paging Virtual Memory Segmentation

Segmentation All segments of all programs do not have to be of the same length There is a maximum segment length Addressing consists of two parts - a segment number and an offset Since segments are not equal, segmentation is similar to dynamic partitioning

Logical Addresses

Segmentation

Comparison What is the advantage of the segmentation mechanism vs. the dynamic partitioning mechanism? Segmentation permits the physical address space of a process to be non-contiguous

Appedix

Static Linking and Loading Printf.c Printf.o Static Library gcc ar Linker Memory HelloWorld.c HelloWorld.o Loader a.out (or name of your command) Unix: linker is inside gcc command Loader is part of exec system call

Dynamic Linking The linking of some external modules is done after the creation of the load module (executable file) Windows: external modules are .DLL files Unix: external modules are .SO files (shared library) The load module contains references to external modules which are resolved either at: Loading time (load-time dynamic linking) Run time: when a call is made to a procedure defined in the external module (run-time dynamic linking) OS finds the external module and links it to the load module Check to see if the external module has been loaded into memory Unix: linker is inside gcc command Loader is part of exec system call

Advantages of Dynamic Linking The external module is often an OS utility. Executable files can use another version of the external module without the need of being modified Code sharing: the same external module needs to be loaded in main memory only once. Each process is linked to the same external module Saves memory and disk space

Relocation When program loaded into memory the actual (absolute) memory locations are determined A process may occupy different partitions which means different absolute memory locations during execution (from swapping)

Relocation Compaction will also cause a program to occupy a different partition which means different absolute memory locations

Relocation Bounds register Base register Bounds register These values are set when the process is loaded or when the process is swapped in Base register Starting address for the process Bounds register Ending location of the process These values are set when the process is loaded or when the process is swapped in The value of the base register is added to a relative address to produce an absolute address The resulting address is compared with the value in the bounds register If the address is not within bounds, an interrupt is generated to the operating system