The cow and Zaphod... Virtual Memory #2 Feb. 21, 2007

Similar documents
Virtual Memory #2 Feb. 21, 2018

Virtual Memory #3 Oct. 10, 2018

Address spaces and memory management

CS 153 Design of Operating Systems Winter 2016

Recap: Memory Management

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

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

CSE 120 Principles of Operating Systems

CSE 120 Principles of Operating Systems Spring 2017

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

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

CS 318 Principles of Operating Systems

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

16 Sharing Main Memory Segmentation and Paging

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

CSE 153 Design of Operating Systems

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

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

Memory management, part 3: outline

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

CS162 Operating Systems and Systems Programming Lecture 12. Address Translation. Page 1

Virtual Memory I. Jo, Heeseung

Virtual Memory. Computer Systems Principles

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

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

EECS 482 Introduction to Operating Systems

OPERATING SYSTEM. Chapter 9: Virtual Memory

Memory management, part 3: outline

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

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Memory Management - Demand Paging and Multi-level Page Tables

Learning Outcomes. An understanding of page-based virtual memory in depth. Including the R3000 s support for virtual memory.

Another View of the Memory Hierarchy. Lecture #25 Virtual Memory I Memory Hierarchy Requirements. Memory Hierarchy Requirements

How to create a process? What does process look like?

Virtual Memory Outline

Learning Outcomes. An understanding of page-based virtual memory in depth. Including the R3000 s support for virtual memory.

Virtual Memory II CSE 351 Spring

CS399 New Beginnings. Jonathan Walpole

Memory Mapping. Sarah Diesburg COP5641

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 24

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

15 Sharing Main Memory Segmentation and Paging

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

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

VIRTUAL MEMORY. Operating Systems 2015 Spring by Euiseong Seo

Virtual Memory. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Multi-Process Systems: Memory (2) Memory & paging structures: free frames. Memory & paging structures. Physical memory

Chapter 8: Virtual Memory. Operating System Concepts

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

CS370 Operating Systems

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Memory management: outline

Memory management: outline

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

memory management Vaibhav Bajpai

Solution to the. Gaming Parlor. Programming Project

CS510 Operating System Foundations. Jonathan Walpole

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

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

Operating Systems. Memory Management. Lecture 9 Michael O Boyle

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

Opera&ng Systems ECE344

Outline. V Computer Systems Organization II (Honors) (Introductory Operating Systems) Advantages of Multi-level Page Tables

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

Virtual Memory 2: demand paging

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

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

CIS Operating Systems Memory Management Address Translation for Paging. Professor Qiang Zeng Spring 2018

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

Memory Management. Memory Management

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

Module 8: Memory Management

Chapter 10: Virtual Memory

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

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

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

Virtual Memory. 1 Administrivia. Tom Kelliher, CS 240. May. 1, Announcements. Homework, toolboxes due Friday. Assignment.

Operating System Concepts 9 th Edition

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

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

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

Lecture 4: Memory Management & The Programming Interface

Computer Systems. Virtual Memory. Han, Hwansoo

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

CSE 560 Computer Systems Architecture

Memory management OS

Virtual Memory. ICS332 Operating Systems

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

Distributed Systems Operation System Support

Simple idea 1: load-time linking. Our main questions. Some terminology. Simple idea 2: base + bound register. Protection mechanics.

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

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

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

Chapter 9 Memory Management

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

Pentium/Linux Memory System March 17, 2005

Chapter 8: Memory-Management Strategies

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

Transcription:

15-410...The cow and Zaphod... Virtual Memory #2 Feb. 21, 2007 Dave Eckhardt Bruce Maggs 1 L16_VM2

Wean Synchronization Watch for exam e-mail Please answer promptly Computer Club demo night Thursday (2/22) 7500, 19:00 Computer Club introduction Demos menagerie of hardware, software (old games) Movie: Tron 2

Last Time Mapping problem: logical vs. physical addresses Contiguous memory mapping (base, limit) Swapping taking turns in memory Paging Array mapping page numbers to frame numbers Observation: typical table is sparsely occupied Response: some sparse data structure (e.g., 2-level array) 3

Swapping Multiple user processes Sum of memory demands > system memory Goal: Allow each process 100% of system memory Take turns Temporarily evict process(es) to disk Swap daemon shuffles process in & out Can take seconds per process Creates external fragmentation problem 4

External Fragmentation ( Holes ) Process 3 Process 3 Process 1 Process 2 Process 4 Process 2 Process 4 Process 1 OS Kernel OS Kernel 5

Benefits of Paging Process growth problem Any process can use any free frame for any purpose Fragmentation compaction problem Process doesn't need to be contiguous Long delay to swap a whole process Swap part of the process instead! 6

Partial Residence P0 stack 0 P0 data 0 P0 code 1 P0 code 0 [free] P1 data 1 P0 stack 0 P1 stack 0 P1 data 0 P0 data 0 [free] P0 code 0 OS Kernel P1 stack 0 P1 data 1 P1 data 0 P1 code 0 7

Page Table Entry (PTE) flags Protection bits set by OS Read/write/execute Valid/Present bit set by OS Dirty bit Frame pointer is valid, no need to fault Hardware sets 0 1 when data stored into page OS sets 1 0 when page has been written to disk Reference bit Hardware sets 0 1 on any data access to page OS uses for page eviction (below) 8

