Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 13: Main Memory (Chapter 8)

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

9.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory OSC: Chapter 9. Demand Paging Copy-on-Write Page Replacement.
CS 311 – Lecture 21 Outline Memory management in UNIX
Modified from Silberschatz, Galvin and Gagne Lecture 16 Chapter 8: Main Memory.
Chapter 9: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 9: Memory Management Background.
Memory Management.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 9: Virtual Memory Background.
1 Friday, June 30, 2006 "Man's mind, once stretched by a new idea, never regains its original dimensions." - Oliver Wendell Holmes, Jr.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Chapter 7: Main Memory CS 170, Fall Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
Silberschatz, Galvin and Gagne  Operating System Concepts Multistep Processing of a User Program User programs go through several steps before.
Main Memory. Background Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are only.
03/17/2008CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
CSCI 315 Operating Systems Design
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Chapter 8: Main Memory.
Chapter 8 Main Memory Bernard Chen Spring Objectives To provide a detailed description of various ways of organizing memory hardware To discuss.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, Operating System Concepts Operating Systems Lecture 24 Paging.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Background Program must be brought.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
8.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 8: Memory Management.
Page 19/11/2015 CSE 542: Graduate Operating Systems Review  Chapter 9: Memory management  Swapping  Contiguous Allocation  Paging  Segmentation 
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 8: Main Memory.
Example of a Resource Allocation Graph CS1252-OPERATING SYSTEM UNIT III1.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 32 Paging Read Ch. 9.4.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 8 Operating Systems.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 8: Main Memory.
Swapping and Contiguous Memory Allocation. Multistep Processing of a User Program User programs go through several steps before being run. Program components.
Operating Systems Chapter 8
Memory Management. Process must be loaded into memory before being executed. Memory needs to be allocated to ensure a reasonable supply of ready processes.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
8.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 8: Memory-Management Strategies Objectives To provide a detailed description.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Silberschatz and Galvin  Operating System Concepts Module 8: Memory Management Background Logical versus Physical Address Space Swapping Contiguous.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
CE Operating Systems Lecture 14 Memory management.
Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
Silberschatz and Galvin  Operating System Concepts Workshop 3: Agenda Homework review Study group presentations Lecture – memory concepts Group.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 8: Memory Management n.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Memory and Addressing It all starts.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual-Memory Management.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 8: Main Memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition, Chapter 8: Memory- Management Strategies.
Main Memory CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
8.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 8: Memory-Management Strategies.
Chapter 8: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
Operating System Concepts
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Multistep Processing of a User Program
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
So far… Text RO …. printf() RW link printf Linking, loading
Main Memory Background Swapping Contiguous Allocation Paging
Chapter 8: Memory management
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
Chapter 8: Memory Management strategies
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
Page Main Memory.
Presentation transcript:

Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 13: Main Memory (Chapter 8)

13.2 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Background Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are only storage CPU can access directly Register access in one CPU clock (or less) Main memory can take many cycles Cache sits between main memory and CPU registers Protection of memory required to ensure correct operation Logical vs. Physical address space: Logical address: generated by the CPU. Also called virtual address. Physical address: the address seen by the memory unit.

13.3 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Binding of Instructions and Data to Memory Address binding of instructions and data to memory addresses can happen at three different stages Compile time: If memory location known a priori, absolute code can be generated; must recompile code if starting location changes Load time: If not, the compiler must generate relocatable code. Final binding happens at load time. Execution time: Binding delayed until run time if the process can be moved during its execution from one memory segment to another. Need hardware support for address maps (e.g., base and limit registers) How are logical and virtual addresses in each of these cases? (i.e., identical or different?)

13.4 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Memory-Management Unit ( MMU ) Hardware device that maps virtual to physical address In MMU scheme, the value in the relocation register is added to every address generated by a user process at the time it is sent to memory The user program deals with logical addresses; it never sees the real physical addresses Dynamic relocation using a relocation register

13.5 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Base and Limit Registers A pair of base and limit registers define the logical address space

13.6 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition How To Protect Processes? Relocation registers used to protect user processes from each other, and from changing operating-system code and data Base register contains value of smallest physical address Limit register contains range of logical addresses MMU maps logical address dynamically

13.7 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Swapping

13.8 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Memory Allocation Problem: how to allocate memory for multiple processes (in a multi-programming environment) Solutions: Contiguous allocation  Fixed partitions  Dynamic partitions Paging

13.9 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Contiguous Allocation (Fixed Partitions) (a) Separate input queues for each partition (b) Single input queue

13.10 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Contiguous Allocation (Dynamic Partitions) Main memory usually into two partitions: Resident operating system, usually held in low memory with interrupt vector User processes, held in high memory Multiple-partition allocation Hole – block of available memory; holes of various size are scattered throughout memory When a process arrives, it is allocated memory from a large enough hole Operating system maintains information about: a) allocated partitions b) free partitions (hole) OS process 5 process 8 process 2 OS process 5 process 2 OS process 5 process 2 OS process 5 process 9 process 2 process 9 process 10

