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

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

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

Memory Management. Goals of Memory Management. Mechanism. Policies

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

Memory Management Topics. CS 537 Lecture 11 Memory. Virtualizing Resources

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

1. Creates the illusion of an address space much larger than the physical memory

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

2 nd Half. Memory management Disk management Network and Security Virtual machine

CS 550 Operating Systems Spring Memory Management: Paging

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

Memory Management. Dr. Yingwu Zhu

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

Virtual Memory. Patterson & Hennessey Chapter 5 ELEC 5200/6200 1

Recall: Address Space Map. 13: Memory Management. Let s be reasonable. Processes Address Space. Send it to disk. Freeing up System Memory

CS399 New Beginnings. Jonathan Walpole

Memory Management. Dr. Yingwu Zhu

CS399 New Beginnings. Jonathan Walpole

Computer Architecture. Lecture 8: Virtual Memory

CS307 Operating Systems Main Memory

Virtual Memory: From Address Translation to Demand Paging

Virtual to physical address translation

Virtual Memory Oct. 29, 2002

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. April 12, 2018 L16-1

Main Memory (Part II)

CSE 120 Principles of Operating Systems Spring 2017

Motivations for Virtual Memory Virtual Memory Oct. 29, Why VM Works? Motivation #1: DRAM a Cache for Disk

CS 318 Principles of Operating Systems

Virtual Memory. Motivations for VM Address translation Accelerating translation with TLBs

virtual memory Page 1 CSE 361S Disk Disk

Virtual Memory. Today. Segmentation Paging A good, if common example

Last Class: Deadlocks. Where we are in the course

CSE 120 Principles of Operating Systems

Virtual Memory 1. To do. q Segmentation q Paging q A hybrid system

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

CS 550 Operating Systems Spring File System

CS 153 Design of Operating Systems Winter 2016

Operating Systems (1DT020 & 1TT802) Lecture 9 Memory Management : Demand paging & page replacement. Léon Mugwaneza

Lecture: Virtual Memory, DRAM Main Memory. Topics: virtual memory, TLB/cache access, DRAM intro (Sections 2.2)

CPS104 Computer Organization and Programming Lecture 16: Virtual Memory. Robert Wagner

Page 1. Review: Address Segmentation " Review: Address Segmentation " Review: Address Segmentation "

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. November 15, MIT Fall 2018 L20-1

CISC 360. Virtual Memory Dec. 4, 2008

Processes and Virtual Memory Concepts

CS 261 Fall Mike Lam, Professor. Virtual Memory

Virtual Memory. Kevin Webb Swarthmore College March 8, 2018

Random-Access Memory (RAM) Systemprogrammering 2007 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

CSE 153 Design of Operating Systems

Random-Access Memory (RAM) Systemprogrammering 2009 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics! The memory hierarchy

Virtual Memory. CS 3410 Computer System Organization & Programming

CS 390 Chapter 8 Homework Solutions

EECS 482 Introduction to Operating Systems

ECE331: Hardware Organization and Design

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

File Systems. Kartik Gopalan. Chapter 4 From Tanenbaum s Modern Operating System

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

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

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

Virtual Memory 1. Virtual Memory

Virtual Memory 1. Virtual Memory

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

CS 153 Design of Operating Systems Winter 2016

Operating Systems, Fall

Operating Systems, Fall

Processes and Tasks What comprises the state of a running program (a process or task)?

CS 3733 Operating Systems:

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

The memory of a program. Paging and Virtual Memory. Swapping. Paging. Physical to logical address mapping. Memory management: Review

Main Memory: Address Translation

CS3600 SYSTEMS AND NETWORKS

Virtual Memory: From Address Translation to Demand Paging

Virtual memory Paging

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

Goals of memory management

Recap: Memory Management

Classifying Information Stored in Memory! Memory Management in a Uniprogrammed System! Segments of a Process! Processing a User Program!

virtual memory. March 23, Levels in Memory Hierarchy. DRAM vs. SRAM as a Cache. Page 1. Motivation #1: DRAM a Cache for Disk

Virtual Memory. Physical Addressing. Problem 2: Capacity. Problem 1: Memory Management 11/20/15

I/O. Disclaimer: some slides are adopted from book authors slides with permission 1

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

Virtual Memory 2. q Handling bigger address spaces q Speeding translation

ECE 571 Advanced Microprocessor-Based Design Lecture 12

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

CS307: Operating Systems

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

Chapter 3 - Memory Management

Virtual Memory Review. Page faults. Paging system summary (so far)

Memory Management - Demand Paging and Multi-level Page Tables

Virtual Memory II CSE 351 Spring

Virtual Memory. CS61, Lecture 15. Prof. Stephen Chong October 20, 2011

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

Memory and multiprogramming

Virtual Memory. CS 3410 Computer System Organization & Programming. [K. Bala, A. Bracy, E. Sirer, and H. Weatherspoon]

CS 61C: Great Ideas in Computer Architecture. Lecture 23: Virtual Memory. Bernhard Boser & Randy Katz

Chapter 8 Virtual Memory

Chapter 9 Memory Management

