CS420: Operating Systems

Similar documents
Chapter 8: Memory Management. Operating System Concepts with Java 8 th Edition

Main Memory (Part I)

Chapter 7: Main Memory. Operating System Concepts Essentials 8 th Edition

Background. Contiguous Memory Allocation

Performance of Various Levels of Storage. Movement between levels of storage hierarchy can be explicit or implicit

CS370 Operating Systems

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

Chapter 8: Main Memory

Chapter 8: Main Memory

Chapter 8: Memory Management

Chapter 8: Memory Management Strategies

Memory Management. CSCI 315 Operating Systems Design Department of Computer Science

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

Chapter 8: Memory- Management Strategies

CS307: Operating Systems

Chapter 8: Main Memory. Operating System Concepts 9 th Edition

CSE 4/521 Introduction to Operating Systems. Lecture 12 Main Memory I (Background, Swapping) Summer 2018

Chapter 8: Main Memory

Chapter 8: Memory Management. Background Swapping Contiguous Allocation Paging Segmentation Segmentation with Paging

Part Three - Memory Management. Chapter 8: Memory-Management Strategies

Chapter 8: Main Memory

8.1 Background. Part Four - Memory Management. Chapter 8: Memory-Management Management Strategies. Chapter 8: Memory Management

Memory Management. Memory Management

Roadmap. Tevfik Koşar. CSC Operating Systems Spring Lecture - XII Main Memory - II. Louisiana State University

Chapter 8: Memory-Management Strategies

Module 8: Memory Management

I.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 8: MEMORY

Chapter 9: Memory Management. Background

Chapter 9 Memory Management Main Memory Operating system concepts. Sixth Edition. Silberschatz, Galvin, and Gagne 8.1

Memory management. Last modified: Adaptation of Silberschatz, Galvin, Gagne slides for the textbook Applied Operating Systems Concepts

Module 8: Memory Management

Module 9: Memory Management. Background. Binding of Instructions and Data to Memory

I.-C. Lin, Assistant Professor. Textbook: Operating System Principles 7ed CHAPTER 8: MEMORY

The Memory Management Unit. Operating Systems. Autumn CS4023

Chapter 8: Memory Management

Logical versus Physical Address Space

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

CHAPTER 8: MEMORY MANAGEMENT. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation

Memory Management. Contents: Memory Management. How to generate code? Background

Chapters 9 & 10: Memory Management and Virtual Memory

Operating Systems. Memory Management. Lecture 9 Michael O Boyle

Chapter 8 Memory Management

Memory Management (1) Memory Management

Memory Management (1) Memory Management. CPU vs. memory. No.8. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

CS307 Operating Systems Main Memory

Main Memory. Electrical and Computer Engineering Stephen Kim ECE/IUPUI RTOS & APPS 1

12: Memory Management

SHANDONG UNIVERSITY 1

Chapter 8: Memory- Manage g me m nt n S tra r t a e t gie i s

Lecture 8 Memory Management Strategies (chapter 8)

6 - Main Memory EECE 315 (101) ECE UBC 2013 W2

CSE 421/521 - Operating Systems Fall Lecture - XII Main Memory Management. Tevfik Koşar. University at Buffalo. October 18 th, 2012.

Memory Management Cache Base and Limit Registers base limit Binding of Instructions and Data to Memory Compile time absolute code Load time

Principles of Operating Systems

Main Memory Yi Shi Fall 2017 Xi an Jiaotong University

Operating systems. Part 1. Module 11 Main memory introduction. Tami Sorgente 1

Chapter 8 Main Memory

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Main Memory. CISC3595, Spring 2015 X. Zhang Fordham University

Chapter 8: Memory- Management Strategies Dr. Varin Chouvatut

CS370: Operating Systems [Spring 2017] Dept. Of Computer Science, Colorado State University

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

P r a t t hr h ee e : e M e M m e o m r o y y M a M n a a n g a e g m e e m n e t 8.1/72

CS370 Operating Systems

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science

Chapter 8: Main Memory. Operating System Concepts 8th Edition

