Chapter 2 Memory Management: Early Systems. Understanding Operating Systems, Fourth Edition

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

Operating Systems, 6 th ed. Test Bank Chapter 7

Chapter 7 Memory Management

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

Chapter 7 Memory Management

OPERATING SYSTEM - MEMORY MANAGEMENT

Operating Systems OBJECTIVES 7.1 DEFINITION. Chapter 7. Note:

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

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

The Deadlock Problem. Deadlocks. Deadlocks. Bridge Crossing Example

Unit Storage Structures 1. Storage Structures. Unit 4.3

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

Traditional IBM Mainframe Operating Principles

OS OBJECTIVE QUESTIONS

OPERATING SYSTEM - VIRTUAL MEMORY

In-memory Tables Technology overview and solutions

OPERATING SYSTEMS MEMORY MANAGEMENT

Part III Storage Management. Chapter 11: File System Implementation

Chapter 11 I/O Management and Disk Scheduling

Operating System: Scheduling

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

Chapter 12. Paging an Virtual Memory Systems

Record Storage and Primary File Organization

CS5460: Operating Systems

Chapter 2: OS Overview

Operating System Tutorial

Garbage Collection in the Java HotSpot Virtual Machine

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

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

Linux Process Scheduling Policy

Real-Time Systems Prof. Dr. Rajib Mall Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

6. Storage and File Structures

INTRODUCTION The collection of data that makes up a computerized database must be stored physically on some computer storage medium.

Chapter 3 Operating-System Structures

Disk Space Management Methods

Cloud Computing. Up until now

Windows Server Performance Monitoring

Chapter 13: Query Processing. Basic Steps in Query Processing

CHAPTER 17: File Management

An Implementation Of Multiprocessor Linux

Operating Systems Lecture #6: Process Management

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

Chapter 12 File Management

Chapter 12 File Management. Roadmap

An Introduction to the ARM 7 Architecture

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

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

1. Computer System Structure and Components

APP INVENTOR. Test Review

361 Computer Architecture Lecture 14: Cache Memory

Chapter 1 Computer System Overview

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

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

How To Understand The History Of An Operating System

Operating Systems Concepts: Chapter 7: Scheduling Strategies

(Refer Slide Time: 00:01:16 min)

File System Management

Filing Systems. Filing Systems

Chapter 11 I/O Management and Disk Scheduling

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

Chapter 13 File and Database Systems

Chapter 13 File and Database Systems

CPU Scheduling. Basic Concepts. Basic Concepts (2) Basic Concepts Scheduling Criteria Scheduling Algorithms Batch systems Interactive systems

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

Computer Architecture

COS 318: Operating Systems. Virtual Memory and Address Translation

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

MS SQL Performance (Tuning) Best Practices:

Lecture 25 Symbian OS

Fastboot Techniques for x86 Architectures. Marcus Bortel Field Application Engineer QNX Software Systems

Chapter 6, The Operating System Machine Level

Real-Time Scheduling 1 / 39

Objectives. Chapter 5: Process Scheduling. Chapter 5: Process Scheduling. 5.1 Basic Concepts. To introduce CPU scheduling

ICS Principles of Operating Systems

Introduction. What is an Operating System?

Readings for this topic: Silberschatz/Galvin/Gagne Chapter 5

Recommended hardware system configurations for ANSYS users

Chapter 12 File Management

Chapter 2 System Structures

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

A Comparative Study of CPU Scheduling Algorithms

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

Reconfigurable Architecture Requirements for Co-Designed Virtual Machines

Chapter 14 MS-DOS Operating System

Operating System Overview. Otto J. Anshus

Physical Data Organization

Operating Systems. Virtual Memory

1 Organization of Operating Systems

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

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.

CHAPTER 1 INTRODUCTION

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

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

System Virtual Machines

How To Understand And Understand An Operating System In C Programming

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

Introduction. What is RAID? The Array and RAID Controller Concept. Click here to print this article. Re-Printed From SLCentral

Outline: Operating Systems

Introduction to Embedded Systems. Software Update Problem

Transcription:

