Today. Memory management. Memory Management. Computer Hardware Review

Similar documents
Chapter 7 Memory Management

Chapter 7 Memory Management

COS 318: Operating Systems. Virtual Memory and Address Translation

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

OPERATING SYSTEM - MEMORY MANAGEMENT

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

CS5460: Operating Systems

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

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

Operating Systems, 6 th ed. Test Bank Chapter 7

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

Chapter 2: Computer-System Structures. Computer System Operation Storage Structure Storage Hierarchy Hardware Protection General System Architecture

Chapter 2: OS Overview

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

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

Virtual Memory Paging

Operating System Software

Lecture 25 Symbian OS

Chapter 1 Computer System Overview

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

lesson 1 An Overview of the Computer System

POSIX. RTOSes Part I. POSIX Versions. POSIX Versions (2)

Lesson Objectives. To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization

Virtual vs Physical Addresses

Operating System Tutorial

OPERATING SYSTEMS MEMORY MANAGEMENT

Computer-System Architecture

Operating Systems 4 th Class

OPERATING SYSTEM - VIRTUAL MEMORY

Computer Architecture

361 Computer Architecture Lecture 14: Cache Memory

The Deadlock Problem. Deadlocks. Deadlocks. Bridge Crossing Example

Linux Process Scheduling Policy

Operating Systems. Virtual Memory

COS 318: Operating Systems

CS161: Operating Systems

Unit Storage Structures 1. Storage Structures. Unit 4.3

Lecture 17: Virtual Memory II. Goals of virtual memory

A3 Computer Architecture

Lecture 16: Storage Devices

W4118: segmentation and paging. Instructor: Junfeng Yang

Operating Systems. Design and Implementation. Andrew S. Tanenbaum Melanie Rieback Arno Bakker. Vrije Universiteit Amsterdam

Outline. Operating Systems Design and Implementation. Chap 1 - Overview. What is an OS? 28/10/2014. Introduction

Embedded Software development Process and Tools: Lesson-4 Linking and Locating Software

Memory Hierarchy. Arquitectura de Computadoras. Centro de Investigación n y de Estudios Avanzados del IPN. adiaz@cinvestav.mx. MemoryHierarchy- 1

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

Chapter 1: Introduction. What is an Operating System?

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

Operating Systems OBJECTIVES 7.1 DEFINITION. Chapter 7. Note:

Operating System Overview. Otto J. Anshus

Outline: Operating Systems

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

Types Of Operating Systems

How To Write A Page Table

Amoeba Distributed Operating System

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

Review from last time. CS 537 Lecture 3 OS Structure. OS structure. What you should learn from this lecture

Chapter 3. Operating Systems

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

CHAPTER 1 INTRODUCTION

Physical Data Organization

Chapter 6, The Operating System Machine Level

Scheduling. Yücel Saygın. These slides are based on your text book and on the slides prepared by Andrew S. Tanenbaum

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

An Implementation Of Multiprocessor Linux

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-17: Memory organisation, and types of memory

Process Description and Control william stallings, maurizio pizzonia - sistemi operativi

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

Operating system Dr. Shroouq J.

Computer Architecture

CS 6290 I/O and Storage. Milos Prvulovic

Performance Comparison of RTOS

TECHNOLOGY BRIEF. Compaq RAID on a Chip Technology EXECUTIVE SUMMARY CONTENTS

File-System Implementation

OS OBJECTIVE QUESTIONS

Multi-core Programming System Overview

Process Scheduling CS 241. February 24, Copyright University of Illinois CS 241 Staff

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

Chapter 1. The largest computers, used mainly for research, are called a. microcomputers. b. maxicomputers. c. supercomputers. d. mainframe computers.

Republic Polytechnic School of Information and Communications Technology C226 Operating System Concepts. Module Curriculum

Real-Time Scheduling 1 / 39

Overview and History of Operating Systems

Operating Systems: Basic Concepts and History

Operating System Structures

Main Memory & Backing Store. Main memory backing storage devices

Kernel Optimizations for KVM. Rik van Riel Senior Software Engineer, Red Hat June

6. Storage and File Structures

ò Paper reading assigned for next Thursday ò Lab 2 due next Friday ò What is cooperative multitasking? ò What is preemptive multitasking?

CS0206 OPERATING SYSTEMS Prerequisite CS0201, CS0203

This tutorial will take you through step by step approach while learning Operating System concepts.

SYSTEM ecos Embedded Configurable Operating System

COS 318: Operating Systems. I/O Device and Drivers. Input and Output. Definitions and General Method. Revisit Hardware

Operating Systems. 05. Threads. Paul Krzyzanowski. Rutgers University. Spring 2015

Operating Systems Lecture #6: Process Management

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

This Unit: Putting It All Together. CIS 501 Computer Architecture. Sources. What is Computer Architecture?

CHAPTER 7: The CPU and Memory

How To Understand And Understand An Operating System In C Programming

Two Parts. Filesystem Interface. Filesystem design. Interface the user sees. Implementing the interface

Components of a Computing System. What is an Operating System? Resources. Abstract Resources. Goals of an OS. System Software

