CS 261 Fall Mike Lam, Professor. Virtual Memory

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

virtual memory Page 1 CSE 361S Disk Disk

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

Virtual Memory Oct. 29, 2002

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

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

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

CISC 360. Virtual Memory Dec. 4, 2008

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

Processes and Virtual Memory Concepts

@2010 Badri Computer Architecture Assembly II. Virtual Memory. Topics (Chapter 9) Motivations for VM Address translation

Computer Systems. Virtual Memory. Han, Hwansoo

Virtual Memory: Concepts

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: CONCEPTS

Lecture 19: Virtual Memory: Concepts

CSE 153 Design of Operating Systems

14 May 2012 Virtual Memory. Definition: A process is an instance of a running program

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

198:231 Intro to Computer Organization. 198:231 Introduction to Computer Organization Lecture 14

Virtual Memory. Computer Systems Principles

Carnegie Mellon. 16 th Lecture, Mar. 20, Instructors: Todd C. Mowry & Anthony Rowe

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

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

Virtual Memory Nov 9, 2009"

Virtual Memory: Concepts

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

Memory Management! Goals of this Lecture!

Systems Programming and Computer Architecture ( ) Timothy Roscoe

VM as a cache for disk

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

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

Understanding the Design of Virtual Memory. Zhiqiang Lin

18-447: Computer Architecture Lecture 16: Virtual Memory

Memory Management. Goals of this Lecture. Motivation for Memory Hierarchy

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

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

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

