Operating Systems. IV. Memory Management

Similar documents
Chapter 4 Memory Management. Memory Management

12: Memory Management

Virtual Memory Management

CS399 New Beginnings. Jonathan Walpole

Memory management: outline

Memory management: outline

Chapters 9 & 10: Memory Management and Virtual Memory

stack Two-dimensional logical addresses Fixed Allocation Binary Page Table

Memory Management. Chapter 4 Memory Management. Multiprogramming with Fixed Partitions. Ideally programmers want memory that is.

Virtual Memory Outline

CS450/550 Operating Systems

Memory management. Requirements. Relocation: program loading. Terms. Relocation. Protection. Sharing. Logical organization. Physical organization

CISC 7310X. C08: Virtual Memory. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/22/2018 CUNY Brooklyn College

Modeling Page Replacement: Stack Algorithms. Design Issues for Paging Systems

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

Memory Management. Outline. Memory. Virtual Memory. Instructor: Dr. Tongping Liu

Memory management, part 2: outline. Operating Systems, 2017, Danny Hendler and Amnon Meisels

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

Course Outline. Processes CPU Scheduling Synchronization & Deadlock Memory Management File Systems & I/O Distributed Systems

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

CS370 Operating Systems

Memory management, part 2: outline

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

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

Memory Management. Virtual Memory. By : Kaushik Vaghani. Prepared By : Kaushik Vaghani

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

Chapter 3 - Memory Management

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

Operating Systems Lecture 6: Memory Management II

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

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

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

Background. Contiguous Memory Allocation

Memory Management. Dr. Yingwu Zhu

Basic Memory Management

Chapter 9: Virtual Memory

Chapter 8 Virtual Memory

Operating Systems. II. Processes

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

OPERATING SYSTEM. Chapter 9: Virtual Memory

CS 5523 Operating Systems: Memory Management

Chapter 9 Memory Management

Module 9: Virtual Memory

Chapter 4 Memory Management

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

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management

CS370 Operating Systems

1. Background. 2. Demand Paging

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

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Chapter 8: Main Memory

Operating Systems and Computer Networks. Memory Management. Dr.-Ing. Pascal A. Klein

Chapter 3: Important Concepts (3/29/2015)

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

MODERN OPERATING SYSTEMS. Chapter 3 Memory Management

Module 9: Virtual Memory

Chapter 8 Memory Management

Page replacement algorithms OS

Chapter 8: Memory-Management Strategies

Chapter 8: Virtual Memory. Operating System Concepts

Operating Systems. Memory Management. Lecture 9 Michael O Boyle

Motivation. Memory Management. Memory Management. Computer Hardware Review

CS420: Operating Systems

Preview. Memory Management

CS 3733 Operating Systems:

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Course: Operating Systems Instructor: M Umair. M Umair

CS 5523 Operating Systems: Memory Management (SGG-8)

Move back and forth between memory and disk. Memory Hierarchy. Two Classes. Don t

Memory Management Ch. 3

CS307: Operating Systems

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition

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

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Memory Management. Dr. Yingwu Zhu

Memory Management. Memory Management

Chapter 9: Virtual Memory

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

Chapter 8: Main Memory

Memory Management. Memory Management. G53OPS: Operating Systems. Memory Management Monoprogramming 11/27/2008. Graham Kendall.

Memory management. Knut Omang Ifi/Oracle 10 Oct, 2012

Operating Systems. V. Input / Output

Chapter 9: Virtual Memory. Operating System Concepts 9th Edition

Chapter 8: Memory Management

Operating Systems. V. Input / Output. Eurecom

Memory Management. Fundamentally two related, but distinct, issues. Management of logical address space resource

Memory Management. To improve CPU utilization in a multiprogramming environment we need multiple programs in main memory at the same time.

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

Chapter 10: Virtual Memory

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

