Lectures 21 : Memory Management (ii) Thu 19 Nov 2009

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

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

The Deadlock Problem. Deadlocks. Deadlocks. Bridge Crossing Example

OPERATING SYSTEM - MEMORY MANAGEMENT

Chapter 7 Memory Management

Chapter 7 Memory Management

Virtual vs Physical Addresses

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

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

Operating Systems, 6 th ed. Test Bank Chapter 7

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

Lecture 17: Virtual Memory II. Goals of virtual memory

Chapter 12. Paging an Virtual Memory Systems

OPERATING SYSTEMS MEMORY MANAGEMENT

OPERATING SYSTEM - VIRTUAL MEMORY

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

W4118: segmentation and paging. Instructor: Junfeng Yang

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

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

How To Write A Page Table

Virtual Memory. How is it possible for each process to have contiguous addresses and so many of them? A System Using Virtual Addressing

COS 318: Operating Systems. Virtual Memory and Address Translation

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

CS5460: Operating Systems

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

Board Notes on Virtual Memory

Operating Systems. Virtual Memory

361 Computer Architecture Lecture 14: Cache Memory

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

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

Record Storage and Primary File Organization

Outline: Operating Systems

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

The Linux Virtual Filesystem

Computer Architecture

Peter J. Denning, Naval Postgraduate School, Monterey, California

Traditional IBM Mainframe Operating Principles

Chapter 11 I/O Management and Disk Scheduling

HY345 Operating Systems

Disk Space Management Methods

We r e going to play Final (exam) Jeopardy! "Answers:" "Questions:" - 1 -

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

Hypervisor: Requirement Document (Version 3)

OS OBJECTIVE QUESTIONS

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

Operating Systems. Steven Hand. Michaelmas / Lent Term 2008/ lectures for CST IA. Handout 3. Operating Systems N/H/MWF@12

File-System Implementation

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

High-Performance Processing of Large Data Sets via Memory Mapping A Case Study in R and C++

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

Chapter 1 13 Essay Question Review

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

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

Mass Storage Structure

Segmentation Segmentation: Generalized Base/Bounds

Operating System Tutorial

General Purpose Operating System Support for Multiple Page Sizes

Virtualization. Explain how today s virtualization movement is actually a reinvention

Beyond Physical Memory: Mechanisms

Lecture 15. IP address space managed by Internet Assigned Numbers Authority (IANA)

Midterm Exam #2 Solutions November 10, 1999 CS162 Operating Systems

Chapter 3 Operating-System Structures

Name: 1. CS372H: Spring 2009 Final Exam

Chapter 1 8 Essay Question Review

An Introduction to RAID. Giovanni Stracquadanio

Operating Systems OBJECTIVES 7.1 DEFINITION. Chapter 7. Note:

Windows Server Performance Monitoring

b. A program calls malloc to request more memory from the operating system. i.what system call would malloc use to request more memory of the OS?

Computer-System Architecture

Virtual Memory Paging

1. Computer System Structure and Components

Paging: Introduction A Simple Example And Overview

Memories Are Made of This

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

Virtual Machines. COMP 3361: Operating Systems I Winter

How To Understand And Understand An Operating System In C Programming

