Memory Management. CSE 2431: Introduction to Operating Systems Reading: , [OSC]

Similar documents
12: Memory Management

Preview. Memory Management

Memory Management. Reading: Silberschatz chapter 9 Reading: Stallings. chapter 7 EEL 358

UNIT III MEMORY MANAGEMENT

8: Memory Management

CS370 Operating Systems

Chapter 9 Real Memory Organization and Management

Chapter 9 Real Memory Organization and Management

Memory Management. Memory Management

Memory management OS

Process. Memory Management

Memory management. Knut Omang Ifi/Oracle 10 Oct, 2012

Motivation. Memory Management. Memory Management. Computer Hardware Review

Process. One or more threads of execution Resources required for execution. Memory (RAM) Others

Memory management: outline

Memory management: outline

OPERATING SYSTEMS. After A.S.Tanenbaum, Modern Operating Systems 3rd edition Uses content with permission from Assoc. Prof. Florin Fortis, PhD

Memory: Overview. CS439: Principles of Computer Systems February 26, 2018

Process. One or more threads of execution Resources required for execution

Performance of Various Levels of Storage. Movement between levels of storage hierarchy can be explicit or implicit

Process. One or more threads of execution Resources required for execution. Memory (RAM) Others

Memory Management. COMP755 Advanced Operating Systems

Operating Systems (2INC0) 2017/18

Memory Management. Memory Management Requirements

Memory Management (1) Memory Management

Memory Management Basics

Memory Management (1) Memory Management. CPU vs. memory. No.8. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

CS420: Operating Systems

Operating Systems Memory Management. Mathieu Delalandre University of Tours, Tours city, France

The Memory Management Unit. Operating Systems. Autumn CS4023

Memory Management. Memory Management

Main Memory (Part I)

3. Memory Management

Chapter 7 Memory Management

ECE 598 Advanced Operating Systems Lecture 10

Chapter 4 Memory Management. Memory Management

Operating System Support

Lecture 7. Memory Management

Memory Management. Jo, Heeseung

Operating Systems and Computer Networks. Memory Management. Dr.-Ing. Pascal A. Klein

Requirements, Partitioning, paging, and segmentation

Memory Management. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

CS450/550 Operating Systems

Objectives and Functions Convenience. William Stallings Computer Organization and Architecture 7 th Edition. Efficiency

CSE325 Principles of Operating Systems. Memory. David P. Duggan. March 6, 2010

General Objective:To understand the basic memory management of operating system. Specific Objectives: At the end of the unit you should be able to:

CS399 New Beginnings. Jonathan Walpole

Memory management. Requirements. Relocation: program loading. Terms. Relocation. Protection. Sharing. Logical organization. Physical organization

Memory Management. Today. Next Time. Basic memory management Swapping Kernel memory allocation. Virtual memory

Memory Management. Chapter 4 Memory Management. Multiprogramming with Fixed Partitions. Ideally programmers want memory that is.

Operating Systems, Fall

Operating Systems, Fall

Background. Contiguous Memory Allocation

Last Class: Deadlocks. Where we are in the course

Operating Systems. Memory Management. Lecture 9 Michael O Boyle

MEMORY MANAGEMENT: Real Storage. Unit IV

Memory Management. Frédéric Haziza Spring Department of Computer Systems Uppsala University

MEMORY MANAGEMENT. Jo, Heeseung

Chapter 8: Memory Management. Background Swapping Contiguous Allocation Paging Segmentation Segmentation with Paging

Operating Systems Lecture 5: Memory Management I

C06: Memory Management

Compile: compiler. Load: loader. compiler linker loader memory. source object load code module module 2

Memory and multiprogramming

4.1 Paging suffers from and Segmentation suffers from. Ans

Memory Management (Chaper 4, Tanenbaum)

Memory management. Last modified: Adaptation of Silberschatz, Galvin, Gagne slides for the textbook Applied Operating Systems Concepts

In multiprogramming systems, processes share a common store. Processes need space for:

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

Chapter 8: Memory Management. Operating System Concepts with Java 8 th Edition

4 MEMORY MANAGEMENT 4.1 BASIC MEMORY MANAGEMENT

Chapter 3 - Memory Management

Chapter 8: Main Memory

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

Memory Management (Chaper 4, Tanenbaum)

COMPUTER SCIENCE 4500 OPERATING SYSTEMS

Chapter 8: Memory-Management Strategies