OPERATING SYSTEMS. After A.S.Tanenbaum, Modern Operating Systems 3rd edition Uses content with permission from Assoc. Prof. Florin Fortis, PhD

Chapter 9: Virtual-Memory

Virtual Memory III. Jo, Heeseung

MEMORY MANAGEMENT/1 CS 409, FALL 2013

Chapter 9: Virtual Memory. Chapter 9: Virtual Memory. Objectives. Background. Virtual-address address Space

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

Chapter 9: Virtual Memory

Chapter 8: Main Memory

Transcription:

Operating Systems IV. Memory Management Ludovic Apvrille ludovic.apvrille@telecom-paristech.fr Eurecom, office 470 http://soc.eurecom.fr/os/ @OS Eurecom

Outline Basics of Memory Management Hardware Architecture Monoprogramming Multiprogramming Basics of Memory Management Hardware Architecture Monoprogramming Multiprogramming 2/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Memory Hierarchy Hardware Architecture Monoprogramming Multiprogramming 3/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Memory Access Hardware Architecture Monoprogramming Multiprogramming CPU Address bus Data bus Memory Write Read 4/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Memory Protection Hardware Architecture Monoprogramming Multiprogramming Goal Prevent a process to access unauthorized memory Memory used by other processes Memory used by Operating System Interrupt vector, interrupt service routines, kernel, services, etc. Mechanisms Dual Mode and MMU - Memory Management Unit 5/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Monoprogramming Hardware Architecture Monoprogramming Multiprogramming 6/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Hardware Architecture Monoprogramming Multiprogramming Multiprogramming: Issues Process Admittance OS estimates the required memory and allocates it Dynamic Allocation A process may request additional memory space A process may release part of its memory space Process termination OS must release all the allocated memory 7/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Memory Allocation Hardware Architecture Monoprogramming Multiprogramming Main issues Keep track of memory allocations Return requested memory chunks as fast as possible Avoid fragmentation Allocation unit Smallest amount of continuous memory managed by the OS From a few bytes to several KBytes Impact of this size? Keeping track of allocation units Bitmaps Linked Lists 8/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Bitmaps vs. Linked Lists Hardware Architecture Monoprogramming Multiprogramming 9/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Allocation Algorithms Hardware Architecture Monoprogramming Multiprogramming First Fit The system scans the list along until a large enough continuous allocation is found Next Fit Scanning begins at the last position where a free block has been found Performs slightly worse than First Fit Best Fit Scans all the list and takes the smallest free block that is adequate Performs worse than First Fit! Can you guess why? 10/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Hardware Architecture Monoprogramming Multiprogramming Allocation Algorithms (Cont.) Worse Fit Searches for the largest free block Not very good either! Quick Fit Separate lists for most usual size Additional complexity of memory management Merging is expensive But very quick search! 11/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Outline Basics of Memory Management Basics of Memory Management 12/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

: Principle 13/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

When to Swap? is expensive! How much time at least is necessary to swap in a 1 GB process (e.g., Firefox) with a transfer rate of 500 MB / second (Typical transfer rate for a (very good) ssd) May have to perform a swap out before! Swap out When? Memory occupied over threshold A memory allocation request fails Which process to swap out? Recently executed processes (RR scheduling) Processes with lower priorities (Priority-based scheduling) Swap in When a process is ready to execute I/O completed When a large amount of memory freed 14/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Logical vs. Physical Address Space At compilation time, the exact memory location of a program may not be known Two address spaces Virtual address space vs. physical address space Logical / virtual address: address used at CPU level (i.e., addresses generated at compilation time) Physical address: physical address of the RAM Address binding (virtual physical) done at execution time: Memory Management Unit 15/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Memory Management Unit Logical addresses MMU Physical addresses CPU Data bus Memory Write Read 16/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Segmentation of Memory Segment = logical memory unit of variable length Virtual segments mapped to physical memory segments Memory address = segment number + an address within the segment (= offset) 17/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Segmentation of Processes A process is a collection of different types of data Code, stack, heap, etc. Use of several segments per Process 18/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Data Sharing with Segmentation 19/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Limitations of Segmentation Fragmentation Solution: Using algorithms to select segments (e.g., best-fit, first-fit, etc.) Cost of segment expansion! If a process allocates more space in a segment and this segment cannot be expanded, and there is free memory available elsewhere memory segment must be moved 1. Process is blocked 2. OS makes a memory copy segment is moved to another location 3. Process is unblocked Paging! 20/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Basics of Paging Paging allows the logical address space of a process to be non contiguous in physical memory Physical memory All physical memory is cut into fixed-size blocks Physical memory includes swap partitions Logical memory: page Physical memory: frame Virtual memory Address divided into two parts Page number (p) Page offset (d) 21/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

