Memory Management CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 13: Main Memory (Chapter 8)
Basic Memory Management 1. Readings r Silbershatz et al: chapters
CS 311 – Lecture 21 Outline Memory management in UNIX
1 CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania, Fall 2002 Lecture Note: Memory Management.
Operating Systems CMPSCI 377 Lecture 11: Memory Management
Modified from Silberschatz, Galvin and Gagne Lecture 16 Chapter 8: Main Memory.
Memory Management Chapter 4. Memory hierarchy Programmers want a lot of fast, non- volatile memory But, here is what we have:
Memory Management and Paging CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
CS 104 Introduction to Computer Science and Graphics Problems
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 Chapter 5.
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.
Operating System Concepts
Silberschatz, Galvin and Gagne  Operating System Concepts Multistep Processing of a User Program User programs go through several steps before.
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.
CSCI 315 Operating Systems Design
Review of Memory Management, Virtual Memory CS448.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
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.
SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally MEMORYMANAGEMNT.
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.
1. Memory Manager 2 Memory Management In an environment that supports dynamic memory allocation, the memory manager must keep a record of the usage of.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
Operating Systems Memory management. Memory Management List of Topics 1. Memory Management 2. Memory In Systems Design 3. Binding Times 4. Introduction.
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
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.
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 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 Basics. 2 Program P Basic Memory Management Concepts Address spaces Physical address space — The address space supported by the hardware.
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
NETW3005 Memory Management. Reading For this lecture, you should have read Chapter 8 (Sections 1-6). NETW3005 (Operating Systems) Lecture 07 – Memory.
Slide 11-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11.
Memory management The main purpose of a computer system is to execute programs. These programs, together with the data they access, must be in 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.
Main Memory CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
W4118 Operating Systems Instructor: Junfeng Yang.
Memory Management.
Chapter 2 Memory and process management
Chapter 8: Main Memory.
Chapter 8 Main Memory.
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.
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.
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.
So far… Text RO …. printf() RW link printf Linking, loading
Memory Management-I 1.
Main Memory Background Swapping Contiguous Allocation Paging
CS399 New Beginnings Jonathan Walpole.
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.
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.
Presentation transcript:

Memory Management CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han

Announcements PA #2 due Friday March 18 11:55 pm - note extension of a day Midterms returned after spring break Read chapters 11 and 12

Memory Management CPU ALU PC registers Bus interface I/O Bridge USB Controller Graphics Card I/O Bus Memory Bus System Bus L1 Cache L2 Cache Memory Hierarchy: Code Disk Code Data Stack Fetch and Execute Cycle Main Memory

Memory Management Memory Hierarchy –cache frequently accessed instructions and/or data in local memory that is faster but also more expensive registers L1 Cache (SRAM) L2 Cache (SRAM) Main Memory (DRAM) Disk or Flash Secondary Storage Remote Networked Disks

Main Memory OS Loader Memory Management Code Data Code Data P1 binary P2 binary Disk Logical Address Space of Process P1 Code Data Heap Stack lower limit = 0 upper limit = max Code Data Heap Stack base register OS P2 P3 P1 limit register 3000 upper limit

Memory Management In the previous figure, when the program P1 becomes an active process P1, then the process P1 can be viewed as conceptually executing in a logical address space ranging from 0 to max –In reality, the code and data are stored in physical memory –There needs to be a mapping from logical addresses to physical addresses - memory management unit (MMU) takes care of this Usually, these logical addresses are mapped into physical addresses when the process is loaded into memory –the logical address space becomes mapped into a physical address space –base register keeps track of lower limit of the physical address space –limit register keeps track of size of logical address space –upper limit of physical address space = base register + limit register

Memory Management base and limit registers provide hardware support for a simple MMU –memory access should not go out of bounds. If out of bounds, then this is a segmentation fault so trap to the OS. MMU will detect out-of-bounds memory access and notify OS by throwing an exception Only the OS can load the base and limit registers while in kernel/supervisor mode –these registers would be loaded as part of a context switch

