Memory Management Basics

Similar documents
Memory management basics (1) Requirements (1) Objectives. Operating Systems Part of E1.9 - Principles of Computers and Software Engineering

Memory Management Outline. Background Swapping Contiguous Memory Allocation Paging Segmentation Segmented Paging

OPERATING SYSTEM - MEMORY MANAGEMENT

CS5460: Operating Systems

Chapter 7 Memory Management

Chapter 7 Memory Management

The Deadlock Problem. Deadlocks. Deadlocks. Bridge Crossing Example

Memory Allocation. Static Allocation. Dynamic Allocation. Memory Management. Dynamic Allocation. Dynamic Storage Allocation

& Data Processing 2. Exercise 3: Memory Management. Dipl.-Ing. Bogdan Marin. Universität Duisburg-Essen

Virtual vs Physical Addresses

OPERATING SYSTEMS MEMORY MANAGEMENT

Operating Systems, 6 th ed. Test Bank Chapter 7

Segmentation and Fragmentation

CS 61C: Great Ideas in Computer Architecture Virtual Memory Cont.

Chapter 12. Paging an Virtual Memory Systems

Dynamic Memory Management for Embedded Real-Time Systems

Page 1 of 5. IS 335: Information Technology in Business Lecture Outline Operating Systems

System Software Prof. Dr. H. Mössenböck

Memory unit sees only the addresses, and not how they are generated (instruction counter, indexing, direct)

Lecture 10: Dynamic Memory Allocation 1: Into the jaws of malloc()

How To Write A Page Table

W4118: segmentation and paging. Instructor: Junfeng Yang

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

Free-Space Management

Disk Space Management Methods

Memory Management 1. Memory Management. Multitasking without memory management is like having a party in a closet.

Memory Management CS 217. Two programs can t control all of memory simultaneously

Memory management. Chapter 4: Memory Management. Memory hierarchy. In an ideal world. Basic memory management. Fixed partitions: multiple programs

Chapter 3: Operating-System Structures. System Components Operating System Services System Calls System Programs System Structure Virtual Machines

Segmentation Segmentation: Generalized Base/Bounds

Chapter 3 Operating-System Structures

Operating System Tutorial

General Introduction

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

COS 318: Operating Systems. Virtual Memory and Address Translation

Outline: Operating Systems

Chapter 2 Basic Structure of Computers. Jin-Fu Li Department of Electrical Engineering National Central University Jungli, Taiwan

Introduction. What is an Operating System?

Chapter 3: Operating-System Structures. Common System Components

Lecture 17: Virtual Memory II. Goals of virtual memory

Technical Properties. Mobile Operating Systems. Overview Concepts of Mobile. Functions Processes. Lecture 11. Memory Management.

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

Introduction. Application Security. Reasons For Reverse Engineering. This lecture. Java Byte Code

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Introduction Disks RAID Tertiary storage. Mass Storage. CMSC 412, University of Maryland. Guest lecturer: David Hovemeyer.

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

W4118 Operating Systems. Instructor: Junfeng Yang

A3 Computer Architecture

Lecture 25 Symbian OS

Garbage Collection in the Java HotSpot Virtual Machine

Chapter 11 I/O Management and Disk Scheduling

Unit Storage Structures 1. Storage Structures. Unit 4.3

Linked Lists, Stacks, Queues, Deques. It s time for a chainge!

- An Essential Building Block for Stable and Reliable Compute Clusters

Exception and Interrupt Handling in ARM

ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER

System Structures. Services Interface Structure

Paging: Introduction A Simple Example And Overview

Intel P6 Systemprogrammering 2007 Föreläsning 5 P6/Linux Memory System

COMPUTERS ORGANIZATION 2ND YEAR COMPUTE SCIENCE MANAGEMENT ENGINEERING UNIT 5 INPUT/OUTPUT UNIT JOSÉ GARCÍA RODRÍGUEZ JOSÉ ANTONIO SERRA PÉREZ