Chapter 2 Memory Management: Early Systems Understanding Operating Systems, Fourth Edition

Memory Management: Early Systems Memory is second only to processes in importance (and in intensity) with which its managed by the OS Tanenbaum. 2

Memory Management Ideally programmers want memory that is large fast non volatile Memory management done by OS memory manager Special purpose hardware Memory hierarchy small amount of fast, expensive memory cache some medium-speed, medium price main memory Gigabytes of slow, cheap disk storage Translate these speeds to human scale 3

Memory Management Memory Management means Being aware of what parts of the memory are in use and which parts are not Allocating memory to processes when they request it and de-allocating memory when a process releases it Moving data from memory to disc, when the physical capacity becomes full, and vice versa. Stopping programs interfering with memory that doesn t belong to them 4

Memory Management: Early Systems Types of memory allocation schemes: Single-user systems Fixed partitions Dynamic partitions Relocatable dynamic partitions 5

Single-User Contiguous Scheme Program is loaded in its entirety into memory and allocated as much contiguous space in memory as it needs Jobs processed sequentially in single-user systems Requires minimal work by the Memory Manager Register to store the base address Accumulator to keep track of the program size One ie BIOS Embedded System DOS 6

Memory Protection in Single-User Contiguous Scheme To properly implement this scheme a boundary register is needed Special purpose H/W must be designed into CPUs the contents of the register can only be modified by special privileged instruction When a process references memory the system checks if its outside its boundary Inside: then service the request Outside: Error message and terminate program Of course the user program must access the OS from time to time to perform I/O for example Does this through system calls The system detects the call and switches to kernel mode or executive mode 0x123 CPU boundary register 0x123 7

Single-User Contiguous Scheme (continued) Disadvantages of Single-User Contiguous Scheme: Doesn t support multiprogramming Mono-programming is unacceptable for modern user Modern users will not suffer the delay of swapping programs in/out to the hard disk Not cost effective Multiprogramming makes more effective use of the CPU... When a single process is doing I/O the CPU is inactive 8

The secret is multiprogramming can improve the utilization of the CPU But now the problem is : how do we to organize the available memory so all the programs can reside there? 9

Memory Management: Early Systems Types of memory allocation schemes: Single-user systems Fixed partitions Dynamic partitions Relocatable dynamic partitions 10

Fixed Partitions Main memory is partitioned; one partition/job Partitions can be different sizes The partition sizes remain static unless and until computer system is shut down, reconfigured, and restarted Must remember where each space is in memory Also requires protection of the job s memory space Requires matching job size with partition size Allows multiprogramming 11

Fixed Partitions (continued) To allocate memory spaces to jobs, the operating system s Memory Manager must keep some sort of table. A very simple example is shown below: Table 2.1: A simplified fixed partition memory table with the free partition shaded 12

Fixed Partitions (continued) Job1 is allocated first space large enough to accommodate it Job 2 is allocated next available space large enough to accommodate it Job 3? No partition big enough to accommodate it even though 70K of free space is available in Partition 1 where Job 1 occupies only 30K of the 100K available but unfortunately Job 1 owns all of this partition. 13

Fixed Partitions (continued) Programmers In the earliest multi-programming systems the programmer translated the job using an absolute assemble or compiler This meant that the process had a pre-defined precise location defined for it in memory The process could only run in that space If that partition was occupied (while others were free) then this resulted in inefficiencies. To overcome this problem programmers created (more complex) relocating compilers, assemblers, and loaders. These programs produced a relocatable program that could run in any available (big enough) partition 14

Fixed Partitions (continued) Disadvantages: Requires entire program to be stored contiguously Jobs are allocated space on the basis of first available partition of required size Works well only if all of the jobs are of the same size or if the sizes are known ahead of time Arbitrary partition sizes lead to undesired results Too small a partition size results in large jobs having to wait such that their turnaround time is extended Too large a partition size results in memory waste or internal fragmentation 15

Memory Management: Early Systems Types of memory allocation schemes: Single-user systems Fixed partitions Dynamic partitions Relocatable dynamic partitions 16

Dynamic Partitions Dynamic Partitions: Jobs are given only as much memory as they request when they are loaded Available memory is kept in contiguous blocks Memory waste is comparatively small Disadvantages: At first its great and it fully utilizes memory when the first jobs are loaded Subsequent allocation leads to memory waste or external fragmentation 17

Dynamic Partitions (continued) Figure 2.2: Main memory use during dynamic partition allocation 18

Dynamic Partitions (continued) 5 K 10 K 35K of memory available but Job 8 still has to wait! 20K Figure 2.2 (continued): Main memory use during dynamic partition allocation 19

Where to put the jobs With Dynamic memory allocation we give jobs just enough room Easy for first job What happens when we have lots of jobs all arriving one after the other and all with different requirements We need some sort of allocation algorithm 20

Best-Fit and First-Fit Fit Allocation Free partitions are allocated on the following basis: First-fit memory allocation: First partition fitting the requirements Leads to fast allocation of memory space Best-fit memory allocation: Smallest partition fitting the requirements Results in least wasted space Internal fragmentation reduced but not eliminated 21

Best-Fit Versus First-Fit Fit Allocation First-fit memory allocation: Advantage: Faster in making allocation Disadvantage: Leads to memory waste Best-fit memory allocation Advantage: Makes the best use of memory space Disadvantage: Slower in making allocation 22

First-Fit Fit Allocation Figure 2.3: An example of a first-fit free scheme 23

Best-Fit? Figure 2.4: An example of a best-fit free scheme 24

A Note: The Memory Manager In the following slides we assume that the Memory Manager keeps two lists, one for free memory (LHS) and one for busy memory blocks (RHS) Assume the two lists are of a fixed size and the elements in the list can contain values or be empty. For simplicity the lists are often merged in the diagrams that follow 25

A new Job requires a 200 size block First-Fit Fit Algorithm Free Memory List The various addresses where we can get free space.... Where can we put the Job? Please note that 4075 + 105 = 4180 ( so the space (1045) up to 5225 must be filled with jobs) After Job is placed in memory the list of addresses where free space is available changes 26

Best-Fit Algorithm Algorithm for Best-Fit: Goal: find the smallest memory block into which the job will fit NB: Entire table must be searched before allocation 27

A Job requires 200 spaces Best-Fit Algorithm Where will it be placed? 28

More Allocation Schemes Hypothetical allocation schemes:. Next-fit: Starts searching from last allocated block, for the next available block when a new job arrives Worst-fit: Allocates the largest free available block to the new job Opposite of best-fit Good way to explore the theory of memory allocation; might not be the best choice for an actual system 29

Another way to do it? Alternative search strategy Search the entire input queue looking for the largest job that fits into the partition Do not waste a large partition on a small job but smaller jobs are discriminated against Have at least one small partition or ensure that small jobs only get skipped a certain number of times 30

When Jobs finish How do we reclaim space when jobs finish? 31

Deallocation Deallocation: Freeing an allocated memory space For fixed-partition system: Straightforward process. When job completes, Memory Manager resets the status of the job s memory block to free Any code for example, binary values with 0 indicating free and 1 indicating busy may be used 32

Deallocation (continued) For dynamic-partition system: Algorithm tries to combine free areas of memory whenever possible. This makes it more complex. The system must prepare for three possible cases: Case 1: When the block to be deallocated is adjacent to another free block Case 2: When the block to be deallocated is between two free blocks Case 3: When the block to be deallocated is isolated from other free blocks 33

Case 1: Joining Two Free Blocks Join This has to be de-allocated. It buts-up to the next highest free memory location (although not to the free space below it... there is probably another process in the green area). 34

Case 1: Joining Two Free Blocks The free memory list must be changed to reflect starting address of the new free block In the example, 7600 this was the address of the first instruction of the job that just released this block Memory block size for the new free space must be changed to show its new size that is, the combined total of the two free partitions In the example, (200 + 5) 35

Case 2: Joining Three Free Blocks Now notice that the memory we will free is butted-up to free memory above and below it. We ll end up with three free spaces. These can be joined together. This has to be de-allocated 36