Memory Management MMU needs to check if physical memory access is out of bounds base +limit MMU ≥ ? base yes no Trap to OS/ seg fault valid physical address RAM CPU physical address < ? no Trap to OS/ seg fault

Memory Management MMU also needs to perform run-time mapping of logical/virtual addresses to physical addresses –each logical address is relocated or translated by MMU to a physical address that is used to access main memory/RAM –thus the application program never sees the actual physical memory - it just presents a logical address to MMU CPU base logical addressphysical address RAM MMU base register is also called a relocation register

Memory Management Let’s combine the MMU’s two tasks (bounds checking, and memory mapping) into one figure –since logical addresses can’t be negative, then lower bound check is unnecessary - just check the upper bound by comparing to the limit register CPU base/relocation logical address physical address RAM MMU < ? limit yes no Trap to OS/ seg fault

Memory Management Address Binding –Compile Time: If you know in advance where in physical memory a process will be placed, then compile your code with absolute physical addresses –Load Time: Code is first compiled in relocatable format. Then replace logical addresses in code with physical addresses during loading –e.g. relative address (14 bytes from beginning of this module) is replaced with a physical address (74002) –Run Time/Execution Time: (most modern OS’s do this) Code is first compiled in relocatable format as if executing in its own virtual address space. As each instruction is executed, i.e. at run time, the MMU relocates the virtual address to a physical address using hardware support such as base/relocation registers.

Memory Management Swapping –memory may not be able to store all processes that are ready to run, i.e. that are in the ready queue –Use disk/secondary storage to store some processes that are temporarily swapped out of memory, so that other (swapped in) processes may execute in memory special area on disk is allocated for this backing store. This is fast to access. –If execution time binding is used, then a process can be easily swapped back into a different area of memory. –If compile time or load time binding is used, then process swapping will become very complicated and slow - basically undesirable

P2 Rest of the disk for files P9 P7 backing store Memory Management Swapping: when the OS scheduler wants to run P2, the dispatcher is invoked to see if P2 is in memory. if not, and there is not enough free memory, then swap out some process P k, and swap in P2. list of processes in backing store RAM OS P1 P0 P3 Ready Queue: P0, P1, P3, P2 “Input” Queue: P2, P9, P7 P3 swap out P3 swap in P2 Disk

Memory Management Some difficulties with swapping: –context-switch time of swapping is very slow on the order of tens to hundreds of milliseconds can’t always hide this latency if in-memory processes are blocked on I/O UNIX avoids swapping unless the memory usage exceeds a threshold –fragmentation of main memory becomes a big issue can also get fragmentation of backing store disk –swapping of processes that are blocked or waiting on I/O becomes complicated one rule is to simply avoid swapping processes with pending I/O

Memory Management Allocation –as processes arrive, they’re allocated a space in main memory –over time, processes leave, and memory is deallocated –This results in external fragmentation of main memory, with many small chunks of non- contiguous unallocated memory between allocated processes in memory –OS must find an unallocated chunk in fragmented memory that a process fits into. Multiple strategies: first fit - find the 1 st chunk that is big enough best fit - find the smallest chunk that is big enough worst fit - find the largest chunk that is big enough –this leaves the largest contiguous unallocated chunk for the next process RAM OS P1 P3 unallocated

Memory Management Fragmentation can mean that, even though there is enough overall free memory to allocate to a process, there is not one contiguous chunk of free memory that is available to fit a process’s needs –the free memory is scattered in small pieces throughout RAM Both first-fit and best-fit aggravate external fragmentation, while worst-fit is somewhat better Solution: execute an algorithm that compacts memory periodically to remove fragmentation –only possible if addresses are bound at run-time –expensive operation - takes time to translate the address spaces of most if not all processes, and CPU is unable to do other meaningful work during this compaction