Operating Systems ECE344 Ashvin Goel ECE University of Toronto Memory Management Overview.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

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.
Allocating Memory.
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.
Memory Management Chapter 4. Memory hierarchy Programmers want a lot of fast, non- volatile memory But, here is what we have:
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
CS 104 Introduction to Computer Science and Graphics Problems
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 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 Management Chapter 5.
CS 333 Introduction to Operating Systems Class 9 - Memory Management
1 Lecture 8: Memory Mangement Operating System I Spring 2008.
CS 333 Introduction to Operating Systems Class 9 - Memory Management Jonathan Walpole Computer Science Portland State University.
Memory management. Instruction execution cycle Fetch instruction from main memory Decode instruction Fetch operands (if needed0 Execute instruction Store.
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.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Memory Management Chapter 7.
1 Memory Management Memory Management COSC513 – Spring 2004 Student Name: Nan Qiao Student ID#: Professor: Dr. Morteza Anvari.
CS333 Intro to Operating Systems Jonathan Walpole.
Chapter 7 Memory Management
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.
Ch. 4 Memory Mangement Parkinson’s law: “Programs expand to fill the memory available to hold them.”
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.
Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
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 Memory Management Requirements of memory management system to provide the memory space to enable several processes to execute concurrently to provide.
Chapter 10 Memory Management Introduction Process must be loaded into memory before being executed. Input queue – collection of processes on the.
1 Address Translation Memory Allocation –Linked lists –Bit maps Options for managing memory –Base and Bound –Segmentation –Paging Paged page tables Inverted.
CS 149: Operating Systems March 3 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
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 Basics. 2 Program P Basic Memory Management Concepts Address spaces Physical address space — The address space supported by the hardware.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam King,
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Hardware.
Processes and Virtual Memory
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Implementation.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Mono an multiprogramming.
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.
CHAPTER 3-1, 3-2 MEMORY MANAGEMENT. MEMORY HIERARCHY Small amount of expensive, fast, volatile cache Larger amount of still fast, but slower, volatile.
Memory Management Chapter 5 Advanced Operating System.
Ch. 4 Memory Mangement Parkinson’s law: “Programs expand to fill the memory available to hold them.”
2010INT Operating Systems, School of Information Technology, Griffith University – Gold Coast Copyright © William Stallings /2 Memory Management.
W4118 Operating Systems Instructor: Junfeng Yang.
Memory Management Chapter 7.
Memory management.
From Monoprogramming to multiprogramming with swapping
CSC 322 Operating Systems Concepts Lecture - 12: by
Main Memory Management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
The Operating System Memory Manager
Multistep Processing of a User Program
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.
Memory Management Overview
Virtual Memory Hardware
Lecture 3: Main Memory.
CSE451 Memory Management Introduction Autumn 2002
Operating System Chapter 7. Memory Management
EECE.4810/EECE.5730 Operating Systems
Chapter 8 & 9 Main Memory and Virtual Memory
CSE 542: Operating Systems
Presentation transcript:

Operating Systems ECE344 Ashvin Goel ECE University of Toronto Memory Management Overview

Outline  Introduction to memory management  Managing memory with bitmaps and lists  Simple memory management and fragmentation 2

Introduction to Memory Management  OS needs to manage physical memory o Allocate memory for programs and for itself  Requirements o Isolation: programs should be protected from other programs o Abstraction: programs have the illusion that they have as much memory as their virtual address space o Sharing: programs should be able to share memory with other programs for communication  Goals o Low memory overhead: programs should be able to use as much as memory as possible o Low Performance overhead: CPU should be spend as much time executing programs as possible 3

Programs and Memory Addresses  When a program is written, it uses variable names  When a program runs, it accesses physical memory addresses  Setting up mapping from program variables to memory addresses requires compiler, linker, OS and h/w support 4

Compiler, Linker, OS and H/W  Compiler o Converts program source file to object file o Generates relocatable virtual memory addresses  Linker o Links together multiple object files to single program on disk o Generates absolute virtual memory addresses  OS o Loads program into physical memory o Sets up virtual memory hardware  H/W o Translates virtual memory address to physical address 5

Generating Memory Addresses 6 CompilationLinkerOS Loader main()... foo()... 0 main:... push... jmp foo: Library routines 0 main:... push... jmp foo:... On diskIn memory 1100 main:... push... jmp foo: Library routines 1000 MMU base register

Managing Memory  Boot loader, loads OS code and data in low memory  After that, OS needs to track the usage of the rest of the physical memory  OS tracks what memory is allocated (used) or free (unused), similar to heap o addr = kmalloc(size)  Allocate contiguous memory of a given size  Address of allocated memory is returned o kfree(addr)  Program frees memory previously allocated at address addr  Two common techniques for managing memory o Bitmaps, linked lists 7

Managing Memory With Bitmaps  A Bitmap is a long bit string o One bit for every chunk of memory  1 = in use  0 = free  Size of chunk determines size of bitmap o Chunk size = 32 bits  Overhead for bitmap = 1/(32 + 1) = 3% o Chunk size = 4 KB  Overhead for bitmap = 1/(4 * 1024 * 8 + 1) = 1 /  Larger chunk size o Lower overhead o Wastes more space (on average, half chunk size), called internal fragmentation 8

Bitmap Operations  mem = allocate(K) o Search bitmap for K consecutive 0 bits o Set the K bits to 1 o Cost: linear search  free(mem, K) o Determine starting bit in bitmap based on memory address o Set next K bits to 0 9

Managing Memory With Linked Lists  Keep a list of elements, one for each allocated or free region of memory  Each element has the following information o Allocated or free region (hole) o Starting address of memory o Length of region o Pointer to next element of list 10 0 A A A A A

Managing Memory With Linked Lists  mem = allocate(K) o Search linked list for a hole (free region) with size >= K o When size > K, break hole into allocated region, smaller hole  free(mem, K) o Determine region based on memory address o Convert allocated region into hole o Merge with adjacent hole to avoid small holes 11

Searching Linked Lists  Could use a separate allocated and free list  First Fit: Start searching at the beginning of the list  Best Fit: Find the smallest hole that will work o Tends to create lots of little holes  Quick Fit: Keep separate lists for common sizes o Efficient but more complicated implementation 12

Simple Memory Management  A basic memory management system assigns each program a contiguous region in physical memory o Region size depends on program size o OS occupies one region  Problems o Internal fragmentation: program doesn’t use entire region o External fragmentation: a large enough region cannot be allocated to the program, even if enough memory is available  Can use compaction, i.e., move processes periodically to collect all free space into one hole, expensive o Allocating additional memory is expensive: can’t grow region, requires copying entire program into another larger region 13

Summary  OS needs to allocate physical memory to programs (and to itself) with low overhead o Bitmaps, linked lists are two methods for managing memory o Programs uses similar techniques for managing their heap  A simple memory management scheme allocates contiguous physical memory to programs o Makes it hard to grow programs o Wastes memory due to internal and external fragmentation 14

Think Time  What is the difference between a virtual and a physical memory address?  Why is hardware support required for address translation?  How does the OS manage memory using bitmaps? using lists? Under which conditions is each approach preferable?  What is internal and external fragmentation? 15