Memory Management. Dr. Yingwu Zhu

Similar documents
Memory Management. Dr. Yingwu Zhu

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

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

Memory Management. Memory Management

Chapter 8: Main Memory

Chapter 8: Main Memory

Chapter 9: Memory Management. Background

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

Module 8: Memory Management

Chapter 8: Memory Management Strategies

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

CS307 Operating Systems Main Memory

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

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

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

Logical versus Physical Address Space

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

Chapter 8: Memory Management

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

CS307: Operating Systems

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

Chapter 8 Memory Management

CS 3733 Operating Systems:

Chapter 8 Main Memory

Goals of Memory Management

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

Memory Management. Memory

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

Module 8: Memory Management

Chapter 8: Main Memory

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

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

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

Chapter 8: Memory-Management Strategies

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

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

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

Lecture 8 Memory Management Strategies (chapter 8)

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

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

CSE 4/521 Introduction to Operating Systems. Lecture 14 Main Memory III (Paging, Structure of Page Table) Summer 2018

Chapter 8: Main Memory

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

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

Chapter 8: Memory- Management Strategies

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

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

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

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

Main Memory (Part II)

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

CS370 Operating Systems

SHANDONG UNIVERSITY 1

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

Principles of Operating Systems

Main Memory Yi Shi Fall 2017 Xi an Jiaotong University

The Memory Management Unit. Operating Systems. Autumn CS4023

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

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

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

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

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

CS3600 SYSTEMS AND NETWORKS

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

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

Chapter 8: Memory Management

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

CS370 Operating Systems

Memory Management. Goals of Memory Management. Mechanism. Policies

Basic Memory Management

Main Memory (Part I)

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

Main Memory (II) Operating Systems. Autumn CS4023

Address Translation. Tore Larsen Material developed by: Kai Li, Princeton University

Chapter 9 Memory Management

Memory Management (2)

Background. Contiguous Memory Allocation

Chapter 8: Memory- Management Strategies Dr. Varin Chouvatut

COSC Operating Systems Design, Fall 2001, Byunggu Yu. Chapter 9 Memory Management (Lecture Note #8) 1. Background

Operating Systems. 09. Memory Management Part 1. Paul Krzyzanowski. Rutgers University. Spring 2015

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

CS399 New Beginnings. Jonathan Walpole

Operating Systems. Memory Management. Lecture 9 Michael O Boyle

CS420: Operating Systems

Chapter 8 Main Memory

Operating Systems Unit 6. Memory Management

COS 318: Operating Systems. Virtual Memory and Address Translation

CS420: Operating Systems. Paging and Page Tables

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

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

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

Fall 2015 COMP Operating Systems. Lab 06

CS 333 Introduction to Operating Systems. Class 11 Virtual Memory (1) Jonathan Walpole Computer Science Portland State University

UNIT-III VIRTUAL MEMORY

12: Memory Management

Memory: Page Table Structure. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

Memory Management and Protection

Paging & Segmentation

CS 143A - Principles of Operating Systems

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

Transcription:

Memory Management Dr. Yingwu Zhu

Big picture Main memory is a resource A process/thread is being executing, the instructions & data must be in memory Assumption: Main memory is super big to hold a program Allocation of memory to processes Address translation Real world: a program and its data is larger than physical memory VM comes to rescue OS needs to manage this resource

First cut Background: Program must be brought into memory and placed within a process for it to be run An assumption for this discussion: Physical memory is large enough to hold an any sized process We will relax this assumption later

Logical vs. Physical Address Space Logical address (virtual address) Generated by the CPU, always starting from 0 Physical address Address seen/required by the memory unit Logical address space is bound to a physical address space Central to proper memory management

Binding logical address space to physical address space Binding instructions & data into memory can happen at 3 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., relocation and limit registers) Logical address = physical address for compile time and load time; logical address!= physical address for execution time

Memory Management Unit (MMU) Hardware device logical address physical address (mapping) Simplest MMU scheme: relocation register The user program deals with logical addresses; it never sees the real physical addresses

Memory Allocation, How? In the context of Multiprocessing, competing for resources Memory is a scarce resource shared by processes Questions: #1: How to allocate memory to processes? #2: What considerations need to be taken in memory allocation? #3: How to manage free space?

Memory Allocation Contiguous allocation Non-contiguous allocation: Paging

Contiguous Allocation Fact: memory is usually split into 2 partitions Low end for OS (e.g., interrupt vector) High end for user processes where allocation happens

Contiguous Allocation Definition: each process is placed in a single contiguous section of memory Single partition allocation Multiple-partition allocation

Contiguous Allocation Single partition allocation, needs hardware support Relocation register: the base physical address Limit register: the range of logical address

Contiguous Allocation Base register + limit register define a logical address space in memory!

Contiguous Allocation Single partition allocation (high-end partition), needs hardware support Relocation register: the base physical address Limit register: the range of logical address Protect user processes from each other, and from changing OS code & data

Protection by Base + Limit Registers Limit register Relocation register Logical Physical CPU address < yes + address Memory no Trap: address error

Contiguous Allocation Multiple-partition allocation Divide memory into multiple fixed-sized partitions Hole: block of free/available memory Holes of various sizes are scattered thru memory When a process arrives, it is allocated from a hole large enough to hold it May create a new hole OS manages Allocated blocks & holes

Multiple-Partition Allocation OS OS OS OS process 5 process 8 process 5 process 5 process 9 rm p8 add p9 add p10 process 5 process 9 process 10 process 2 process 2 process 2 process 2

Multiple-Partition Allocation Dynamic storage allocation problem How to satisfy a request of size n from a list of holes? Three strategies First fit: allocate the first hole large enough Best fit: allocate the smallest hole that is big enough Worst fit: allocate the largest hole First & best fit outperform worst fit (in storage utilization)

Fragmentation Storage allocation produces fragmentation! External fragmentation Total available 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 Why?

Fragmentation Storage allocation produces fragmentation! External fragmentation Total available 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 Why? Memory is allocated in block size rather than in the unit of bytes

Thinking What fragmentations are produced by multiple-partition allocation? What fragmentation is produced by singlepartition allocation? Any solution to eliminate fragmentations?

Memory Allocation Contiguous allocation Non-contiguous allocation: Paging

Paging Memory allocated to a process is not necessarily contiguous Divide physical memory into fixed-sized blocks, called frames (size is power of 2, e.g., 512B 16MB) Divide logical address space into blocks of same size, called pages Memory allocated to a process in one or multiple of frames Page table: maps pages to frames, per-process structure Keep track of all free frames

Paging Example

Address Translation Scheme Logical address Physical address Address generated by the 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

Logical Address Logical address space 2^m p d m-n bits n bits

Address Translation

Exercise Consider a process of size 72,776 bytes and page size of 2048 bytes How many entries are in the page table? What is the internal fragmentation size?

Discussion How to implement page tables? Where to store page tables?

Implementation of Page Tables (1) Option 1: hardware support, using a set of dedicated registers Case study 16-bit address, 8KB page size, how many registers needed for the page table? Using dedicated registers Pros Cons

Implementation of Page Tables (2) Option 2: kept in main memory Page-table base register (PTBR) points to the page table Page-table length register (PTLR) indicates size of the page table Problem?

Implementation of Page Tables (2) Option 2: kept in main memory Page-table base register (PTBR) points to the page table Page-table length register (PTLR) indicates size of the page table Problem?

Implementation of Page Tables (2) Option 2: kept in main memory Page-table base register (PTBR) points to the page table Page-table length register (PTLR) indicates size of the page table Problem? Every data/instruction access requires 2 memory accesses: one for the page table and one for the data/instruction.

Option 2: Using memory to keep page tables How to handle 2-memory-accesses problem?

Option 2: Using memory to keep page tables How to handle 2-memory-accesses problem? Caching + hardware support Use of a special fast-lookup hardware cache called associative memory or translation look-aside buffers (TLBs) Cache page-table entries (LRU, etc.) Expensive but faster Small: 64 1024 entries

Associative Memory Associative memory parallel search Page # Frame # Address translation (A, A ) If A is in associative register, get frame # out Otherwise get frame # from page table in memory

Paging with TLB

Memory Protection Memory protection implemented by associating protection bit with each frame Valid-invalid bit attached to each entry in the page table: valid indicates that the associated page is in the process s logical address space, and is thus a legal page invalid indicates that the page is not in the process s logical address space

Memory Protection

Page Table Structure Hierarchical Paging Hashed page tables Inverted hash tables

Why Hierarchical Paging? Most modern computer systems support a large logical address space, 2^32 2^64 Large page tables Example: 32-bit logical address space, page size is 4KB, then 2^20 page table entries. If address takes 4 bytes, then the page table size costs 4MB Contiguous memory allocation for large page tables may be a problem! Physical memory may not hold a single large page table!

Hierarchical Paging Break up the logical address space into multiple page tables Page table is also paged! A simple technique is a two-level page table

Two-Level Paging Example A logical address (on 32-bit machine with 4K page size) is divided into: A page number consisting of 20 bits what s the page table size in bytes? A page offset consisting of 12 bits Since the page table is paged, the page number is further divided into: A 10-bit page number A10-bit page offset Thus, a logical address is as follows: page number p i p 2 d page offset 10 10 12 where p i is an index into the outer page table, and p 2 is the displacement within the page of the outer page table

Address Translation 2-level 32-bit paging architecture

Address Translation Example

Page Table Structure Hierarchical Paging Hashed page tables Inverted hash tables

Hashed Page Tables A common approach for handling address space > 32 bits The virtual page number is hashed into a page table. This page table contains a chain of elements hashing to the same location. Virtual page numbers are compared in this chain searching for a match. If a match is found, the corresponding physical frame is extracted.

Hashed Page Tables

Page Table Structure Hierarchical Paging Hashed page tables Inverted hash tables

Inverted Page Tables Why need it? How? One entry for each memory frame Each entry consists of the virtual address of the page stored in the memory frame, with info about the process that owns the page: <pid, page #> One page table system wide Pros & Cons

Inverted Hash Tables Pros: reduce memory consumption for page tables Cons: linear search performance!

Exercise Consider a system with 32GB virtual memory, page size is 2KB. It uses 2-level paging. The physical memory is 512MB. Show how the virtual memory address is split in page directory, page table and offset. How many (2nd level) page tables are there in this system (per process)? How many entries are there in the (2nd level) page table? What is the size of the frame number (in bits) needed for implementing this? How large should be the outer page table size?

Summary Basic concepts MMU: logical addr. physical addr. Memory Allocation Contiguous Non-contiguous: paging Implementation of page tables Hierarchical paging Hashed page tables Inverted page tables TLB & effective memory-access time