Virtual Memory. P & H Chapter 5.4 (up to TLBs) Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University

Lecture 19: Virtual Memory: Concepts

Transcription:

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

CPU management Roadmap Process, thread, synchronization, scheduling Memory management Virtual memory Disk management Other topics 3

Goals Memory Management Easy to use abstraction Same virtual memory space for all processes Isolation among processes Don t corrupt each other Efficient use of capacity limited physical memory Don t waste memory 4

Virtual memory MMU and TLB Demand paging Concepts to Learn 5

Abstraction Virtual Memory (VM) 4GB linear address space for each process Reality 1GB of actual physical memory shared with 20 other processes How? 6

Hardware support Virtual Memory MMU (memory management unit) TLB (translation lookaside buffer) OS support Manage MMU (sometimes TLB) Determine address mapping Alternatives No VM: many real-time OS (RTOS) don t have VM 7

Virtual Address Process A Process B Process C MMU Physical Memory 8

MMU Hardware unit that translates virtual address to physical address Virtual address Physical address CPU MMU Memory 9

A Simple MMU BaseAddr: base register Paddr = Vaddr + BaseAddr Advantages Fast Disadvantages No protection Wasteful 28000 14000 P3 P2 P1 10

Base + Limit approach A Better MMU If Vaddr > limit, then trap to report error Else Paddr = Vaddr + BaseAddr 11

Base + Limit approach A Better MMU If Vaddr > limit, then trap to report error Else Paddr = Vaddr + BaseAddr Advantages Support protection Support variable size partitions Disadvantages Fragmentation P3 P2 P1 12

Fragmentation External fragmentation total available memory space exists to satisfy a request, but it is not contiguous P4 P3 Free P2, P4 P3 Alloc P5 P3 P2 P5 P1 P1 P1 13

Paging approach Modern MMU Divide physical memory into fixed-sized blocks called frames (e.g., 4KB each) Divide logical memory into blocks of the same size called pages (page size = frame size) Pages are mapped onto frames via a table page table 14

Paging hardware Modern MMU 15

Memory view Modern MMU 16

Virtual Address Translation Virtual address 0x12345678 Page # Ox12345 Offset 0x678 0x678 0x12345 Physical address 0xabcde678 frame #: 0xabcde frame # offset 17

Advantages of Paging No external fragmentation Efficient use of memory Internal fragmentation (waste within a page) still exists 25

Translation speed Issues of Paging Each load/store instruction requires a translation Table is stored in memory Memory is slow to access ~100 CPU cycles to access DRAM 26

Translation Lookaside Buffer (TLB) Cache frequent address translations So that CPU don t need to access the page table all the time Much faster 27

Issues of Paging Page size Small: minimize space waste, requires a large table Big: can waste lots of space, the table size is small Typical size: 4KB How many pages are needed for 4GB (32bit)? 4GB/4KB = 1M pages What is the required page table size? assume 1 page table entry (PTE) is 4bytes 1M * 4bytes = 4MB Btw, this is for each process. What if you have 100 processes? Or what if you have a 64bit address? 28

Advantages Paging No external fragmentation Two main Issues Translation speed can be slow TLB Table size is big 29

Two-level paging Multi-level Paging 30

Two Level Address Translation Virtual address 1 st level 2 nd level offset Base ptr 1 st level Page table 2 nd level Page Physical address Frame # Offset 31

Example 8 bits 1 st level 8 bits 8 bits 2 nd level offset Virtual address format (24bits) Vaddr: 0x0703FE 1 st level idx: 07 2 nd level idx: 03 Offset: FE Vaddr: 0x072370 1 st level idx: 2 nd level idx: Offset: Vaddr: 0x082370 1 st level idx: 2 nd level idx: Offset: 32

Can save table space How, why? Multi-level Paging Don t need to create all mappings in the outer page table 33

Advantages Recap: Paging No external fragmentation Two main Issues Translation speed can be slow TLB Table size is big Multi-level page table 34

Recap: Two Level Paging Virtual address 1 st level 2 nd level offset Base ptr 1 st level Page table 2 nd level Page Physical address Frame # Offset 35

Quiz What is the page table size for a process that only uses 8MB memory? Common: 32bit address space, 4KB page size Case 1) 1-level page table Assume each page table entry is 4 bytes Answer: 2^20 x 4 byte = 4MB Case 2) two-level page table Assume first 10 bits are used as the index of the first-level page table, next 10 bits are used as the index of the second-level page table. In both-levels, single page table entry size is 4 bytes Answer: 2^10 x 4 + 2 x (2^10 x 4) = 4KB + 8KB = 12KB 36

Quiz What is the page table size for a process that only uses 16MB memory? Common: 32bit address space, 4KB page size Case 1) 1-level page table Assume each page table entry is 4 bytes Answer: 2^20 x 4 byte = 4MB Case 2) two-level page table Assume first 10 bits are used as the index of the first-level page table, next 10 bits are used as the index of the second-level page table. In both-levels, single page table entry size is 4 bytes Answer: 2^10 x 4 + 4 x (2^10 x 4) = 4KB + 16KB = 20KB 37