Outline Partial memory residence (demand paging) in action The task of the page fault handler Big speed hacks Sharing memory regions & files Page replacement policies 9

Partial Memory Residence Error-handling code not used by every run No need for it to occupy memory for entire duration... Tables may be allocated larger than used player players[max_players]; Computer can run very large programs Much larger than physical memory As long as active footprint fits in RAM Swapping can't do this Programs can launch faster Needn't load whole program before running 10

Demand Paging Use RAM frames as a cache for the set of all pages Some pages are fast to access (in a RAM frame) Some pages are slow to access (in a disk frame ) Page tables indicate which pages are resident Non-resident pages have present=0 in page table entry Memory access referring to page generates page fault Hardware invokes page-fault exception handler 11

Page fault Reasons, Responses Address is invalid/illegal deliver software exception Unix SIGSEGV Mach deliver message to thread's exception port 15-410 kill thread Process is growing stack give it a new frame Cache misses - fetch from disk Where on disk, exactly? 12

Satisfying Page Faults stack Free-frame pool bss data code Paging Space Filesystem 13

Page fault story - 1 Process issues memory reference TLB: miss PT: not present Trap to OS kernel! Processor dumps trap frame onto kernel stack (x86) Transfers via page fault interrupt descriptor table entry Runs trap handler 14

Page fault story 2 Classify fault address Illegal address deliver an ouch, else... Code/rodata region of executable? Determine which sector of executable file Launch read() from file into an unused frame Previously resident r/w data, paged out somewhere on the paging partition Queue disk read into an unused frame First use of bss/stack page Allocate a frame full of zeroes, insert into PT 15

Page fault story 3 Put process to sleep (for most cases) Switch to running another Handle I/O-complete interrupt Fill in PTE (present = 1) Mark process runnable Restore registers, switch page table Faulting instruction re-started transparently Single instruction may fault more than once! 16

Memory Regions vs. Page Tables What's a poor page fault handler to do? Kill process? Copy page, mark read-write? Fetch page from file? Which? Where? Page table not a good data structure Format defined by hardware Per-page nature is repetitive Not enough bits to encode OS metadata Disk sector address can be > 32 bits 17

Dual-view Memory Model Logical Physical Process memory is a list of regions Holes between regions are illegal addresses Per-region methods fault(), evict(), unmap() Process memory is a list of pages Faults delegated to per-region methods Many invalid pages can be made valid But sometimes a region fault handler returns error» Handle as with hole case above 18

Page-fault story (for real) Examine fault address Look up: address region region->fault(addr, access_mode) Quickly fix up problem Or start fix, put process to sleep, run scheduler 19

Demand Paging Performance Effective access time of memory word (1 p miss ) * T memory + p miss * T disk Textbook example (a little dated) T memory 100 ns T disk 25 ms p miss = 1/1,000 slows down by factor of 250 slowdown of 10% needs p miss < 1/2,500,000!!! 20

Speed Hacks COW ZFOD (Zaphod?) Memory-mapped files What msync() is supposed to be used for... 21

Copy-on-Write fork() produces two very-similar processes Same code, data, stack Expensive to copy pages Many will never be modified by new process Especially in fork(), exec() case Share physical frames instead of copying? Easy: code pages read-only Dangerous: stack pages! 22

Copy-on-Write 23 Simulated copy Copy page table entries to new process Mark PTEs read-only in old & new Done! (saving factor: 1024) Simulation is excellent as long as process doesn't write... Making it real Process writes to page (Oops! We lied...) Page fault handler responsible Kernel makes a copy of the shared frame Page tables adjusted»...each process points page to private frame»...page marked read-write in both PTEs

Example Page Table Virtual Address VRW f981 --- --- VRW f029 VRX f237 Page table stack code data 24

Copy-on-Write of Address Space P0 VRW --- VRW VRX f981 --- f029 f237 stack P9 VRW --- VRW VRX f981 --- f029 f237 code data 25

Memory Write Permission Fault P0 VRW --- VRW VRX f981 --- f029 f237 stack P9 VRW --- VRW VRX f981 --- f029 f237 code data 26

Copy Into Blank Frame P0 VRW --- VRW VRX f981 --- f029 f237 stack stack P9 VRW --- VRW VRX f981 --- f029 f237 code data 27

Adjust PTE frame pointer, access P0 VRW --- VRW VRX f982 --- f029 f237 stack stack P9 VRW --- VRW VRX f981 --- f029 f237 code data 28

Zero Pages Very special case of copy-on-write ZFOD = Zero-fill on demand Many process pages are blank All of bss New heap pages New stack pages 29 Have one system-wide all-zero frame Everybody points to it Logically read-write, physically read-only Reads of zeros are free Writes cause page faults & cloning

Memory-Mapped Files Alternative interface to read(),write() Benefits mmap(addr, len, prot, flags, fd, offset) new memory region presents file contents write-back policy typically unspecified unless you msync()... Avoid serializing pointer-based data structures Reads and writes may be much cheaper Look, Ma, no syscalls! 30

Memory-Mapped Files Implementation Memory region remembers mmap() parameters Page faults trigger read() calls Pages stored back via write() to file Shared memory Two processes mmap() the same way Point to same memory region 31

Summary Process address space Logical: list of regions Hardware: list of pages Fault handler is complicated Page-in, copy-on-write, zero-fill,... Understand definition & use of Dirty bit Reference bit 32