File Systems. OS Overview I/O. Swap. Management. Operations CPU. Hard Drive. Management. Memory. Hard Drive. CSI3131 Topics. Structure.

Outlook. Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The Intel Pentium

Unit-03 Deadlock and Memory Management Unit-03/Lecture-01

Basic Memory Management. Basic Memory Management. Address Binding. Running a user program. Operating Systems 10/14/2018 CSC 256/456 1

Memory Management. Reading: Silberschatz chapter 9 Reading: Stallings. chapter 7 EEL 358

Operating Systems (2INC0) 2017/18

Course: Operating Systems Instructor: M Umair. M Umair

Goals of Memory Management

Memory Management. Frédéric Haziza Spring Department of Computer Systems Uppsala University

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses.

Memory Management. Memory

Memory Management and Protection

CSE325 Principles of Operating Systems. Memory. David P. Duggan. March 6, 2010

Memory Management 9th Week

Memory Management. (SGG, Chapter 08) Objectives. Memory Hierarchy. Outline. Instructor: Dr. Tongping Liu. To describe various memory hardware"

Process. Memory Management

Process. One or more threads of execution Resources required for execution. Memory (RAM) Others

Memory Management. Minsoo Ryu. Real-Time Computing and Communications Lab. Hanyang University.

CS399 New Beginnings. Jonathan Walpole

Memory Management Minsoo Ryu Real-Time Computing and Communications Lab. Hanyang University

Basic Memory Management

Administrivia. Deadlock Prevention Techniques. Handling Deadlock. Deadlock Avoidance

UNIT-III VIRTUAL MEMORY

Topics: Memory Management (SGG, Chapter 08) 8.1, 8.2, 8.3, 8.5, 8.6 CS 3733 Operating Systems

Process. One or more threads of execution Resources required for execution

Memory Management. Dr. Yingwu Zhu

Chapter 9 Memory Management

Last class: Today: Deadlocks. Memory Management

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Memory Management


9.1 Background. In Chapter 6, we showed how the CPU can be shared by a set of processes. As a result of

Memory management: outline

Transcription:

Main Memory James Moscola Department of Engineering & Computer Science York College of Pennsylvania Based on Operating System Concepts, 9th Edition by Silberschatz, Galvin, Gagne

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 Memory unit only sees a stream of addresses, doesn t know if instructions or data Protection of memory required to ensure correct operation 2

Base and Limit Registers A pair of base and limit registers define the logical address space for each process 3

Hardware Address Protection Base and limit registers provide memory protection Prevent a process from accessing memory outside of its own memory space Only the operating system can change the contents of the base and limit registers (must be done in kernel mode) 4

Address Binding Not very convenient to have first user process physical address always at memory address 0x0000 (and subsequent processes following that) Addresses are represented differently at different stages of a program s life - In source code addresses are usually symbolic (e.g. variables, function names) - In compiled code addresses bind to relocatable addresses (a relative address) i.e. 8 bytes from beginning of this program module - Linker or loader will bind relocatable addresses to absolute addresses when program is executed i.e. address = 0x74000 + 0x00008 = 0x74008 - program module starts at 0x74000 - the 8th byte of the program is at 0x74008 5

Binding of Program Instructions and Data to Memory Address binding of program 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: Must generate relocatable code if memory location is not known at compile 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) 6

Logical vs. Physical Address Space The concept of a logical address space that is bound to a separate physical address space is central to proper memory management - Logical address generated by the CPU; also referred to as virtual address - Physical address address seen by the memory unit (refers to physical memory in the machine) Logical and physical addresses are the same in compile-time and load-time address-binding schemes; logical (virtual) and physical addresses differ in execution-time address-binding scheme Logical address space is the set of all logical addresses generated by a program Physical address space is the set of all physical addresses generated by a program 7

Memory-Management Unit (MMU) Hardware device that at run time maps logical address to physical address (for execution-time binding) Consider simple scheme where the value in the relocation register is added to every address generated by a user process at the time it is sent to memory - Base register now called relocation register The user program deals with logical addresses; it never sees the real physical addresses - Execution-time binding occurs when reference is made to location in memory - Logical address bound to physical addresses 8