Computer Organization and Architecture

Chapter 13: Query Processing. Basic Steps in Query Processing

Chapter 2 System Structures

File System & Device Drive. Overview of Mass Storage Structure. Moving head Disk Mechanism. HDD Pictures 11/13/2014. CS341: Operating System

Hardware Performance Optimization and Tuning. Presenter: Tom Arakelian Assistant: Guy Ingalls

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

Addressing The problem. When & Where do we encounter Data? The concept of addressing data' in computations. The implications for our machine design(s)

361 Computer Architecture Lecture 14: Cache Memory

Chapter 14 MS-DOS Operating System

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Operating Systems. Virtual Memory

1 File Management. 1.1 Naming. COMP 242 Class Notes Section 6: File Management

ELEC 377. Operating Systems. Week 1 Class 3

Stack Allocation. Run-Time Data Structures. Static Structures

Operating Systems CSE 410, Spring File Management. Stephen Wagner Michigan State University

Programming Embedded Systems

The V8 JavaScript Engine

Understanding Java Garbage Collection

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

Debugging A MotoHawk Application using the Application Monitor

1/20/2016 INTRODUCTION

Chapter 6, The Operating System Machine Level

OPERATING SYSTEM SERVICES

Using Power to Improve C Programming Education

2) Write in detail the issues in the design of code generator.

Operating System Overview. Otto J. Anshus

Big Data Technology Map-Reduce Motivation: Indexing in Search Engines

Buffer Overflows. Security 2011

Convenience: An OS makes a computer more convenient to use. Efficiency: An OS allows the computer system resources to be used in an efficient manner.

Organization of Programming Languages CS320/520N. Lecture 05. Razvan C. Bunescu School of Electrical Engineering and Computer Science

Contributions to Gang Scheduling

Linux Process Scheduling Policy

OS OBJECTIVE QUESTIONS

Hardware and Software Requirements

Linux VM Infrastructure for memory power management

1 Organization of Operating Systems

Introduction to Embedded Systems. Software Update Problem

CHAPTER 17: File Management

Insight into Performance Testing J2EE Applications Sep 2008

SYSTEM ecos Embedded Configurable Operating System

Transcription:

Memory Management Basics 1 Basic Memory Management Concepts Address spaces Physical address space The address space supported by the hardware Starting at address, going to address MAX sys Logical/virtual address space A process s view of its own memory Starting at address, going to address MAX prog MAX sys MAX prog P But where do addresses come from? MOV r, @xfffa62e 2

Which is bigger, physical or virtual address space? A. Physical address space B. Virtual address space C. It depends on the system. 3 Basic Concepts Address generation The compilation pipeline prog P foo() end P P push... inc SP, x jmp _foo foo... 1 Library Routines 1 11 push... inc SP, 4 jmp 75 jmp 175 75... 175... 1175 Library Routines jmp 1175... Compilation Assembly Linking Loading 4

Relocation issues virtual addresses Machine has physical addresses. If virtual == physical, then how can we have multiple programs resident concurrently? Instead, relocate virtual addresses to physical at run time. While we are relocating, also bounds check addresses for safety. I can relocate that program (safely) in two registers 5 Basic Concepts (Cont d.) Address Translation MAX prog MEMORY EXCEPTION Logical no Addresses CPU yes + Instructions P s logical address space 5 Limit Register 1 Base Register Physical Addresses MAX sys 15 1 P s physical address space 6

With base and bounds registers, the OS needs a hole in physical memory at least as big as the process. A. True B. False 7 Evaluating Dynamic Allocation Techniques The fragmentation problem External fragmentation Unused memory between units of allocation E.g, two fixed tables for 2, but a party of 4 MAX Internal fragmentation Unused memory within a unit of allocation E.g., a party of 3 at a table for 4 Code ( text ) Q s PAS Execution Data Stack Execution Stack R s PAS 8

