CS 149: Operating Systems February 26 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak www.cs.sjsu.edu/~mak.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

CSS430 Memory Management Textbook Ch8
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 13: Main Memory (Chapter 8)
Memory Management Chapter 7.
CS 311 – Lecture 21 Outline Memory management in UNIX
1 CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania, Fall 2002 Lecture Note: Memory Management.
Modified from Silberschatz, Galvin and Gagne Lecture 16 Chapter 8: Main Memory.
03/09/2007CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
CS 104 Introduction to Computer Science and Graphics Problems
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Memory Management Chapter 5.
A. Frank - P. Weisberg Operating Systems Real Memory Management.
Operating System Concepts
Silberschatz, Galvin and Gagne  Operating System Concepts Multistep Processing of a User Program User programs go through several steps before.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
Chap 8 Memory Management. Background Program must be brought into memory and placed within a process for it to be run Input queue – collection of processes.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
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.
Lecture 13 L.Mohammad R.Alkafagee1.  The concept of a logical address space that is bound to a separate physical address space is central to proper memory.
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: Memory Management Strategies.
A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,
8.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 8: Memory-Management Strategies Objectives To provide a detailed description.
Ch. 4 Memory Mangement Parkinson’s law: “Programs expand to fill the memory available to hold them.”
Cosc 2150: Computer Organization Chapter 6, Part 2 Virtual Memory.
Chapter 4 Storage Management (Memory Management).
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
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.
CS 149: Operating Systems March 3 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
Memory Management. Introduction To improve both the utilization of the CPU and the speed of its response to users, the computer must keep several processes.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
Basic Memory Management 1. Readings r Silbershatz et al: chapters
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
CS 149: Operating Systems March 5 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 31 Memory Management.
Memory Management 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.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
CHAPTER 3-1, 3-2 MEMORY MANAGEMENT. MEMORY HIERARCHY Small amount of expensive, fast, volatile cache Larger amount of still fast, but slower, volatile.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 8: Main Memory.
Ch. 4 Memory Mangement Parkinson’s law: “Programs expand to fill the memory available to hold them.”
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.
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.
Chapter 9: Memory Management
Memory Management.
CSC 322 Operating Systems Concepts Lecture - 12: by
Main Memory Management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
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.
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.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
Presentation transcript:

CS 149: Operating Systems February 26 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 2 Memory Hierarchy  Small amount of very fast, expensive, volatile cache memory. volatile: contents disappear when the power goes off  Gigabytes of medium-speed, medium-price, volatile main memory. RAM: random access memory  Gigabytes or terabytes of slow, cheap, non-volatile disk storage.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak Memory/Storage Speed Comparisons  Suppose your computer ran at human speeds. 1 CPU cycle: 1 second  Then the time to retrieve one byte from: SRAM  5 seconds DRAM  2 minutes Flash  1 day 3 Hard drive  2 months Tape  1,000 years

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 4 Memory Manager  The memory manager manages the memory hierarchy. Resides in the OS kernel.  Keep track of which parts of memory are in use.  Allocate memory to processes.  Deallocate the memory when the processes complete.  Swap the contents of main memory to and from disk when main memory isn’t large enough to hold all the active processes.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 5 Memory Manager, cont’d  Today’s mobile devices and embedded systems can use simple memory management schemes from the old mainframe days.  Run one application at a time. Share memory between the program and the OS.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 6 Monoprogramming Systems  Three models: OS resides at the “bottom” of main memory.  Formerly used by mainframes and minicomputers.  Rarely used today. OS resides in read-only memory (ROM) at the top of main memory.  Used by some mobile devices and embedded systems. Part of the OS resides in main memory, some parts such as device drivers reside in ROM.  Early PCs: DOS in RAM and the Basic Input Output System (BIOS) in ROM.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 7 Monoprogramming Systems, cont’d Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 8 Multiprogramming with Fixed Partitions  Modern OS’s allow multiple processes to run at the same time. An easy memory management scheme is to divide main memory into fixed-size (possibly unequal-sized) partitions. Partition sizes and boundaries can be configured.  When a process is scheduled to execute, it is entered into the queue for the smallest memory partition large enough to hold it. Any memory left over in the partition is wasted.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 9 Multiprogramming Fixed Partitions, cont’d  What’s inefficient about this scheme? If a larger partition is available but processes are queued for a smaller partition, the available partition isn’t used. Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 10 Multiprogramming Fixed Partitions, cont’d  Use a single queue for all memory partitions. When a partition becomes free, search the queue for a process that can best use the partition size.  Smaller processes may starve. Always have small partitions available. Use an aging algorithm. Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 11 Process Relocation  How can the OS enable processes to run in any part of main memory?  Compiled programs can refer to memory addresses.  You generally do not want a process to be able to run only at specific memory addresses.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 12 Process Relocation Solutions  Whenever a process is loaded into main memory, modify all the addresses used by the code. No longer done on today’s computer systems.  Base and limit registers in the hardware. Whenever a process is loaded, put the address of the start of its partition in the process’s base register and the size of the partition in the limit register. All memory references by the process are relative to the base register and checked against the limit register. Slows down each memory reference.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 13 Process Relocation Solutions, cont’d Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 14 Process Protection  The OS protects processes from each other. Do not allow the code of one process to access the memory of another process. Unless the processes have agree to use shared memory.  Old mainframe technique: Divide main memory into blocks. Assign a protection code to each block. Each process uses a key code that allows the process to access memory blocks with only certain protection codes.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 15 Address Binding Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 16 Address Binding, cont’d  A programming language compiler will bind symbolic addresses used in a program to relocatable addresses.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 17 Address Binding, cont’d  Example: The memory location of variable X is 24 bytes from the beginning of the code module. The “address” 24 is relocatable because it’s relative to the start of the code module.  At run time, the code module can be placed anywhere in main memory, but variable X will always be 24 bytes from the beginning of the module.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 18 Compile-Time Binding  Suppose it is known at program compile time exactly where in physical main memory the program will run.  The compiler can generate absolute code with physical memory addresses.  If the program needs to run elsewhere in main memory, it will have to be recompiled.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 19 Load-Time Binding  The compiler generates relocatable code.   Final address binding is delayed until load time.  If the starting address changes, just reload the program to incorporate the changed address.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 20 Execution-Time Binding  Special hardware enables a process to move during its execution from one memory segment to another.  Most general-purpose operating systems use this feature.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 21 Logical vs. Physical Address Space  Logical address (AKA virtual address) A memory address generated by the CPU while a process is running.  Physical address A memory address seen by the memory manager, such as in the memory-address register.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 22 Logical vs. Physical Address Space, cont’d  Logical address space (AKA virtual address space) The set of all logical addresses generated by a program.  Physical address space The set of all physical addresses corresponding to the logical addresses.  Memory-management unit (MMU) A hardware device that does the runtime mapping from virtual to physical address.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 23 Logical vs. Physical Address Space, cont’d Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 24 Logical vs. Physical Address Space, cont’d  Dynamic relocation using a relocation register. Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 25 Dynamic Loading  Dynamic loading allows only part of a program to be loaded into memory at run time.  Routines are kept on disk as relocatable code.  A routine is not loaded until it’s called.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 26 Dynamic Loading, cont’d  When a routine (already in memory) calls another routine: The caller first checks if the desired routine is already in memory. If not, the relocatable linking loader loads the desired routine into memory and updates the process’s address tables. Then control passes to the newly loaded routine.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 27 Dynamic Linking  Dynamically linked libraries contain routines that are not linked to programs until run time.  Each program no longer needs to statically link to its own copy of the library routines.  Saves disk and memory space.  Microsoft Windows: DLLs

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 28 Dynamic Linking, cont’d  A program that calls a dynamically linked library routine contains a stub for the routine.  The stub serves as a proxy for the library routine.  It appears to the program to be the library routine itself.  At run time, the stub can load and link to the library routine.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 29 Dynamic Linking, cont’d  This is a good way to issue software updates.  Just issue a new version of the dynamically linked library.  Programs that use the library routines don’t need to recompile if the new library version is compatible with the old version.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 30 Swapping  What if there isn’t sufficient main memory to hold all the currently active processes?  Swapping: The process scheduler works with the memory manager to load a process in its entirety from disk into main memory before the process can execute.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 31 Swapping, cont’d  Whenever the process blocks, the process scheduler and memory manager can decide to write the entire process back onto disk.  Free up the process’s memory resources to be available for other processes.  Swapping requires a backing store, usually a very fast hard disk.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 32 Swapping, cont’d Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 33 Swapping, cont’d  The OS maintains a ready queue of processes whose memory images are either On the backing store, or Already in main memory and are ready to run.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 34 Swapping, cont’d  Whenever the process scheduler decides to execute a process, it calls the dispatcher. The dispatcher checks whether the next process in the ready queue is in memory. If the process is not in memory and main memory is already full, the dispatcher can swap out a process currently in memory and swap in the desired process.  Context-switch time can be very expensive. Swapping is disk I/O.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 35 Variable Partition Scheme  The number, location, and sizes of the partitions vary dynamically as processes come and go. More flexible than fixed partitions, but more complex to manage. Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 36 Memory Compaction  Swapping can create multiple “holes” in main memory.  Memory compaction can occur in order to slide processes over to eliminate the holes. Similar to garbage collection by the Java Virtual Machine.  Compaction time may be disruptive to some applications, especially real-time applications that can’t tolerate interruptions.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 37 Memory Demands  A process may demand more memory during execution. Its data segment, stack, or both may grow. Allocate memory to a process with extra “headroom”.  If a process requests more main memory but none is available and the swap area on disk is full, the process must block waiting for memory to become available, or be killed by the OS.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 38 Memory Demands, cont’d Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 39 Keeping Track of Memory  The memory manager must keep track of which parts of main memory are currently allocated to processes and which parts are free.  Bitmaps can keep track of which allocation units are allocated and which are free. 0 = free unit 1 = allocated unit

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 40 Keeping Track of Memory, cont’d  The size of an allocation unit is an important computer system design issue.  A smaller unit size allows finer granularity in allocating memory to processes, but the bitmaps need to be larger.  A larger unit size means smaller bitmaps, but more wasted memory when the amount of memory requested by a process is not a multiple of the allocation unit size.

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 41 Keeping Track of Memory, cont’d  The memory manager can maintain either a bitmap or a linked list of allocated and free memory segments. A segment is either a process or a hole between processes. Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: February 26 CS 149: Operating Systems © R. Mak 42 Keeping Track of Memory, cont’d  A linked list entry changes from “process” to “hole” when the process terminates.  Two adjacent hole entries can coalesce into a single entry for a (larger) hole. Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved