Virtualizing Memory: Paging. Announcements

Similar documents
CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Fall 2017 :: CSE 306. Introduction to. Virtual Memory. Nima Honarmand (Based on slides by Prof. Andrea Arpaci-Dusseau)

! What is main memory? ! What is static and dynamic allocation? ! What is segmentation? Maria Hybinette, UGA. High Address (0x7fffffff) !

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

CS 550 Operating Systems Spring Memory Management: Paging

CS 537 Lecture 6 Fast Translation - TLBs

Operating System Labs. Yuanbin Wu

Operating System Labs. Yuanbin Wu

MEMORY: SWAPPING. Shivaram Venkataraman CS 537, Spring 2019

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

CS399 New Beginnings. Jonathan Walpole

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

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

Administrivia. Lab 1 due Friday 12pm. We give will give short extensions to groups that run into trouble. But us:

Virtual Memory 3. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. P & H Chapter 5.4

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

Introduction to Paging

CS 153 Design of Operating Systems Winter 2016

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Virtual memory Paging

15 Sharing Main Memory Segmentation and Paging

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

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

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

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 13: Address Translation

Lecture 13: Virtual Memory Management. CSC 469H1F Fall 2006 Angela Demke Brown

A.Arpaci-Dusseau. Mapping from logical address space to physical address space. CS 537:Operating Systems lecture12.fm.2

Virtual Memory. CS 3410 Computer System Organization & Programming

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

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

Virtual Memory 2. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. P & H Chapter 5.4

EECS 470. Lecture 16 Virtual Memory. Fall 2018 Jon Beaumont

16 Sharing Main Memory Segmentation and Paging

CS 3733 Operating Systems:

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CS5460: Operating Systems Lecture 14: Memory Management (Chapter 8)

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

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

Memory: Overview. CS439: Principles of Computer Systems February 26, 2018

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

Memory Management. Goals of Memory Management. Mechanism. Policies

memory management Vaibhav Bajpai

CS252 S05. Main memory management. Memory hardware. The scale of things. Memory hardware (cont.) Bottleneck

Motivation for Dynamic Memory. Dynamic Memory Allocation. Stack Organization. Stack Discussion. Questions answered in this lecture:

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

ECE 571 Advanced Microprocessor-Based Design Lecture 12

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

Multi-level Translation. CS 537 Lecture 9 Paging. Example two-level page table. Multi-level Translation Analysis

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

Page 1. Goals for Today" Important Aspects of Memory Multiplexing" Virtualizing Resources" CS162 Operating Systems and Systems Programming Lecture 9

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

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

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

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

Virtual Memory. CS 351: Systems Programming Michael Saelee

ECE 598 Advanced Operating Systems Lecture 14

Preview. Memory Management

CS450/550 Operating Systems

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

CSE 351. Virtual Memory

CS61C : Machine Structures

CS 61C: Great Ideas in Computer Architecture. Virtual Memory

Virtual or Logical. Logical Addr. MMU (Memory Mgt. Unit) Physical. Addr. 1. (50 ns access)

Memory Management. Dr. Yingwu Zhu

Virtual Memory. Virtual Memory

Lecture #15: Translation, protection, sharing

Memory Management - Demand Paging and Multi-level Page Tables

lecture 18 cache 2 TLB miss TLB - TLB (hit and miss) - instruction or data cache - cache (hit and miss)

Virtual memory - Paging

The process. one problem

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

CS 390 Chapter 8 Homework Solutions

CS307 Operating Systems Main Memory

Processes and Virtual Memory Concepts

Agenda. CS 61C: Great Ideas in Computer Architecture. Virtual Memory II. Goals of Virtual Memory. Memory Hierarchy Requirements

CS 537: Introduction to Operating Systems Fall 2016: Midterm Exam #1. All cell phones must be turned off and put away.

CS 61C: Great Ideas in Computer Architecture Virtual Memory. Instructors: John Wawrzynek & Vladimir Stojanovic

Recall from Tuesday. Our solution to fragmentation is to split up a process s address space into smaller chunks. Physical Memory OS.

Operating Systems. Pablo Prieto Torralbo. 3. Memory Virtualizing DEPARTMENT OF COMPUTER ENGINEERING

- Established working set model - Led directly to virtual memory. Protection

Protection. - Programmers typically assume machine has enough memory - Sum of sizes of all processes often greater than physical memory 1 / 36

Virtual Memory. Kevin Webb Swarthmore College March 8, 2018

Changelog. Virtual Memory (2) exercise: 64-bit system. exercise: 64-bit system

Midterm 1. Administrivia. Virtualizing Resources. CS162 Operating Systems and Systems Programming Lecture 12. Address Translation

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

EECS 482 Introduction to Operating Systems

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

12: Memory Management

P & H Chapter 5.7 (up to TLBs) Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University

Computer Architecture Lecture 13: Virtual Memory II

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

CS152 Computer Architecture and Engineering Lecture 18: Virtual Memory

Main Memory: Address Translation


11.1 Segmentation: Generalized Base/Bounds

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

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

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

Virtual Memory: Mechanisms. CS439: Principles of Computer Systems February 28, 2018

238P: Operating Systems. Lecture 5: Address translation. Anton Burtsev January, 2018

Transcription:

CS 537 Introduction to Operating Systems UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department Andrea C. Arpaci-Dusseau Remzi H. Arpaci-Dusseau Virtualizing Memory: Paging Questions answered in this lecture: Review segmentation and fragmentation What is paging? Where are page tables stored? What are advantages and disadvantages of paging? Announcements P1: Due Friday, 5pm Lots of test scripts available Lots of office hours through Friday P2 available immediately after (shell and MLFQ scheduler) Exam 1: Two weeks + 1 day, Wed 10/5 7:15pm 9:15pm Class time on Tuesday for review Look at homeworks / simulations and sample questions Conflicts? Use form to notify us Discussion Section Tell us what topics you want to learn more about! Reading for today: Chapter 18 1

Review: Match Description Description one process uses RAM at a time dynamic approach that verifies address is in one valid range for process rewrite code and addresses before running add per-process starting location to virt addr to obtain phys addr several base+bound pairs per process Name of approach (choose 1 best for each): Segmentation Static Relocation Base Base+Bounds Time Sharing Review: Segmentation Assume 14-bit virtual addresses, high 2 bits indicate segment Segments: 0=>code 1=>heap 2=>stack. Virt Mem Phys Mem??? Code Heap Stack 0x0000 0x1000 0x2000 0x3000 0x4000 0x4000 0x5000 0x6000 0x7000 0x8000 Where dose segment table live? All registers, MMU Seg Base Bounds 0 1 2 0x4000 0x5800 0x6800 0xfff 0xfff 0x7ff 2

Review: Memory Accesses 0x0010: movl 0x1100, %edi 0x0013: addl $0x3, %edi 0x0019: movl %edi, 0x1100 %rip: 0x0010 Seg Base Bounds 0 0x4000 0xfff 1 0x5800 0xfff 2 0x6800 0x7ff Physical Memory Accesses? 1) Fetch instruction at logical addr 0x0010 Physical addr: 0x4010 Exec, load from logical addr 0x1100 Physical addr: 0x5900 2) Fetch instruction at logical addr 0x0013 Physical addr: 0x4013 Exec, no load 3) Fetch instruction at logical addr 0x0019 Physical addr: 0x4019 Exec, store to logical addr 0x1100 Physical addr: 0x5900 Total of 5 memory references (3 instruction fetches, 2 movl s) Problem: Fragmentation Definition: Free memory that can t be usefully allocated Why? Free memory (hole) is too small and scattered Rules for allocating memory prohibit using this free space Types of fragmentation External: Visible to allocator (e.g., OS) Internal: Visible to requester (e.g., if must allocate at some granularity) Segment A Segment B Segment C Segment D External Segment E No contiguous space! Allocated to requester useful free Internal 3

Paging Goal: Eliminate requirement that address space is contiguous Eliminate external fragmentation Grow segments as needed Idea: Divide address spaces and physical memory into fixed-sized pages Size: 2 n, Example: 4KB Physical page: page frame Physical View Process 1 Logical View Process 2 Process 3 Translation of Page Addresses How to translate logical address to physical address? High-order bits of address designate page number Low-order bits of address designate offset within page 20 bits 12 bits 32 bits page number page offset Logical address translate frame number page offset Physical address No addition needed; just append bits correctly How does format of address space determine number of pages and size of pages? 4

Quiz: Address Format Given known page size, how many bits are needed in address to specify offset in page? Page Size Low Bits (offset) 16 bytes 4 1 KB 10 1 MB 20 512 bytes 9 4 KB 12 Quiz: Address Format Given number of bits in virtual address and bits for offset, how many bits for virtual page number? Page Size Low Bits (offset) Virt Addr Bits High Bits (vpn) 16 bytes 4 10 6 1 KB 10 20 10 1 MB 20 32 12 512 bytes 9 16 5 7 4 KB 12 32 20 Correct? 5

