Memory System Case Studies Oct. 13, 2008

Similar documents
Pentium/Linux Memory System March 17, 2005

Intel P6 (Bob Colwell s Chip, CMU Alumni) The course that gives CMU its Zip! Memory System Case Studies November 7, 2007.

Intel P The course that gives CMU its Zip! P6/Linux Memory System November 1, P6 memory system. Review of abbreviations

P6 memory system P6/Linux Memory System October 31, Overview of P6 address translation. Review of abbreviations. Topics. Symbols: ...

Page Which had internal designation P5

P6/Linux Memory System Nov 11, 2009"

Virtual Memory: Systems

Virtual Memory III /18-243: Introduc3on to Computer Systems 17 th Lecture, 23 March Instructors: Bill Nace and Gregory Kesden

Virtual Memory: Systems

Foundations of Computer Systems

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

Systems Programming and Computer Architecture ( ) Timothy Roscoe

Virtual Memory Nov 9, 2009"

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

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 24

Operating Systems: Internals and Design. Chapter 8. Seventh Edition William Stallings

Virtual Memory Oct. 29, 2002

Virtual Memory. Samira Khan Apr 27, 2017

Foundations of Computer Systems

Virtual Memory. Spring Instructors: Aykut and Erkut Erdem

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

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

Virtual Memory II. CSE 351 Autumn Instructor: Justin Hsia

CS 153 Design of Operating Systems

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

CSE 153 Design of Operating Systems

Virtual Memory II CSE 351 Spring

CISC 360. Virtual Memory Dec. 4, 2008

Virtual Memory II. CSE 351 Autumn Instructor: Justin Hsia

Computer Systems. Virtual Memory. Han, Hwansoo

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 25

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

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

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

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

Processes and Virtual Memory Concepts

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

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

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

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

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

Virtual Memory: Concepts

CSE 351. Virtual Memory

virtual memory Page 1 CSE 361S Disk Disk

Virtual Memory: Concepts

Lecture 19: Virtual Memory: Concepts

CS 153 Design of Operating Systems

Understanding the Design of Virtual Memory. Zhiqiang Lin

Applications of. Virtual Memory in. OS Design

Computer Structure. X86 Virtual Memory and TLB

Virtual Memory: Concepts

Computer Architecture Lecture 13: Virtual Memory II

VM as a cache for disk

Chapter 5: Memory Management

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

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

IA32/Linux Virtual Memory Architecture

CSE 120 Principles of Operating Systems

University of Washington Virtual memory (VM)

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

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

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

CSE 560 Computer Systems Architecture

seven Virtual Memory Introduction

Virtual Memory: From Address Translation to Demand Paging

Memory Mapping. Sarah Diesburg COP5641

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

Virtual Memory. Computer Systems Principles

Virtual Memory. CS 351: Systems Programming Michael Saelee

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

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

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

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

Problem 9. VM address translation. (9 points): The following problem concerns the way virtual addresses are translated into physical addresses.

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

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

Virtual Memory. Virtual Memory

CS 318 Principles of Operating Systems

Virtual Memory. CS 3410 Computer System Organization & Programming

CSE 120 Principles of Operating Systems Spring 2017

Recap: Memory Management

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

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

A Few Problems with Physical Addressing. Virtual Memory Process Abstraction, Part 2: Private Address Space

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

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

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

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

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

Las time: Large Pages Last time: VAX translation. Today: I/O Devices

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

Virtual Memory: From Address Translation to Demand Paging

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

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Compsci 104. Duke University. Input/Output. Instructors: Alvin R. Lebeck. Some Slides provided by Randy Bryant and Dave O Hallaron and G.

Virtual Memory I. CSE 351 Spring Instructor: Ruth Anderson

Administrivia. - If you didn t get Second test of class mailing list, contact cs240c-staff. Clarification on double counting policy

Transcription:

Topics 15-213 Memory System Case Studies Oct. 13, 2008 P6 address translation x86-64 extensions Linux memory management Linux page fault handling Memory mapping Class15+.ppt

Intel P6 (Bob Colwell s Chip, CMU Alumni) Internal designation for successor to Pentium Which had internal designation P5 Fundamentally different from Pentium Out-of-order, superscalar operation Resulting processors Pentium Pro (1996) Pentium II (1997) L2 cache on same chip Pentium III (1999) The freshwater fish machines Saltwater fish machines: Pentium 4 Different operation, but similar memory system Abandoned by Intel in 2005 for P6 based Core 2 Duo 2

P6 Memory System 32 bit address space 4 KB page size 3 DRAM bus interface unit instruction fetch unit processor package external system bus (e.g. PCI) L1 L2 cache i-cache cache bus inst TLB data TLB L1 d-cache L1, L2, and TLBs 4-way set associative Inst TLB 32 entries 8 sets Data TLB 64 entries 16 sets L1 i-cache and d-cache 16 KB 32 B line size 128 sets L2 cache unified 128 KB -- 2 MB

Review of Abbreviations Symbols: Components of the virtual address (VA) TLBI: TLB index TLBT: TLB tag VPO: virtual page offset VPN: virtual page number Components of the physical address (PA) PPO: physical page offset (same as VPO) PPN: physical page number CO: byte offset within cache line CI: cache index CT: cache tag 4

Overview of P6 Address Translation CPU 32 result L2 and DRAM 20 12 VPN VPO 16 4 TLBT TLBI virtual address (VA) L1 hit L1 miss TLB miss... TLB hit L1 (128 sets, 4 lines/set)... 10 10 VPN1 VPN2 TLB (16 sets, 4 entries/set) 20 12 PPN PPO 20 7 5 CT CI CO PDE PTE physical address (PA) PDBR 5 Page tables

P6 2-level Page Table Structure Page directory 1024 4-byte page directory entries (PDEs) that point to page tables One page directory per process. Page directory must be in memory when its process is running Always pointed to by PDBR Page tables: 1024 4-byte page table entries (PTEs) that point to pages. Page tables can be paged in and out. page directory 1024 PDEs Up to 1024 page tables 1024 PTEs... 1024 PTEs... 1024 PTEs 6

P6 Page Directory Entry (PDE) 31 1211 9 8 7 6 5 4 3 2 1 0 Page table physical base addr Avail G PS A CD WT U/S R/W P=1 Page table physical base address: 20 most significant bits of physical page table address (forces page tables to be 4KB aligned) Avail: These bits available for system programmers G: global page (don t evict from TLB on task switch) PS: page size 4K (0) or 4M (1) A: accessed (set by MMU on reads and writes, cleared by software) CD: cache disabled (1) or enabled (0) WT: write-through or write-back cache policy for this page table U/S: user or supervisor mode access R/W: read-only or read-write access P: page table is present in memory (1) or not (0) 31 1 0 Available for OS (page table location in secondary storage) P=0 7

P6 Page Table Entry (PTE) 31 1211 9 8 7 6 5 4 3 2 1 0 Page physical base address Avail G 0 D A CD WT U/S R/W P=1 Page base address: 20 most significant bits of physical page address (forces pages to be 4 KB aligned) Avail: available for system programmers G: global page (don t evict from TLB on task switch) D: dirty (set by MMU on writes) A: accessed (set by MMU on reads and writes) CD: cache disabled or enabled WT: write-through or write-back cache policy for this page U/S: user/supervisor R/W: read/write P: page is present in physical memory (1) or not (0) 31 1 0 Available for OS (page location in secondary storage) P=0 8

How P6 Page Tables Map Virtual Addresses to Physical Ones 10 VPN1 10 12 VPN2 VPO Virtual address word offset into page directory page directory word offset into page table page table word offset into physical and virtual page PDBR physical address of page directory PDE PTE physical address of page table base (if P=1) physical address of page base (if P=1) 20 PPN 12 PPO Physical address 9

Representation of VM Address Space Simplified Example Flags 10 Page Directory P=1, M=1 P=1, M=1 P=0, M=0 P=0, M=1 PT 3 PT 2 PT 0 P=1, M=1 P=0, M=0 P=1, M=1 P=0, M=1 P=1, M=1 P=0, M=0 P=1, M=1 P=0, M=1 P=0, M=1 P=0, M=1 P=0, M=0 P=0, M=0 16 page virtual address space P: Is entry in physical memory? M: Has this part of VA space been mapped? Page 15 Page 14 Page 13 Page 12 Page 11 Page 10 Page 9 Page 8 Page 7 Page 6 Page 5 Page 4 Page 3 Page 2 Page 1 Page 0 Mem Addr Disk Addr In Mem On Disk Unmapped

CPU P6 TLB Translation 32 result L2 and DRAM 20 12 VPN VPO 16 4 TLBT TLBI virtual address (VA) L1 hit L1 miss TLB miss... TLB hit L1 (128 sets, 4 lines/set)... 10 10 VPN1 VPN2 TLB (16 sets, 4 entries/set) 20 12 PPN PPO 20 7 5 CT CI CO PDE PTE physical address (PA) PDBR 11 Page tables

P6 TLB TLB entry (not all documented, so this is speculative): 32 PDE/PTE Tag PD V 16 1 1 V: indicates a valid (1) or invalid (0) TLB entry PD: is this entry a PDE (1) or a PTE (0)? tag: disambiguates entries cached in the same set PDE/PTE: page directory or page table entry Structure of the data TLB: 16 sets, 4 entries/set 12 entry entry entry entry entry entry entry entry entry entry entry entry... entry entry entry entry set 0 set 1 set 2 set 15

Translating with the P6 TLB CPU 1. Partition VPN into TLBT and TLBI. 20 12 VPN VPO virtual address 2. Is the PTE for VPN cached in set TLBI? 16 4 TLBT TLBI TLB miss 1 2 PDE... page table translation PTE TLB hit 3 20 12 PPN PPO physical address 4 3. Yes: then build physical address. 4. No: then read PTE (and PDE if not cached) from memory and build physical address. 13

CPU P6 Page Table Translation 32 result L2 and DRAM 20 12 VPN VPO 16 4 TLBT TLBI virtual address (VA) L1 hit L1 miss TLB miss... TLB hit L1 (128 sets, 4 lines/set)... 10 10 VPN1 VPN2 TLB (16 sets, 4 entries/set) 20 12 PPN PPO 20 7 5 CT CI CO PDE PTE physical address (PA) PDBR 14 Page tables

Translating with the P6 Page Tables (case 1/1) Mem Disk 20 VPN VPN1 VPN2 PDBR PDE 12 VPO Page directory p=1 PTE p=1 Page table 20 12 PPN PPO data Data page Case 1/1: page table and page present. MMU Action: MMU builds physical address and fetches data word. OS action None 15

Translating with the P6 Page Tables (case 1/0) Mem Disk 16 PDBR 20 VPN VPN1 VPN2 PDE 12 VPO Page directory p=1 PTE p=0 Page table data Data page Case 1/0: page table present but page missing. MMU Action: Page fault exception Handler receives the following args: VA that caused fault Fault caused by non-present page or page-level protection violation Read/write User/supervisor

Translating with the P6 Page Tables (case 1/0, cont) Mem Disk 17 PDBR 20 VPN VPN1 VPN2 PDE 12 VPO Page directory p=1 PTE p=1 Page table 20 12 PPN PPO data Data page OS Action: Check for a legal virtual address. Read PTE through PDE. Find free physical page (swapping out current page if necessary) Read virtual page from disk and copy to virtual page Restart faulting instruction by returning from exception handler.

Translating with the P6 Page Tables (case 0/1) Mem Disk PDBR 20 VPN VPN1 VPN2 PDE 12 VPO p=0 Page directory PTE p=1 data Data page Case 0/1: page table missing but page present. Introduces consistency issue. Potentially every page-out requires update of disk page table. Linux disallows this If a page table is swapped out, then swap out its data pages too. 18 Page table

Translating with the P6 Page Tables (case 0/0) Mem PDBR 20 VPN VPN1 VPN2 PDE 12 VPO p=0 Page directory Case 0/0: page table and page missing. MMU Action: Page fault exception Disk PTE p=0 data 19 Page table Data page

Translating with the P6 Page Tables (case 0/0, cont) Mem PDBR 20 VPN VPN1 VPN2 PDE 12 VPO Page directory p=1 PTE p=0 Page table OS action: Swap in page table. Restart faulting instruction by returning from handler. Like case 0/1 from here on. Disk 20 data Data page

CPU P6 L1 Cache Access 32 result L2 and DRAM 20 12 VPN VPO 16 4 TLBT TLBI virtual address (VA) L1 hit L1 miss TLB miss... TLB hit L1 (128 sets, 4 lines/set)... 10 10 VPN1 VPN2 TLB (16 sets, 4 entries/set) 20 12 PPN PPO 20 7 5 CT CI CO PDE PTE physical address (PA) PDBR 21 Page tables

32 data L1 hit... physical address (PA) L1 Cache Access L2 anddram L1 miss L1 (128 sets, 4 lines/set) 20 7 5 CT CI CO Partition physical address into CO, CI, and CT. Use CT to determine if line containing word at address PA is cached in set CI. If no: check L2. If yes: extract word at byte offset CO and return to processor. 22

Speeding Up L1 Access Tag Check Physical address (PA) 20 7 5 CT CI CO PPN PPO Addr. Trans. No Change CI Observation 23 virtual address (VA) VPN VPO 20 12 Bits that determine CI identical in virtual and physical address Can index into cache while address translation taking place Then check with CT from physical address Virtually indexed, physically tagged Cache carefully sized to make this possible

Origin x86-64 Paging AMD s way of extending x86 to 64-bit instruction set Intel has followed with EM64T Requirements 48 bit virtual address 256 terabytes (TB) Not yet ready for full 64 bits 52 bit physical address Requires 64-bit table entries 4KB page size Only 512 entries per page 24

x86-64 Paging Virtual address 9 VPN1 9 9 9 VPN2 VPN3 VPN4 12 VPO Page Directory Page Page Map Pointer Directory Page Table Table Table Table PM4LE PDPE PDE PTE BR 40 PPN 12 PPO Physical address 25

Linux Organizes VM as Collection of Areas task_struct mm_struct mm pgd mmap vm_area_struct process virtual memory vm_end vm_start vm_prot vm_flags shared libraries vm_next 0x40000000 pgd: Page directory address vm_prot: Read/write permissions for this area vm_flags Shared with other processes or private to this process vm_end vm_start vm_prot vm_flags vm_next vm_end vm_start vm_prot vm_flags vm_next data text 0x0804a020 0x08048000 0 26

vm_area_struct 27 vm_end vm_start r/o vm_next vm_end vm_start r/w vm_next vm_end vm_start r/o vm_next Linux Page Fault Handling process virtual memory shared libraries data text 0 1 read 3 read 2 write Is the VA legal? i.e., Is it in an area defined by a vm_area_struct? If not then signal segmentation violation (e.g. (1)) Is the operation legal? i.e., Can the process read/write this area? If not then signal protection violation (e.g., (2)) If OK, handle fault e.g., (3)

Memory Mapping Creation of new VM area done via memory mapping Create new vm_area_struct and page tables for area Area can be backed by (i.e., get its initial values from) : Regular file on disk (e.g., an executable object file)» Initial page bytes come from a section of a file Nothing (e.g., bss)» Initial page bytes are zeros Dirty pages are swapped back and forth between a special swap file. Key point: no virtual pages are copied into physical memory until they are referenced! Known as demand paging Crucial for time and space efficiency 28

User-Level Memory Mapping void *mmap(void *start, int len, int prot, int flags, int fd, int offset) Map len bytes starting at offset offset of the file specified by file description fd, preferably at address start (usually 0 for don t care). prot: MAP_READ, MAP_WRITE flags: MAP_PRIVATE, MAP_SHARED Return a pointer to the mapped area. Example: fast file copy Useful for applications like Web servers that need to quickly copy files. mmap allows file transfers without copying into user space. 29

mmap() Example: Fast File Copy #include <unistd.h> #include <sys/mman.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> /* * mmap.c - a program that uses mmap * to copy itself to stdout */ int main() { struct stat stat; int i, fd, size; char *bufp; /* open the file & get its size*/ fd = open("./mmap.c", O_RDONLY); fstat(fd, &stat); size = stat.st_size; /* map the file to a new VM area */ bufp = mmap(0, size, PROT_READ, MAP_PRIVATE, fd, 0); } /* write the VM area to stdout */ write(1, bufp, size); 30

same for each process 0xc0 %esp brk 31 0 process-specific data structures (page tables, task and mm structs) physical memory kernel code/data/stack stack Memory mapped region for shared libraries runtime heap (via malloc) uninitialized data (.bss) initialized data (.data) program text (.text) forbidden Exec() Revisited kernel VM demand-zero process VM.data.text libc.so demand-zero.data.text p To run a new program p in the current process using exec(): Free vm_area_struct s and page tables for old areas. Create new vm_area_struct s and page tables for new areas. Stack, bss, data, text, shared libs. Text and data backed by ELF executable object file. bss and stack initialized to zero. Set PC to entry point in.text Linux will swap in code and data pages as needed.

32 Fork() Revisited To create a new process using fork(): Make copies of the old process s mm_struct, vm_area_struct s, and page tables. At this point the two processes are sharing all of their pages. How to get separate spaces without copying all the virtual pages from one space to another?» copy on write technique. Copy-on-write Make pages of writeable areas read-only Flag vm_area_struct s for these areas as private copy-onwrite. Writes by either process to these pages will cause page faults.» Fault handler recognizes copy-on-write, makes a copy of the page, and restores write permissions. Net result: Copies are deferred until absolutely necessary (i.e., when one of the processes tries to modify a shared page).

Cache Memory Memory System Summary Purely a speed-up technique Behavior invisible to application programmer and (mostly) OS Implemented totally in hardware Virtual Memory Supports many OS-related functions Process creation Task switching Protection Combination of hardware & software implementation Software management of tables, allocations Hardware access of tables Hardware caching of table entries (TLB) 33