How To Write A Virtual Machine (Or \"Virtual Machine\") On A Microsoft Linux Operating System (Or Microsoft) (Or Linux) ( Or Microsoft Microsoft Operating System) (For A Non-Power Os) (On A

Presentation of Diagnosing performance overheads in the Xen virtual machine environment

APP INVENTOR. Test Review

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

Chapter 11: File System Implementation. Operating System Concepts with Java 8 th Edition

Data Storage - I: Memory Hierarchies & Disks

Chapter 13: Query Processing. Basic Steps in Query Processing

Chapter 10: Virtual Memory. Lesson 03: Page tables and address translation process using page tables

Operating System Software

A3 Computer Architecture

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

Topics in Computer System Performance and Reliability: Storage Systems!

Tested product: Auslogics BoostSpeed

CRASH RECOVERY FOR REAL-TIME MAIN MEMORY DATABASE SYSTEMS

W4118 Operating Systems. Instructor: Junfeng Yang

Kernel. What is an Operating System? Systems Software and Application Software. The core of an OS is called kernel, which. Module 9: Operating Systems

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

Memory Management Simulation Interactive Lab

An Implementation Of Multiprocessor Linux

IOMMU: A Detailed view

Chapter 2: OS Overview

Windows OS File Systems

Segmentation and Fragmentation

Filing Systems. Filing Systems

Transcription:

CS211: Programming and Operating Systems Lectures 21 : Memory Management (ii) Thu 19 Nov 2009 CS211 Lectures 21 : Memory Management (ii) 1/23

This afternoon... 1 Recall... Memory management 2 Contiguous Memory Allocation 3 Fragmentation 4 Paging Implementation of Page Table 5 Virtual Memory 6 Demand Paging 7 Page Fault CS211 Lectures 21 : Memory Management (ii) 2/23

Recall... Memory management On Monday we discussed 1 Logical versus Physical Address Space 2 Swapping Today: 1 Contiguous Memory Allocation 2 Fragmentation 3 Paging CS211 Lectures 21 : Memory Management (ii) 3/23

Contiguous Memory Allocation In a multiprogramming environment, memory space is occupied by the operating system and a collection of user processes. In order to maximise the degree of multiprogramming on the system, the OS will load as many procs into memory as there is space for. When new procs arrive in the Input queue, it picks the first one and loads it into memory unless there is not enough room to accommodate it. In this case, it may search through to procs in the Input queue and load the first one for which there is a large enough space to accommodate. CS211 Lectures 21 : Memory Management (ii) 4/23

Contiguous Memory Allocation When user procs terminate, memory holes are created. The operating system must allocated one of these hole to a new proc that is starting. If the hole it too large, only part of it is allocated and a new smaller hole is created. Also, when a proc terminates, if its space is adjacent to a free hole, they are amalgamated to create a larger one. The scheduler then checks if they new hole is large enough to accommodate the next job in the Input queue. If this procedure of splitting and amalgamating of holes continues for a while, we end up with blocks of available memory of various size are scattered throughout memory. This is called Fragmentation and is to be avoided. Strategies/Algorithms for allocating memory to procs is a crucial part of memory management. CS211 Lectures 21 : Memory Management (ii) 5/23

Contiguous Memory Allocation To summarise: Goal: In a multiprogramming environment, we wish to maximise the degree of multiprogramming on the system, by loading as many procs into memory as there is space for. Whats the problem? When user procs terminate, memory holes (or pockets ) are created. If the hole it too large, only part of it is allocated to the next proc., creating a smaller hole. When a proc terminates, if its space is adjacent to a free hole, they are amalgamated to create a larger one. How does the OS deal with this? Use strategies/algorithms/policy for allocating memory to procs. Try to maintain efficiency while minimising fragmentation. CS211 Lectures 21 : Memory Management (ii) 6/23

Contiguous Memory Allocation Three different strategies are: 1 First Fit (FF): allocate the first hole that is large enough to accommodate the new proc. This is the fastest method, but may cause the most fragmentation i.e, the most small pockets of unused non-contiguous memory. 2 Best Fit (BF): search all available holes and allocate the smallest hole that is big enough to accommodate the new proc. This is slower than best-fit, but leads to the smallest pocket sizes. 3 Worst Fit (WF): search all available holes and assign part of the the largest available hole. This is the slowest method but may leave a smaller number of larger holes than either first or best fit. CS211 Lectures 21 : Memory Management (ii) 7/23

Contiguous Memory Allocation Example Suppose that a system has four free memory holes orders as follows: H 1 = 100k, H 2 = 200k, H 3 = 500k, H 4 = 600k. Four procs arrive in the following order: P 1 (210k), P 2 (450k), P 3 (120k), P 4 (200k). Show how these would be allocated by the FF, BF, and WF strategies. CS211 Lectures 21 : Memory Management (ii) 8/23

Fragmentation Memory is partitioned into contiguous segments and allocated to different processes. The methods for contiguous memory allocation described above can lead to External fragmentation: total memory space exists to satisfy a request, but it is not contiguous. That is, memory is available but is broken up into pockets between partitions that are too small to be used. Internal fragmentation: Suppose there is a free hole of size 12,100 bytes and we require a partition of size 12,080 bytes. The OS may require more that 20 bytes to keep track of the unused portion, so it can be more economical to allocate all 12,100 bytes even though this is slightly larger than requested memory; this is called internal fragmentation CS211 Lectures 21 : Memory Management (ii) 9/23

Fragmentation One solution to the fragmentation problem is compaction, i.e., shuffle memory contents to place all free memory together in one large block. This is not always possible requires dynamic memory relocation. Also it can be time-consuming. Furthermore, fragmentation may happen in the swap space. However, compaction is certainly not feasible in that instance. (Why?) The other alternative is to allow for non-contiguous memory allocation. This is done by paging or segmentation, or some hybrid of these two approaches. CS211 Lectures 21 : Memory Management (ii) 10/23

Paging Basic idea: Logical address space of a process can be non-contiguous; process is allocated physical memory whenever the latter is available. Divide physical memory into fixed-sized blocks called frames. All frames on the system are of the same size, some power of 2, between 512 bytes and 8192 bytes (determined by the hardware). CS211 Lectures 21 : Memory Management (ii) 11/23

Paging To find out the page size on a Linux system, run this program: 1 / / Try this for Windows 2 #include <s t d i o. h> 3 # include <windows. h> From http://en.wikipedia.org/wiki/page size link! 5 i n t main ( void ) 6 { 7 SYSTEM INFO s i ; 8 GetSystemInfo (& s i ) ; 10 p r i n t f ( The page size f o r t h i s system i s %u bytes.\ n, 11 s i. dwpagesize ) ; 12 return 0; 13 } CS211 Lectures 21 : Memory Management (ii) 12/23

Paging From http://en.wikipedia.org/wiki/page size link! 1 / / Try this for Linux 2 #include <s t d i o. h> 3 #include <u n i s t d. h> / / sysconf(3) 4 i n t main ( void ) 5 { 6 p r i n t f ( The page size f o r t h i s system i s %l d bytes.\ n, 7 sysconf ( SC PAGESIZE ) ) ; 8 return ( 0 ) ; 9 } CS211 Lectures 21 : Memory Management (ii) 13/23

Paging Logical memory into blocks called pages. Frames and Pages are of the same size. the OS keeps track of all free frames in memory. To run a program of size n pages, we need to find n free frames and load program. Page Table maintained to translate logical to physical addresses. CS211 Lectures 21 : Memory Management (ii) 14/23

Paging Address Translation Scheme An address generated by CPU is divided into: Page number (p), used as an index into a page table which contains base address of each page in physical memory; Page offset (d), combined with base address to define the physical memory address that is sent to the memory unit. CS211 Lectures 21 : Memory Management (ii) 15/23

Paging Implementation of Page Table The Page table is kept in main memory. Page-table base register (PTBR) points to the page table. Page-table length register (PRLR) indicates size of the page table. Every data/instruction access requires two memory accesses one for the page table and one for the data/instruction. The two memory access problem can be solved by the use of a special fast-lookup hardware cache called associative registers or translation look-aside buffers (TLBs) Example: Suppose we have 128kb of physical memory, pages/frames of size 8kb, and a process that requires 32kb... By using paging we avoid external fragmentation. A problem with paging is that, on average, internal fragmentation accounts for one half page per process. CS211 Lectures 21 : Memory Management (ii) 16/23

Virtual Memory We have already considered using some hard-drive space as temporary storage for data that should reside in main memory but which belongs to a process that is not currently running in the CPU (e.g., it is ready or waiting ). We extend this idea to allow part of the address space of a process to be swapped out into secondary ( backing ) storage even though the process is in the CPU. We will look at a system that allows the total addressable logical memory to include physical memory and part of the backing storage. Key concepts include 1 Introduction 2 Demand paging 3 Page faults 4 the dirty bit 5 Page fault handling 6 page replacement algorithms 7 Thrashing CS211 Lectures 21 : Memory Management (ii) 17/23

Virtual Memory CS211 Lectures 21 : Memory Management (ii) 18/23

Virtual Memory Basic Idea: Only part of the program needs to be in memory for execution. Why? Often a process does not have to access all of its memory at once. For example, if the process has error handling routines, these will rarely be required. Logical address space can therefore be much larger than physical address space. Hence we can run procs that require more memory than is available on the system. Also, we can increase the degree of multi-programming in the system. (the number of procs that are ready to be brought into the CPU at any time.) VM requires that pages to be swapped/paged in and out (of swap space) in a procedure known as demand paging CS211 Lectures 21 : Memory Management (ii) 19/23

Demand Paging Basic ideas: Bring a page into memory only when it is needed (lazy paging). Pages belonging to a proc may be memory resident or not. The system needs some mechanism for distinguishing between resident and non-resident pages. Therefore the page table associates a valid/invalid bit with each page. 1 resident 0 not in physical memory. If a proc wishes to access a valid page it can do so. If a proc wishes to access an invalid page then the paging hardware generates a Page Fault. CS211 Lectures 21 : Memory Management (ii) 20/23

Page Fault If there is a reference to an invalid page, reference will trap to OS. reference to nonexisting page abort Just not in memory must bring page into memory. 1 Reference is made to invalid page 2 Page fault generated trap to Operating system (PCB of user process is saved and OS given access to CPU) 3 Locate empty frame in physical memory. 4 Swap page into frame. 5 Reset tables, flip validation bit (change to 1) 6 Restart user process (load PCB and perform next instruction) CS211 Lectures 21 : Memory Management (ii) 21/23

Page Fault CS211 Lectures 21 : Memory Management (ii) 22/23

Page Fault What happens if there is no free frame? Page replacement find some page in memory, but not really in use, and swap it out. We need an algorithm for selecting such a page. The algorithm will be evaluated on the basis of the generation of a minimum number of page faults. (More about this later...) CS211 Lectures 21 : Memory Management (ii) 23/23