CSE 380 Computer Operating Systems. Instructor: Insup Lee. University of Pennsylvania, Fall 2002 Lecture Note: Memory Management.

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

Chapter 7 Memory Management

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

Operating Systems, 6 th ed. Test Bank Chapter 7

Chapter 7 Memory Management

OPERATING SYSTEM - MEMORY MANAGEMENT

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

The Deadlock Problem. Deadlocks. Deadlocks. Bridge Crossing Example

Operating Systems. Virtual Memory

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

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

OPERATING SYSTEMS MEMORY MANAGEMENT

Chapter 3 Operating-System Structures

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

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

CS5460: Operating Systems

Chapter 12. Paging an Virtual Memory Systems

Operating System Tutorial

Operating Systems OBJECTIVES 7.1 DEFINITION. Chapter 7. Note:

Virtual Memory. Virtual Memory. Paging. CSE 380 Computer Operating Systems. Paging (1)

OPERATING SYSTEM - VIRTUAL MEMORY

Chapter 2 System Structures

Segmentation and Fragmentation

A3 Computer Architecture

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

Chapter 12 File Management

Chapter 12 File Management. Roadmap

Virtual vs Physical Addresses

Chapter 11 I/O Management and Disk Scheduling

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

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

Windows Server Performance Monitoring

Operating System Overview. Otto J. Anshus

Chapter 1 Computer System Overview

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

The Classical Architecture. Storage 1 / 36

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

Topics in Computer System Performance and Reliability: Storage Systems!

Lecture 17: Virtual Memory II. Goals of virtual memory

OS OBJECTIVE QUESTIONS

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

CS0206 OPERATING SYSTEMS Prerequisite CS0201, CS0203

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.

Segmentation Segmentation: Generalized Base/Bounds

ELEC 377. Operating Systems. Week 1 Class 3

OPERATING SYSTEM SERVICES

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

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

Disk Space Management Methods

Linux VM Infrastructure for memory power management

An Introduction to RAID. Giovanni Stracquadanio

Computer Architecture

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

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

Dynamic Memory Management for Embedded Real-Time Systems

3 - Introduction to Operating Systems

Introduction to Virtual Machines

ICOM 6005 Database Management Systems Design. Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 August 23, 2001

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

Operating Systems Lecture #6: Process Management

Secondary Storage. Any modern computer system will incorporate (at least) two levels of storage: magnetic disk/optical devices/tape systems

File-System Implementation

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

CS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen

Virtual Memory Paging

CTE214 Operating Systems Syllabus

Outline: Operating Systems

Computer Architecture

Chapter 2: OS Overview

COS 318: Operating Systems

Optimizing Linux Performance

Road Map. Scheduling. Types of Scheduling. Scheduling. CPU Scheduling. Job Scheduling. Dickinson College Computer Science 354 Spring 2010.

Far-western University Central Office, Mahendranagar Operating System

- An Essential Building Block for Stable and Reliable Compute Clusters

Chapter 11: File System Implementation. Chapter 11: File System Implementation. Objectives. File-System Structure

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

CHAPTER 17: File Management

An Introduction to Computer Science and Computer Organization Comp 150 Fall 2008

361 Computer Architecture Lecture 14: Cache Memory

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

Hardware Assisted Virtualization

Operating System Software

The Linux Virtual Filesystem

CSE 120 Principles of Operating Systems. Modules, Interfaces, Structure

File System Management

Storage. The text highlighted in green in these slides contain external hyperlinks. 1 / 14

Operating System: Scheduling

COURSE OUTLINE Survey of Operating Systems

W4118: segmentation and paging. Instructor: Junfeng Yang

Memory Management under Linux: Issues in Linux VM development

CS 3530 Operating Systems. L02 OS Intro Part 1 Dr. Ken Hoganson

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

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

Example of Standard API

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

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

Chapter 12 File Management

Transcription:

CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania, Fall 2002 Lecture Note: Memory Management 1 Memory Management q The memory management portion of the Operating System is responsible for the efficient usage of main memory, especially in a multiprogramming environment where processes contend for memory. q It must also offer protection of one process address space from another (including protection of system address space from user processes). q The memory subsystem should also provide programmers with a convenient logical or virtual address space, in which the low-level details of memory management are hidden. 2 1

Sharing of Memory Issues Program 1 Free space Program 3 Program 2 O S q Allocation schemes q Protection from each other q Protecting OS code q Translating logical addresses to physical q Swapping programs q What if physical memory is small: Virtual memory 3 Memory Hierarchy small amount of fast, expensive memory cache some medium-speed, medium price main memory gigabytes of slow, cheap disk storage 4 2

Memory Management Strategies 1 Fetch Strategy: Determine when to load and how much to load at a time. E.g., demand fetching, anticipated fetching (prefetching). 2 Placement (or allocation) Strategy: Determine where information is to be placed. E.g., Best-Fit, First-Fit, Buddy-System. 3 Replacement Strategy: Determine which memory area is to be removed under contention conditions. E.g., LRU, FIFO. 5 Memory Management Evolution q Variations 1 Fixed Partitions 2 Variable Partitions 3 Segmentation 4 Paging Early computers Relevant again: PDAs, smartcards Modern PCs q Criteria 1 How efficiently can it be implemented? 2 How effectively can the physical memory be utilized? 6 3