Dynamic Loading To make better utilization of available memory dynamic loading can be used - Routine is not loaded until it is called - Unused routine is never loaded All routines kept on disk in relocatable load format Useful when large amounts of code are needed to handle infrequently occurring cases (e.g. error routines) No special support from the operating system is required - Implemented through program design - OS can help by providing libraries to implement dynamic loading 9

Dynamic Linking To reduce the size of programs, and thus the disk space required for storage and the memory required for execution, use dynamic linking - Static linking system libraries and program code combined by the loader into the binary program image (i.e. large executable files) - Dynamic linking linking postponed until execution time; smaller executable files that make use of dynamically linked libraries (e.g..dll files) A stub is included in the binary image of a program for each reference to a library routine - Used to locate the appropriate library routine and load it into memory (if it hasn t already been loaded) - Stub replaces itself with the address of the routine, and executes the routine - Subsequent calls to the linked library do not incur a loading penalty Dynamic linking is particularly useful for libraries that are shared amongst many processes 10

Swapping A process can be swapped temporarily out of memory to a backing store (a disk), and then brought back into memory to continue execution - Total physical memory space of processes can exceed physical memory Major part of swap time is transfer time to and from backing store; total transfer time is directly proportional to the amount of memory swapped System maintains a ready-queue of ready-to-run processes which have memory images on disk If using execution-time binding, the process need not be swapped back into the same physical address from whence it came Versions of swapping are found on many systems (i.e., UNIX, Linux, and Windows) - Swapping is normally disabled - Started if memory allocation exceeds some threshold - Disabled again once memory demand reduced below threshold 11

Schematic View of Swapping 12

Context Switch Time Including Swapping If next processes to be put on CPU is not in memory, need to swap out a process and swap in target process Context switch time can then be very high when swapping 100 MB process swapping to hard disk with transfer rate of 50 MB/sec - Plus disk latency of 8 ms - Swap out time of 2008 ms - Plus swap in of same sized process - Total context switch swapping component time of 4016ms (> 4 seconds) 13

Contiguous Allocation Need to allocate memory efficiently, a common approach is contiguous allocation Main memory usually divided into two partitions: - Resident operating system, usually held in low memory - User processes held in high memory - Each process is contained in single contiguous section of memory It is desirable to allow these contiguous memory segments to move around in physical memory 14

Hardware Support for Relocation and Limit Registers Relocation registers used to protect user processes from each other, and from changing operating-system code and data - Relocation register contains value of smallest physical address - Limit register contains range of logical addresses each logical address must be less than the limit register - MMU maps logical address dynamically 15

Memory Allocation When allocating memory, the physical memory is divided into multiple, variable-sized, partitions - Degree of multiprogramming is limited by number of partitions (how many process in memory) - A hole is a block of available memory; holes of various size are scattered throughout memory - When a process arrives, it is allocated memory from a hole large enough to accommodate it - When a process exits, it frees its partition, adjacent free partitions are combined - Operating system maintains information about: a) allocated partitions b) free partitions (holes) OS OS OS OS process 5 process 5 process 5 process 5 process 9 process 9 process 8 process 10 process 2 process 2 process 2 process 2 16

Dynamic Storage-Allocation Problem How should a memory request of size n be satisfied from a list of free holes? Several approaches: - 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 First-fit and best-fit better than worst-fit in terms of speed and storage utilization First-fit is generally the fastest 17

Fragmentation Repeatedly allocating and deallocating memory can lead to fragmentation of available memory (fragmentation of holes) - External Fragmentation memory space exists to satisfy a request, but it is not contiguous; small holes are scattered throughout the physical address space Analysis of first fit allocation reveals that given N blocks allocated, another 0.5 N blocks will be lost to fragmentation - 1/3 of memory may be unusable -> 50-percent rule 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 18

Fragmentation (Cont.) In some instances, may allocate a larger memory block than required by process - Extra space in memory block is unused by process - Internal Fragmentation allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used 19