Transcription:

Memory management Knut Omang Ifi/Paradial 1 Oct, 2009 (with slides from V. Goebel, C. Griwodz (Ifi/UiO), P. Halvorsen (Ifi/UiO), K. Li (Princeton), A. Tanenbaum (VU Amsterdam), and M. van Steen (VU Amsterdam)) Today Basic management Swapping Page as unit Segmentation Virtual Page/segment allocation implementation Memory Management Ideally mers want that is large fast non volatile Memory hierarchy small amount of fast, expensive cache some medium-speed, medium price main gigabytes of slow, cheap disk storage Memory manager handles the hierarchy Computer Hardware Review Typical hierarchy numbers shown are rough approximations Memory Management for Monoming Only one user loaded Program is entirely in No swapping or paging Three simple ways of organizing Basic Memory Management Monoming without Swapping or Paging Some PDAs, embedded systems C6, ZX80, User OS in ROM 0x0 0xfff. Old mainframes and minicomputers OS in RAM User 0x0 0xfff. MS-DOS, OS in RAM User Devs in ROM 0x0 0xfff. 5 6 1

Multiming Processes have to wait for I/O Goal Do other work while a process waits Give CPU to another process Multiming Arrival and work requirements of jobs CPU utilization for 1- jobs with 80% I/O wait Job# Arrival time CPU useio wait time time 1 10:00 16 2 10:10 12 10:15 2 8 10:20 2 8 Remaining CPU time 1 2 2.0 1.1 0..0 2.1 1.2 1.0 0.1 2.0 1.1 2.0 1.7 0.7 0.8 # processors % 1 2 CPU idle 80 6 51 1 CPU busy 20 6 9 59 CPU per 20 18 16 15 process Processes may be concurrently ready So If I/O waiting probability for all processes is p Probable CPU utilization can be estimated as CPU utilization = 1 p n 0 10 15 20 22 27.6 1.7 28.2 Sequence of events as jobs arrive and finish Note numbers show amount of CPU time jobs get each interval 7 8 1 2 2.0 0.8 0.8 0.8 0. 0. 0. 0. 0.1 0.1 0.7 time Analysis of Multiming System Performance Multiming Arrival and work requirements of jobs CPU utilization for 1 jobs with 80% I/O wait Sequence of events as jobs arrive and finish 9 note numbers show amout of CPU time jobs get in each Degree of multiming CPU utilization as a function of number of processes in 10 Multiming Several s Concurrently loaded into OS must arrange sharing Memory partitioning Memory Needed for different tasks within a process Shared among processes Process demand may change over time Use of secondary storage Move (parts of) blocking processes from Higher degree of multiming possible Makes sense if processes block for long times 11 Memory Management for Multiming Process may not be entirely in Reasons Other processes use Their turn Higher priority Process is waiting for I/O Too big For its share For entire available Approaches Swapping Paging Overlays Paging Swapping Overlays Registers Cache(s) DRAM Disk 12 2x 100x 10 9 x 2

Memory Management for Multiming Swapping Remove a process from With all of its state and Store it on a secondary medium Disk, Flash RAM, other slow RAM, historically also Tape Paging Remove part of a process from Store it on a secondary medium Sizes of such parts are fixed Page size Overlays Manually replace parts of code and Programmer s rather than OS s work Only for very old and -scarce systems How to use these with Virtual Memory 1 Memory Management Techniques Before details about moving processes out How to assign to processes Memory partitioning Fixed partitioning Dynamic partitioning Simple paging Simple segmentation Virtual paging Virtual segmentation 1 Multiming with Fixed Partitions Divide Into static partitions At system initialization time (boot or earlier) Fixed partitions separate input queues for each partition Advantages Very easy to implement Can support swapping process in and out 15 16 single input queue Two fixed partitioning schemes Equal-size partitions Unequal-size partitions Equal-size partitions Big s can not be executed Unless parts are loaded from disk Small s use entire partition A problem called internal 0x0 0x fff 17 Two fixed partitioning schemes Equal-size partitions Unequal-size partitions Unequal-size partitions Bigger s can be loaded at once Smaller s can lead to less internal Advantages require assignment of jobs to partitions 2MB 18

Approach Has been used in mainframes Uses the term job for a running Jobs run as batch jobs Jobs are taken from a queue of pending jobs Problem with unequal partitions Choosing a job for a partition 2MB 19 One queue per partition Internal is minimal Jobs wait although sufficiently large partitions are available 2MB 20 Single queue Jobs are put into next sufficiently large partition Waiting time is reduced Internal is bigger A swapping mechanism can reduce internal Move a job to another partition 2MB Problems: Relocation and Protection Cannot be sure where will be loaded in address locations of variables, code routines cannot be absolute must keep a out of other processes partitions Base and limit values: Simplest form of virtual (translate: virt --> phys) address locations added to base value to map to phys. addr address locations larger than limit value is an error 21 22 2 Registers: Base and Bound Swapping (1) virtual address + physical address bound base > error Built in Cray-1 A can only access physical in [base, base+bound] On a context switch: save/restore base, bound registers Pros: Simple Cons:, hard to share, and difficult to use disks Memory allocation changes as processes come into leave Shaded regions are unused 2