Fixed Partitions 1 Divide all physical memory into a fixed set of contiguous partitions. E.g., early IBM 360 models. +---------+ 12K Queue for waiting processes +---------+ 2K... +---------+ 6K... +---------+ OS: 2K +---------+ 2 Place only one process at a time in any partition. 3 Bind physical to virtual address during loading, not during execution. 4 Partition boundaries limit the available memory for each process. 5 A process is either entirely in main memory or entirely on backing store (i.e., swapped in or swapped out). 7 6 A process may only be swapped into the same partition from which it was swapped out (why?) 7 It can only simulate smaller, not larger, virtual space than physical space. 8 No sharing between processes. 9 Should there be a single queue per partition or one global queue? 10 Memory space wasted: Internal fragmentation: memory which is internal to a partition, but not used. External fragmentation: a partition is unused and available, but too small for any waiting job. 8 4

Effect of Multiprogramming q Recall: A central goal of multiprogramming is to keep CPU busy while one process waits for an I/O q Number of processes constrained by memory size q Tradeoff between memory size and CPU utilization q Can we have estimate of desired number of processes? If each process spends 75% time waiting, how many processes would keep CPU busy all the time? q If each process spends.75 fraction waiting, then assuming independence, probability that N processes will all wait at the same time is.75 N (this equals.05 for N = 10). So effective CPU utilization is 1 -.75 N q If waiting fraction is p then CPU utilization is 1 p N q This is only a crude estimate, but a useful guide 9 CPU Utilization Curve Degree of multiprogramming 10 5

Relocation and Protection q Cannot be sure where program will be loaded in memory address locations of variables, code routines cannot be absolute, and some scheme for mapping compile-time (logical) addresses to run-time (physical) addresses needed must keep a program out of other processes partitions (protection) q Simplest scheme: Loader performs relocation (feasible only for fixed partitions) q Use base and limit registers in the hardware Logical addresses added to base value to map to physical addr Logical addresses larger than limit value is an error Frequently used, so special hardware required 11 Swapping q Swapper decides which processes should be in main memory Free: 150K A: 30K q How to allocate memory? q For now, assume the entire memory needed by a process is allocated in a single block q Suppose, 180K free memory, and A needs 30K 12 6

Swapping Free: 60K D: 20K Free: 20K B: 50K Free: 30K q B requests 50K q C requests 20K q D requests 20K q A exits q C exits q Memory is fragmented q Should OS compact it to make free memory contiguous? 13 More on swapping q There should be some free space for dynamic allocation of memory (heaps) within the space allocated to a process In modern systems, stack grows downwards and heap grows upwards, with fixed space for compiled code q With variable partitions, OS must keep track of memory that is free Bitmaps (arrays) Linked lists q Classical tradeoffs: space required vs time for (de)allocation 14 7

Managing Free Space Free: 60K D: 20K Free: 20K B: 50K Free: 30K q Bit-map Suppose memory is divided in chunks of 10K Maintain a vector of 0/1 s that specifies availability i-th bit tells whether i-th chunk is free For the current example: 20 bits 00000011 00111110 0011 15 Managing Free Space: Linked Lists Free: 60K D: 20K Free: 20K B: 50K Free: 30K q Each record has Process ID/ Free (H: hole) Start location Size Pointer to Next record q Current state (H,2,3),(B,5,5),(H,10,2),(D,12,2),(H,14,6) How should we update the list when B leaves? 16 8

Managing Free Space: Linked Lists Free: 60K D: 20K Free: 20K B: 50K Free: 30K q Current state (H,2,3),(B,5,5),(H,10,2),(D,12,2),(H,14,6) q PCB for a process can have a pointer into the corresponding record q When a process terminates, neighboring blocks need to be examined Doubly-linked lists 17 Allocation Strategy Free: 60K D: 20K Free: 20K B: 50K q Suppose a new process requests 15K, which hole should it use? q First-fit: 30K hole q Best-fit: 20K hole q Worst-fit: 60K hole Free: 30K 18 9

Allocation strategies q Let {H i i = 1,,n} be unused blocks and k be the size of a requested block. q First-Fit Select the first H i such that size (H i ) k. That is, select the first block that is big enough q Best-Fit Select H i such that size (H i ) k and, if size (H j ) k then size (H j ) size (H i ) for i j. That is, select the smallest block that is big enough. q Worst-Fit Select H i such that size (H i ) k, and if size(h j ) k then size(h j ) size(h i ) for i j. (idea: to produce the largest left-over block.) q Buddy System 19 Best-fit vs. First-fit q Both could leave many small and useless holes. q To shorten search time for First-Fit, start the next search at the next hole following the previously selected hole. q Best-Fit performs better: Assume holes of 20K and 15K, requests for 12K followed by 16K can be satisfied only by best-fit q First-Fit performs better: Assume holes of 20K and 15K, requests for 12K, followed by 14K, and 7K, can be satisfied only by first-fit q In practice, F-F is usually better than B-F, and F-F and B-F are better than W-F. 20 10

Buddy Systems q Allocation algorithm that forms basis of Linux memory management q Suppose we have 128 units (128 pages or 128K) q Each request is rounded up to powers of 2 q Initially a single hole of size 128 q Suppose, A needs 6 units, request rounded up to 8 q Smallest hole available: 128. Successively halved till hole of size 8 is created q At this point, holes of sizes 8, 16, 32, 64 q Next request by B for 5 units: hole of size 8 allocated q Next request by C for 24 units: hole of size 32 allocated 21 Buddy Systems 64H 64H 64H 64H 32C D requests 3 32C A exits 32C B exits 32C 16H 8H 4H 4D 8H 4H 4D 8H 4H 4D 8B 8A 8B 8A 8B 8H 16H 22 11