Simple Memory Management Schemes Dynamic allocation of partitions Simple approach Allocate a partition when a process is admitted into the system Allocate a contiguous memory partition to the process OS keeps track of... Full-blocks Empty-blocks ( holes ) Allocation strategies First-fit Best-fit Worst-fit P 5 MAX P 1 P 2 P 3 P 4 9 First Fit Allocation To allocate n bytes, use the first available free block such that the block size is larger than n. 1K bytes 2K bytes 2K bytes To allocate 4 bytes, we use the 1st free block available 5 bytes 5 bytes 1

Rationale & Implementation Simplicity of implementation Requires Free block list sorted by address Allocation requires a search for a suitable partition De-allocation requires a check to see if the freed partition could be merged with adjacent free partitions (if any) Advantages Simple Tends to produce larger free blocks toward the end of the address space Disadvantages Slow allocation External fragmentation 11 Best Fit Allocation To allocate n bytes, use the smallest available free block such that the block size is larger than n. 1K bytes 1K bytes 2K bytes 2K bytes To allocate 4 bytes, we use the 3rd free block available (smallest) 5 bytes 12

Rationale & Implementation To avoid fragmenting big free blocks To minimize the size of external fragments produced Requires Free block list sorted by size Allocation requires search for a suitable partition De-allocation requires search + merge with adjacent free partitions, if any Advantages Works well when most allocations are of small size Relatively simple Disadvantages External fragmentation Slow de-allocation Tends to produce many useless tiny fragments (not really great) Doug Lea s malloc In most ways this malloc is a best-fit allocator 13 Worst Fit Allocation To allocate n bytes, use the largest available free block such that the block size is larger than n. 1K bytes 1K bytes 2K bytes To allocate 4 bytes, we use the 2nd free block available (largest) 5 bytes 14

Rationale & Implementation To avoid having too many tiny fragments Requires Free block list sorted by size Allocation is fast (get the largest partition) De-allocation requires merge with adjacent free partitions, if any, and then adjusting the free block list Advantages Works best if allocations are of medium sizes Disadvantages Slow de-allocation External fragmentation Tends to break large free blocks such that large partitions cannot be allocated 15 Allocation strategies First fit, best fit and worst fit all suffer from external fragmentation. A. True B. False 16

Dynamic Allocation of Partitions Eliminating Fragmentation Compaction Relocate programs to coalesce holes MAX P 1 Swapping Preempt processes & reclaim their memory P 2 Ready Running P 3 suspended queue Suspended ready queue? Waiting semaphore/condition queues P 4 17 Memory Management Sharing Between Processes Schemes so far have considered only a single address space per process A single name space per process No sharing 2 n -1 Heap Run-Time Stack P s VAS How can one share code and data between programs without paging? Data Text P s VAS 18

Multiple Name Spaces Example Protection/Fault isolation & sharing 2 n -1 2 n 4-1 Heap Run-Time Stack 2 n 2-1 Data 2 n 1-1 Text Text Data 2 n 3-1 Run-Time Stack Heap 2 n 6-1 Libraries 2 n 5-1 User Code 19 Supporting Multiple Name Spaces Segmentation New concept A segment a memory object A virtual address space A process now addresses objects a pair (s, addr) s segment number addr an offset within an object Don t know size of object, so 32 bits for offset? n 2 n 1 n s addr s addr Segment + Address register scheme Single address scheme 2

Implementing Segmentation Base + Limit register scheme Physical Memory P Add a segment table containing base & limit register values s CPU n 32 o Logical Addresses Limit Register MEMORY EXCEPTION no 5 yes + 1 15 1 Base Register P s Segment base limit STBR s Segment Table 21 Memory Management Basics Are We Done? Segmentation allows sharing but leads to poor memory utilization We might not use much of a large segment, but we must keep the whole thing in memory (bad memory utilization). Suffers from external fragmentation Allocation/deallocation of arbitrary size segments is complex How can we improve memory management? Paging 22