This lecture. Virtual Memory. Virtual memory (VM) CS Instructor: Sanjeev Se(a

Memory Management! How the hardware and OS give application pgms:" The illusion of a large contiguous address space" Protection against each other"

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 24

Handout 4 Memory Hierarchy

CIS Operating Systems Memory Management Cache and Demand Paging. Professor Qiang Zeng Spring 2018

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

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

Recap: Memory Management

Storage Management 1

CIS Operating Systems Memory Management Cache. Professor Qiang Zeng Fall 2017

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

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

Virtual Memory I. CSE 351 Spring Instructor: Ruth Anderson

Last 2 Classes: Introduction to Operating Systems & C++ tutorial. Today: OS and Computer Architecture

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

CSE 120 Principles of Operating Systems

Virtual Memory: From Address Translation to Demand Paging

John Wawrzynek & Nick Weaver

CS399 New Beginnings. Jonathan Walpole

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 27, FALL 2012

Chapter 8. Virtual Memory

Address spaces and memory management

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

New-School Machine Structures. Overarching Theme for Today. Agenda. Review: Memory Management. The Problem 8/1/2011

Memory Management. Goals of Memory Management. Mechanism. Policies

Virtual Memory II CSE 351 Spring

PROCESS VIRTUAL MEMORY PART 2. CS124 Operating Systems Winter , Lecture 19

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

Roadmap. Java: Assembly language: OS: Machine code: Computer system:

Virtual Memory: Concepts

Processes, Address Spaces, and Memory Management. CS449 Spring 2016

Virtual Memory. CS 3410 Computer System Organization & Programming

CS 3733 Operating Systems:

CIS Operating Systems Memory Management Cache. Professor Qiang Zeng Fall 2015

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Physical memory vs. Logical memory Process address space Addresses assignment to processes Operating system tasks Hardware support CONCEPTS 3.

CS 31: Intro to Systems Virtual Memory. Kevin Webb Swarthmore College November 15, 2018

ECE 598 Advanced Operating Systems Lecture 14

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

CPE300: Digital System Architecture and Design

Virtual Memory. Alan L. Cox Some slides adapted from CMU slides

ECE 571 Advanced Microprocessor-Based Design Lecture 12

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

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 27, SPRING 2013

Memory Management - Demand Paging and Multi-level Page Tables

CSE 351. Virtual Memory

Princeton University. Computer Science 217: Introduction to Programming Systems. The Memory/Storage Hierarchy and Virtual Memory

16 Sharing Main Memory Segmentation and Paging

Virtual Memory. Yannis Smaragdakis, U. Athens

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

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

CS162 - Operating Systems and Systems Programming. Address Translation => Paging"

CS 153 Design of Operating Systems Winter 2016

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

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

Operating Systems, Fall

Operating Systems, Fall

Transistor: Digital Building Blocks

Virtual Memory. Kevin Webb Swarthmore College March 8, 2018

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

Virtual Memory. CS 351: Systems Programming Michael Saelee

CS162 Operating Systems and Systems Programming Lecture 10 Caches and TLBs"

Transcription:

CS 261 Fall 2016 Mike Lam, Professor Virtual Memory

Topics Operating systems Address spaces Virtual memory Address translation Memory allocation

Lingering questions What happens when you call malloc()? How exactly is memory allocated? What is the correspondence between addresses in machine code and physical memory cells? Are Y86 operand addresses used by the hardware?

Lingering questions What happens when you call malloc()? How exactly is memory allocated? What is the correspondence between addresses in machine code and physical memory cells? Are Y86 operand addresses used by the hardware? There s a gap here... In early machines, there was no gap; the machine ran one program at a time and every program had complete control of the machine there was no need for malloc() Modern machines support multi-tasking, so this is not sufficient What we need is some kind of system software to mediate between user programs and the hardware

Operating systems An operating system (OS) is systems software that provides essential / fundamental system services Manages initialization (booting) and cleanup (shutdown) Manages hardware/software interactions (I/O) Manages running programs (scheduling) Manages memory (virtual memory) Manages data (file systems) Manages external devices (drivers & interrupts) Manages communication (networking) Manages security (permissions)

Kernel The OS kernel is the core piece of software that has complete control over the system Direct access to all hardware ( kernel mode ) All other software runs in user mode Design philosophies: monolithic kernels vs. microkernels Classic debate: Tanenbaum vs. Torvalds Often designed to be small but extensible gnu Plugins are called drivers Technically, Linux is a kernel The operating system is GNU/Linux Tux Combination of Linux kernel and GNU userspace utilities

OS abstractions The OS provides many useful abstractions so that programs don t need to handle hardware details CS 450 covers operating systems in detail In this class: Virtual memory: logical view of memory hierarchy Process: logical view of a program running on a CPU Thread: logical flow of execution in a program File: logical view of data on a disk

Virtual memory Kernel translates between virtual and physical addresses Goals: Use main memory as a cache for disks Provide every process with a uniform view of memory Protect processes from interference No virtual memory With virtual memory

Address spaces An address space is an ordered set of non-negative integer addresses Ex: { 0, 1, 2, 3,, 499, 500 } Linear address spaces don t skip any addresses Two address spaces: virtual and physical Every byte has two addresses (virtual and physical) Example: Y86 programs have a virtual address space with addresses that range from 0x0 to 0x1000, which is large enough to store 4K bytes

Virtual memory Fixed-sized memory partitioning Virtual address space into virtual pages Physical address space into physical pages (or frames) Pages are usually relatively large (4 KB to 2 MB) Virtual memory uses RAM as a cache for pages Process uses consistent virtual / logical addresses OS translates these to physical addresses as necessary Use a table for fast lookups! We will assume hardware handles L1, L2, & L3 SRAM caches

Virtual memory Virtual page groups: Unallocated: uninitialized pages Cached: allocated pages currently cached in physical memory Uncached: allocated pages not currently cached

Page tables Page table: OS data structure for page lookups (array of page table entries) DRAM cache misses (called page faults) are very expensive Disks are MUCH slower than DRAM Transferring pages back and forth is called paging or swapping before page fault on VP 3 after page fault on VP 3

Address translation Memory management unit (MMU) On-chip CPU component for address translation Goal: perform translation as quickly as possible Translation lookaside buffer (TLB) Small cache of PTEs in MMUs Provides faster address translations (in most cases) It s caches all the way down

Virtual memory caveats Virtual memory works well if a program has good locality Especially temporal locality This is a compelling reason to design for good locality Virtual memory works well if a program has a working set that fits in main memory If this is not true, the system may need to continuously swap pages in and out This is called thrashing, and is a significant cause of poor program performance Can be detected by profilers (via counting page faults)

Memory management Operating system provides memory allocation service mmap system call (malloc uses this) Creates virtual memory allocation Private regions: changes are only seen by owner Private, variable-sized region called the heap Shared regions: changes are seen by all processes Usually between heap and stack Multiple virtual addresses map to the same physical address Changes are seen by all processes Usually a read-only region for shared library code

Process address spaces Kernel uses higher addresses Typical Linux process address space

Process address spaces OSes maintain a separate page table for every process Provides program linking consistency E.g., code always begins at 0x400000 Simplifies efficient loading Don t actually load data from disk until needed (more efficient than P2!) Streamlines library sharing Keep one physical copy with multiple virtual mappings Simplifies memory allocation malloc() doesn t need to find contiguous physical memory Improves security Processes can t see/edit each others address spaces

Memory allocation Explicit memory allocation Programmer must allocate and deallocate manually Example: malloc and free in C Implicit memory allocation Programmers allocate manually, then a garbage collector determines when memory can be de-allocated safely Approaches: reference counting and mark & sweep

After the break We will continue discussing OS principles Layers of abstraction that simplify development Theme: systems software is a foundation If you like this material, plan on taking CS 450