Case 2: Joining Three Free Blocks. Deallocated memory space is between two free memory blocks Change list to reflect the starting address of the new free block In the example, 7560 which was the smallest beginning address Sizes of the three free partitions must be combined In the example, (20 + 20 + 205) Because location 7600 in our list has been combined the pointer in that list location must be changed to null to indicate that it no longer points to free memory space, hence null. 37

Case 3: Deallocating an Isolated Block Space to be deallocated is isolated from other free areas 1. System learns that the memory block to be released is tight between two other busy areas 2. Null entry in the busy list 3. Must search the free memory list for a null entry 4. And point that list element to the new free area 1 3 2 4 38

Memory Management: Early Systems Types of memory allocation schemes: Single-user systems Fixed partitions Dynamic partitions Relocatable dynamic partitions 39

Problems so far The fixed and dynamic memory management systems described so far share some unacceptable fragmentation characteristics that must be resolved We ll likely end up with lots of slivers of un-used memory 40

Relocatable Dynamic Partitions Relocatable Dynamic Partitions: Memory Manager relocates programs to gather together all of the empty blocks Compact the empty blocks to make one block of memory large enough to accommodate some or all of the jobs waiting to get in Sometimes called garbage collection Its not easy 41

Relocatable Dynamic Partitions (continued) Compaction: Reclaiming fragmented sections of the memory space Every program in memory must be relocated so they are contiguous So every address so must be relocated Every reference to an address within the program must be updated Data must not be harmed 42

Relocatable Dynamic Partitions (continued) Figure 2.5: An assembly language program that performs a simple incremental operation 43

Relocatable Dynamic Partitions (continued) The assembly language program (RHS) after it has been processed by the assembler appear on LHS. Notice the memory locations are flagged by apostrophe 44

Relocatable Dynamic Partitions (continued) Compaction issues: What goes on behind the scenes when relocation and compaction take place? What keeps track of how far each job has moved from its original storage area? What lists have to be updated? 45

Relocatable Dynamic Partitions (continued) What lists have to be updated? Free list must show the partition for the new block of free memory Busy list must show the new locations for all of the jobs already in process that were relocated Each job will have a new address except for those that were already at the lowest memory locations 46

Relocatable Dynamic Partitions (continued) Special-purpose registers are used for relocation: Bounds register Stores highest location accessible by each program Relocation register Contains the value that must be added to each address referenced in the program so it will be able to access the correct memory addresses after relocation If the program isn t relocated, the value stored in the program s relocation register is zero 47

Relocatable Dynamic Partitions (continued) Figure 2.7: Three snapshots of memory before and after compaction 48

Relocatable Dynamic Partitions (continued) Figure 2.8: Contents of relocation register and close-up of Job 4 memory area (a) before relocation and (b) after relocation and compaction 49

Relocatable Dynamic Partitions (continued) Compacting and relocating optimizes the use of memory and thus improves throughput Options for when and how often it should be done: When a certain percentage of memory is busy When there are jobs waiting to get in After a prescribed amount of time has elapsed Goal: Optimize processing time and memory use while keeping overhead as low as possible 50

Summary Four memory management techniques were used in early systems: single-user systems, fixed partitions, dynamic partitions, and relocatable dynamic partitions Memory waste in dynamic partitions is comparatively small as compared to fixed partitions First-fit is faster in making allocation but leads to memory waste Best-fit makes the best use of memory space but slower in making allocation 51

Summary (continued) Compacting and relocating optimizes the use of memory and thus improves throughput All techniques require that the entire program must: Be loaded into memory Be stored contiguously Remain in memory until the job is completed Each technique puts severe restrictions on the size of the jobs: can only be as large as the largest partitions in memory 52

Objectives of this chapter were You will be able to describe: The basic functionality of the three memory allocation schemes presented in this chapter: fixed partitions, dynamic partitions, relocatable dynamic partitions Best-fit memory allocation as well as first-fit memory allocation schemes How a memory list keeps track of available memory The importance of deallocation of memory in a dynamic partition system 53

Objectives (continued) You should be able to describe: The importance of the bounds register in memory allocation schemes The role of compaction and how it improves memory allocation efficiency 54