SMD149 - Operating Systems - Memory

Last class: Today: Deadlocks. Memory Management

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

Requirements, Partitioning, paging, and segmentation

Chapters 9 & 10: Memory Management and Virtual Memory

Chapter 7: Main Memory. Operating System Concepts Essentials 8 th Edition

Course Outline. Processes CPU Scheduling Synchronization & Deadlock Memory Management File Systems & I/O Distributed Systems

Chapter 4 Memory Management

Memory Management Virtual Memory

Goals of memory management

Chapter 4: Memory Management. Part 1: Mechanisms for Managing Memory

Chapter 1: Introduction. Operating System Concepts 8th Edition,

MEMORY MANAGEMENT/1 CS 409, FALL 2013

Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses.

Operating systems. Part 1. Module 11 Main memory introduction. Tami Sorgente 1

Course: Operating Systems Instructor: M Umair. M Umair

Topics: Memory Management (SGG, Chapter 08) 8.1, 8.2, 8.3, 8.5, 8.6 CS 3733 Operating Systems

CSC 369 Operating Systems

Operating System 1 (ECS-501)

Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation

CHAPTER 8: MEMORY MANAGEMENT. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

Chapter 8: Main Memory. Operating System Concepts 9 th Edition

CPE300: Digital System Architecture and Design

Goals of Memory Management

Transcription:

Memory Management CSE 2431: Introduction to Operating Systems Reading: 8.1 8.3, [OSC] 1

Outline Basic Memory Management Swapping Variable Partitions Memory Management Problems 2

Basic Memory Management Storage Hierarchy Memory Management Problems Fixed Partitions for Multiprogramming Variable Sized Partitions Memory Allocation Strategies 3

Storage Hierarchy Cost $600 a chip $10-2 per byte $10-4 per byte $10-8 per byte CPU Reg Cache Memory Size 2 13 bytes 32 64 bits 2 27 bytes 4 128 words 2 30 bytes 512 16K words Secondary Storage 2 40 bytes 4

General Memory Problem Limited (expensive) physical resources: Main memory E.g. Windows Vista recommends 1G and prefers 2G RAM We want to use it as efficiently as possible Abundant, slower resources: Disk OS needs to provide an abstraction of memory hierarchy to user level applications 5

Responsibilities of Memory Manager Manage memory hierarchy Monitor used and free memory Allocate memory to processes Reclaim (De-allocate) memory Swapping between main memory and disk 6

Scenarios of Memory Management Problems One program, the size is less than memory size The simplest case One program, using lots of memory Can you only keep part of the program in memory? Many programs, total size is less than memory size Technically possible to pack them together Will programs know about each other s existence? Lots of programs, total size exceeds memory size What programs are in memory, and how to decide? 7

Mono-Programming No Swapping Run one process at a time simplest possible memory management scheme Memory is shared only between OS and the process. Three different ways to organize memory User Program OS in RAM 0xFFF 0 OS in ROM User Program Device drivers in ROM User Program OS in RAM 8

Overlaying Used when the process memory requirement exceeds the physical memory space Secondary Storage 0K 5k 7k 12k Main Program Overlay Manager Overlay Area Overlay 1 Overlay 2 Overlay 3 9

Multiprogramming with Fixed Partitions Divide memory into n (possibly unequal) partitions. Problem: Internal Fragmentation 0k 4k 16k 64k Free Space 128k 10

Fixed Partition Allocation Separate input queue for each partition Requires sorting the incoming jobs and putting them into separate queues Problems? One single input queue for all partitions. Find a job for fitting in an available partition Available Fit Best Fit Problems? 11

Problems? Partition 4 800K 700K Partition 4 Partition 3 Partition 3 Partition 2 400K Partition 2 Partition 1 OS 200K 100K 0 Partition 1 OS 12

Relocation Correct starting address when a program should start in the memory Different jobs will run at different addresses When a program is linked, the linker must know at what address the program will begin in memory. Logical addresses, Virtual addresses Logical address space, range (0 to max) Physical addresses, Physical address space range (R+0 to R+max) for base value R. User program never sees the real physical addresses Who translates virtual to physical addresses? Program rewriting at loading time Help from relocation registers at execution time 13

Relocation Register Base Register BA CPU Instruction Address Logical Address MA + Physical Address MA+BA Memory 14