Dynamic Partitioning Dynamic Partitioning Divide Partitions are created dynamically for jobs Removed after jobs are finished External Problem increases with system running time Occurs with swapping as well Addresses of process 2 changed External Solutions to address change: Address Translation 25 Swapped in Process 5 Process 12 20MB 1 free 20MB 1 free Process Process 2 5 1 1 free free free Process 22MB 1 free free Reduce external Compaction Compaction Takes time Consumes processing resources Reduce compaction need Placement algorithms 26 Swapped in Process 2 1 Process Process free Process free 1 Process free 1 free free free Dynamic Partitioning: Placement Algorithms Use most suitable partition for process Typical algorithms First fit Next fit Best fit First Next Best 12 12 12 27 Dynamic Partitioning: Placement Algorithms Use most suitable partition for process Typical algorithms First fit Next fit Best fit First 12 10MB Best 12 10MB 28 Dynamic Partitioning: Placement Algorithms Comparison of First fit, Next fit and Best fit Example is naturally artificial First fit Simplest, fastest of the three Typically the best of the three Next fit Typically slightly worse than first fit Problems with large segments Best fit Slowest Creates lots of small free blocks Therefore typically worst 29 Memory management: bookkeeping Two main strategies: Bitmaps Bit indicate free/allocated Using linked lists Keep list(s) of free/allocated segments 0 5

Memory Management: bitmaps/lists Memory Management with Linked Lists Part of with 5 processes, holes tick marks show allocation units shaded regions are free Corresponding bit map Same information as a list 1 Four neighbor combinations for the terminating process X 2 Buddy System Swapping (2) Mix of fixed and dynamic partitioning Partitions have sizes 2 k, L k U Maintain a list of holes with sizes Assign a process Find smallest k so that process fits into 2 k Find a hole of size 2 k If not available, split smallest hole larger than 2 k Split recursively into halves until two holes have size 2 k Process 2kB Process 128kB Process 128kB 128kB Process 2kB 2kB 6kB 2kB 128kB 6kB 512kB Process 1MB Process 512kB Allocating space for growing segment Allocating space for growing & segment Memory use within a process Memory needs of known size Program code Program Global variables Memory needs of unknown size Process Dynamically allocated Stack Several in multithreaded s PCB Initialized global variables () Uninitialized global vars Uninitialized global variables Memory Addressing Addressing in Addressing needs are determined during ming Must work independently of position in Actual physical address are not known Initialized global variables Uninitialized global vars Possibly s for more threads 5 6 6

Memory Addressing Addressing in Addressing needs are determined during ming Must work independently of position in Actual physical address are not known PCB Memory Management Addressing Covered address translation and virtual Important now Translation is necessary Therefore possible to have several parts Pages Segments PCB 7 8 Paging Paging Equal lengths Determined by processor One page moved into one frames Process is loaded into several frames Not necessarily consecutive No external Little internal Depends on frame size Process Process 2 51 9 Paging Virtual address page table size VPage # offset > error Page table PPage#....... PPage#... PPage # offset Physical address Use a page table to translate Various bits in each entry Context switch: similar to the segmentation scheme What should be the page size? Pros: simple allocation, easy to share Cons: big page table and cannot deal with holes easily Segmentation Segmentation Different lengths Determined by mer Memory frames Programmer (or compiler toolchain) organizes in parts Move control Needs awareness of possible segment size limits Pros and Cons Principle as in dynamic partitioning No internal Less external because on average smaller segments 1 Segmentation Virtual address segment seg + offset physical address. size Have a table of (seg, size) Protection: each entry has > error (nil, read, write) On a context switch: save/restore the table or a pointer to the table in kernel Pros: Efficient, easy to share Cons: Complex management and within a segment 7

Paging Typical for paging and swapping Address translation At execution time With processor support Lookup table ( part 2, offset in part 2) + Simplified Address translation Simple paging and segmentation Without virtual and protection Can be implemented by address rewriting at load time by jump tables setup at load time Code part 1 Code part 2 Segmentation with paging and virtual address space seg Vseg #. size > error Virtual address VPage # offset Page table PPage#....... PPage#... PPage # offset Physical address Other needs (protection) Protection of process from itself ( grows into heap) Protection of processes from each other (write to other process) Solutions to protection: Address Translation PCB 5 Why Address Translation and Virtual Memory? Use secondary storage Extend expensive DRAM with reasonable performance Protection Programs do not step over each other and communicate with each other require explicit IPC operations Convenience Flat address space Programs share same view of the world Programs/ parts can be moved 6 Summary: Memory Management Algorithms Paging and segmentation Extended in address translation and virtual lectures Placement algorithms for partitioning strategies Mostly obsolete for system management since hardware address translation is available But still necessary for managing kernel within a process of specialized systems (esp. base systems) Address translation solves Solves addressing in a loaded Hardware address translation Supports protection from access Supports new physical position after swapping in Virtual provides Provide larger logical (virtual) than physical Selects process, page or segment for removal from physical 7 8