13.11 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Dynamic Storage-Allocation Problem First-fit: Allocate the first hole that is big enough Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size Produces the smallest leftover hole Worst-fit: Allocate the largest hole; must also search entire list Produces the largest leftover hole How to satisfy a request of size n from a list of free holes Statistics: First-fit and best-fit better than worst-fit in terms of speed and storage utilization Fragmentation: for N allocated blocks, another N/2 wasted due to fragmentation

13.12 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Fragmentation External Fragmentation – total memory space exists to satisfy a request, but it is not contiguous Internal Fragmentation – allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used Reduce external fragmentation by compaction Shuffle memory contents to place all free memory together in one large block Compaction is possible only if relocation is dynamic, and is done at execution time I/O problem  Latch job in memory while it is involved in I/O  Do I/O only into OS buffers Can be very slow: 256MB of memory, copy 4 bytes in 40ns  compacting memory in 2.7 sec  Almost never used

13.13 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Paging Key idea: physical address space of a process can be noncontiguous Divide physical memory into fixed-sized blocks called frames (size is power of 2, between 512 and 8,192 bytes) Divide logical memory into blocks of same size called pages To run a program of size n pages, need to find n free frames and load program Set up a page table to translate logical to physical addresses

13.14 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Paging Example 32-byte memory and 4-byte pages

13.15 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Address Translation Scheme 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 For given logical address space 2 m and page size 2 n page number page offset p d m - n n

13.16 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Paging Hardware

13.17 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition From an Undergrad Exam In practice, why is it preferred that the number of frames in memory is a power of two? Write brief answers to the following questions (on memory allocation): What is the difference between fixed partitioning and dynamic partitioning? What do fixed partitioning and dynamic partitioning suffer from, respectively? What does paging allow to do that was not possible with partitioning? Cite important differences between virtual paging and simple paging.

13.18 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition When a New Process is Created… Before allocation After allocation How large can the logical address space be?

13.19 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory That is Larger Than Physical Memory  Key Idea: Only part of the program needs to be in memory for execution Needs: Demand paging (or demand segmentation)

13.20 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Demand Paging Bring a page into memory only when it is needed Less I/O needed Less memory needed Faster response More users Page is needed  reference to it invalid reference  abort not-in-memory  bring to memory Lazy swapper – never swaps a page into memory unless page needed Swapper that deals with pages is a pager

13.21 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Valid-Invalid Bit With each page table entry a valid–invalid bit is associated (v  in-memory, i  not-in-memory) Initially valid–invalid bit is set to i on all entries During address translation, if valid–invalid bit in page table entry is i  page fault

13.22 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Page Fault If there is a reference to a page, first reference to that page will trap to operating system: page fault

13.23 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Performance of Demand Paging Page Fault Rate 0  p  1.0 if p = 0 no page faults if p = 1, every reference is a fault Effective Access Time (EAT) EAT = (1 – p) x memory access + p (page fault overhead + swap page out + swap page in + restart overhead )

13.24 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Demand Paging Example Memory access time = 200 nanoseconds Average page-fault service time = 8 milliseconds EAT = (1 – p) x p (8 milliseconds) = (1 – p x p x 8,000,000 = p x 7,999,800 If one access out of 1,000 causes a page fault, then EAT = 8.2 microseconds. This is a slowdown by a factor of 40!!

13.25 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Copy-on-Write Copy-on-Write (COW) allows processes to initially share the same pages in memory If a process modifies a shared page, only then is the page copied

13.26 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition After Process 1 Modifies Page C

13.27 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition What happens if there is no free frame?

13.28 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Page Replacement Algorithms Performance objective: lowest page-fault rate Evaluate algorithm by running it on a particular string of memory references (reference string) and computing the number of page faults on that string Common page replacement algorithms: FIFO Least Recently Used Optimal (theoretical only) Counting: LFU and MFU... Countless others in the literature

13.29 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Allocation of Frames Each process needs minimum number of pages Two major allocation schemes fixed allocation priority allocation Global vs. local page replacement Global replacement – process selects a replacement frame from the set of all frames; one process can take a frame from another Local replacement – each process selects from only its own set of allocated frames

13.30 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Reading for Tuesday C. Waldspurger. Memory Resource Management in VMware ESX Server in Proceedings of the 5th Symposium on Operating Systems Design and Implementation, 2002 Multiplexing memory between guest OSes: -What if OS1 needs more than OS2? -What if OS3 is not using its share of memory and OS1 needs more? -What if OS1, …, OS10 all use the same (large) OS libraries – 10 copies in memory? … while: -Not modifying the guest OS (unlike Xen) -Not knowing how each OS does its memory management

13.31 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Memory Protection Valid (v) or Invalid (i) Bit In A Page Table