MMU with Paging 22/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Combining Intel 80386 Address Translation 23/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Segmentation and Page Faults Memory protection Process switching: the OS updates the address table MMU detects addresses having no correspondence trap Reasons for segment / page faults The address is invalid i.e., outside of the process address space Process is stopped (segmentation fault) Segment / page has been swapped out The OS must make a swap in operation A segment / page must first be swapped out if memory is full Page Replacement Algorithm 24/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Page Fault Replacement Algorithms Issue: the page-fault rate should be as low as possible FIFO Page Replacement Optimal Page Replacement LRU Page Replacement LRU Approximation Page Replacement Counting-Based Page Replacement... : ongoing research work on this issue 25/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Hardware vs. OS Support Might be system-dependent! Mechanism Address translation Segment / page allocation MMU configuration (choice of active tables, etc.) Segment / page fault Hardware or OS? Hardware OS OS Hardware detection, OS management Finally: Can you tell what are the main interests of MMUs for OS? 26/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Use of Memory in Programs LibC malloc() Process 1 Char * name; name = (char ) ( malloc ( 20 * sizeof(char) ) ); name[0] = 'h'; name[1] = 'i'; name[2] = '!'; name[3] = '\0' brk() OS Process 1 page1 Free mem page3 RAM page1 page2 page3 page4 MMU page2 page4 27/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Outline Basics of Memory Management Basics of Memory Management 28/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Windows and Linux Segments / Pages Linux and Windows: only pages for user processes Many Unix use both techniques Copy and Write (fork()) Frame is first shared If a write operation is performed, frame is duplicated Background daemon Invoked periodically: Page flushing, freeing unused memory Memory mapped Files A file can be mapped onto memory 29/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Windows and Linux (Cont.) Data structures to describe process space Windows Tree structure, each node is called a Virtual Address Descriptor Linux Linked lists (just like most UNIX) of vm area structs OS vs. users process virtual address spaces (x86, 32-bit mode) Higher part: kernel code, and lower part: user code Linux: 3GB for the process, 1GB for the kernel Windows: 2GB for both When switching processes, upper part remains the same 30/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Windows and Linux (Cont.) OS vs. users process virtual address spaces (x86, 64-bit mode) Windows Support since March 2005 (Windows XP Professional x64 Edition). User processes/os: 128 TB of virtual address space (Since Windows 8.1) Linux Since kernel 2.4 (2001) User processes: 128 TB of virtual address space 31/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management

Windows and Linux (Cont.) Windows: Page replacement Clock algorithm: Circular list of pages in memory, with the hand (iterator) pointing to the oldest page in the list Linux: Page replacement Linux 2.2: NRU (Not Recently Used) OS Scans through memory and evicts every page that wasn t accessed since the last scan Since kernel 2.4: LRU (Improved in 2.6: CLOCK-PRO ) Counter is increased when the page is referenced Counter is divided by 2 when it was not referenced kswapd Awakes periodically (e.g., every 1 sec.) Frees memory if enough is not available 32/32 Fall 2017 Institut Mines-Telecom Operating Systems - Memory Management