Protection Problem: How to prevent a malicious process to write or jump into other user's or OS partitions Solutions: Memory protection code Base bounds registers 15

Base Bounds Registers CPU Address Bounds Register Base Register Logical Address LA Memory Address MA Base Address BA < + Physical Address PA Base Address MA+BA Memory Limit Address Fault 16

Review Basic Memory Management Memory Manager s Responsibilities Mono-Programming Multi-Programming with Fixed Partitions Internal fragmentation Relocation and Protection 17

Memory Management (More ) Batch System Multiprogramming with fixed partitions In the memory until job finishes Keep CPU busy Timesharing Systems Not enough memory to hold all active processes Swapping (whole process) Virtual memory (partial process) 18

Swapping Move the whole process to/from disk Allows several processes to share a fixed partition Processes that grow can be swapped out and swapped back in a bigger partition 19

Outline Basic Memory Management Swapping Variable Partitions Memory Management Problems 20

Swapping (1) Monitor Disk User Partition Job 1 21

Swapping (2) Monitor Job 1 User Partition Disk Job 1 22

Swapping (3) Monitor Job 1 User Partition Disk Job 1 Job 2 23

Swapping (4) Monitor Job 2 User Partition Disk Job 1 Job 2 24

Swapping (5) Monitor Job 2 User Partition Disk Job 1 Job 2 25

Swapping (6) Monitor Job 1 User Partition Disk Job 1 Job 2 26

Outline Basic Memory Management Swapping Variable Partitions Memory Management Problems 27

Variable Partitions and Fragmentation 1 2 3 4 5 Monitor Job 1 Job 2 Job 3 Job 4 Free Monitor Job 1 Job 3 Job 4 Free Monitor Job 1 Job 5 Job 3 Job 4 Free Monitor Job 3 Job 4 Free Job 5 Job 6 Monitor Job 7 Job 5 Job 3 Job 8 Job Free 6 Fixed Partitions Variable Partitions External Fragmentation How to solve it? 28

Compaction What is it? What does it looks like? Assumes all programs are relocatable Processes must be suspended during compaction Need be done only when fragmentation gets very bad 5 6 7 8 9 Monitor Job 7 Job 5 Job 3 Job 8 Job Free 6 Monitor Job 7 Job 5 Job 3 Job 8 Job Free 6 Monitor Job 7 Job 5 Job 3 Job 8 Job Free 6 Monitor Job 7 Job 5 Job 3 Job 8 Job Free 6 Monitor Job 7 Job 5 Job 3 Job 8 Job 6 Free 29

Outline Basic Memory Management Swapping Variable Partitions Memory Management Problems 30

Memory Management with Bitmaps Use bitmaps for memory status (free or allocated) Memory is divided into allocation units. One allocation unit corresponds to 1bit in the bitmap 0: free, 1: allocated Size of allocation unit The smaller the allocation unit, the larger the bitmap. Problem: allocation When a new process arrives, the manager must find consecutive 0 bits in the map. Searching a bitmap for a run of a given length is a slow operation. 1 0 1 0 1 0 0 0 1 0 1 0 0 1 0 31

Memory Management with Linked Lists Use a linked list of allocated and free memory segments (called hole) Sorted by the address or by the size Four neighbor combinations for the terminating process X 32

Memory Allocation Strategies Best Fit Uses the hole whose size is equal to the need, or if none is equal, the hole that is larger but closest in size. Problem: Creates small holes that can't be used. First Fit Uses the first available hole whose size is sufficient to meet the need. Problem: Creates average size holes. Next Fit Minor variation of first fit: search from the last stopped place. Problem: slightly worse performance than first fit. Worst Fit Uses the largest available hole. Problem: Gets rid of large holes making it difficult to run large programs. Quick Fit Maintains separate lists of holes for some of the more common sizes requested. When a request comes for placement it finds the closest fit. A very fast scheme, but merge is expensive. If merge is not done, memory will quickly fragment in a large number of holes into which no processes fit. 33

How Bad Is Fragmentation? Statistical arguments - Random sizes First-fit Given N allocated blocks, 0.5*N blocks will be lost because of fragmentation Known as 50% RULE 34

Memory Management Problems Fixed partitions Suffer from internal fragmentation Variable partitions Suffer from external fragmentation Compaction Suffer from overhead Overlays Painful for programmers Swapping Requires writing to disk sectors 35

Summary Basic Memory Management Swapping Variable Partitions Memory Management Problems 36