Quiz: Address Format Given number of bits for vpn, how many virtual pages can there be in an address space? Page Size Low Bits (offset) Virt Addr Bits High Bits (vpn) Virt Pages 16 bytes 4 10 6 1 KB 10 20 10 1 MB 20 32 12 512 bytes 9 16 7 4 KB 12 32 20 64 1 K 4 K 128 1 M VirtUAL => Physical PAGE Mapping VPN offset Number of bits in virtual address format does not need to equal number of bits in physical address format 0 1 0 1 0 1 Addr Mapper 1 0 1 1 0 1 0 1 PPN How should OS translate VPN to PPN? offset For segmentation, OS used a formula (e.g., phys addr = virt_offset + base_reg) For paging, OS needs more general mapping mechanism What data structure is good? Big array: pagetable 6

The Mapping P1 P2 P3 Virt Mem Phys Mem Quiz: Fill in Page Table Virt Mem P1 P2 P3 0 1 2 3 Phys Mem Page Tables: 0 1 2 3 4 5 6 7 8 9 10 11 P1 3 1 7 10 P2 0 4 2 6 P3 8 5 9 11 7

Where Are Pagetables Stored? How big is a typical page table? - assume 32-bit address space - assume 4 KB pages - assume 4 byte page table entries (PTEs) Final answer: 2 ^ (32 - log(4kb)) * 4 = 4 MB Page table size = Num entries * size of each entry Num entries = num virtual pages = 2^(bits for vpn) Bits for vpn = 32 number of bits for page offset = 32 lg(4kb) = 32 12 = 20 Num entries = 2^20 = 1 MB Page table size = Num entries * 4 bytes = 4 MB Implication: Store each page table in memory Hardware finds page table base with register (e.g., CR3 on x86) What happens on a context-switch? Change contents of page table base register to newly scheduled process Save old page table base register in PCB of descheduled process Other PT info What other info is in pagetable entries besides translation? valid bit protection bits present bit (needed later) reference bit (needed later) dirty bit (needed later) Pagetable entries are just bits stored in memory Agreement between hw and OS about interpretation 8

Break What is your strategy for studying for exams? What is the best sub or sandwich shop in Madison? Memory Accesses with Pages 0x0010: movl 0x1100, %edi 0x0013: addl $0x3, %edi 0x0019: movl %edi, 0x1100 Assume PT is at phys addr 0x5000 Assume PTE s are 4 bytes Assume 4KB pages How many bits for offset? 12 0x5000 0x5004 0x5008 0x500c Simplified view of page table 2 0 80 99 Old: How many mem refs with segmentation? 5 (3 instrs, 2 movl) Physical Memory Accesses with Paging? 1) Fetch instruction at logical addr 0x0010; vpn? Access page table to get ppn for vpn 0 Mem ref 1: 0x5000 Learn vpn 0 is at ppn 2 Fetch instruction at 0x2010 (Mem ref 2) Exec, load from logical addr 0x1100; vpn? Access page table to get ppn for vpn 1 Mem ref 3: 0x5004 Learn vpn 1 is at ppn 0 Movl from 0x0100 into reg (Mem ref 4) Pagetable is slow!!! Doubles memory references 9

Advantages of Paging No external fragmentation Any page can be placed in any frame in physical memory Fast to allocate and free Alloc: No searching for suitable free space Free: Doesn t have to coallesce with adjacent free space Just use bitmap to show free/allocated page frames Simple to swap-out portions of memory to disk (later lecture) Page size matches disk block size Can run process when some pages are on disk Add present bit to PTE Disadvantages of Paging Internal fragmentation: Page size may not match size needed by process Wasted memory grows with larger pages Tension? Why not make pages very small? Additional memory reference to page table --> Very inefficient Page table must be stored in memory MMU stores only base address of page table Solution: Add TLBs (future lecture) Storage for page tables may be substantial Simple page table: Requires PTE for all pages in address space Entry needed even if page not allocated Problematic with dynamic stack and heap within address space Page tables must be allocated contiguously in memory Solution: Combine paging and segmentation (future lecture) Code Heap Stack 10

HomeWork Exercises Look at relocation.py Base+bounds dynamic relocation Look at page-linear-translate.py Basic page tables 11