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

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

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

Page Which had internal designation P5

Memory System Case Studies Oct. 13, 2008

Pentium/Linux Memory System March 17, 2005

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

Foundations of Computer Systems

Virtual Memory: Systems

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

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

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 Nov 9, 2009"

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 24

Foundations of Computer Systems

Virtual Memory. Spring Instructors: Aykut and Erkut Erdem

Systems Programming and Computer Architecture ( ) Timothy Roscoe

CS 153 Design of Operating Systems

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 25

Applications of. Virtual Memory in. OS Design

Virtual Memory Oct. 29, 2002

CSE 153 Design of Operating Systems

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. Motivations for VM Address translation Accelerating translation with TLBs

Virtual Memory II CSE 351 Spring

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

Virtual Memory. Samira Khan Apr 27, 2017

CISC 360. Virtual Memory Dec. 4, 2008

Virtual Memory II. CSE 351 Autumn Instructor: Justin Hsia

virtual memory Page 1 CSE 361S Disk Disk

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

Computer Systems. Virtual Memory. Han, Hwansoo

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

CSE 120 Principles of Operating Systems

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

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

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

Understanding the Design of Virtual Memory. Zhiqiang Lin

Virtual Memory II. CSE 351 Autumn Instructor: Justin Hsia

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

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

seven Virtual Memory Introduction

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

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

Outline. 1 Details of paging. 2 The user-level perspective. 3 Case study: 4.4 BSD 1 / 19

Lecture 19: Virtual Memory: Concepts

Memory Mapping. Sarah Diesburg COP5641

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

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

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

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

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

Processes and Virtual Memory Concepts

CS 3733 Operating Systems:

Recap: Memory Management

Virtual Memory: Concepts

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

CSE 560 Computer Systems Architecture

CSE 351. Virtual Memory

CSE 120 Principles of Operating Systems Spring 2017

Topics: Virtual Memory (SGG, Chapter 09) CS 3733 Operating Systems

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

Operating systems. Lecture 9

ECEN 449 Microprocessor System Design. Review of C Programming. Texas A&M University

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Virtual Memory: From Address Translation to Demand Paging

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

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

CSCI 4061: Virtual Memory

Virtual Memory: Concepts

ECEN 449 Microprocessor System Design. Review of C Programming

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

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

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

MMAP AND PIPE. UNIX Programming 2015 Fall by Euiseong Seo

Memory Management - Demand Paging and Multi-level Page Tables

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

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

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

Virtual Memory: Concepts

Introduction to Linux, for Embedded Engineers Tutorial on Virtual Memory. Feb. 22, 2007 Tetsuyuki Kobayashi Aplix Corporation. [translated by ikoma]

The course that gives CMU its Zip! I/O Nov 15, 2001

Virtual Memory. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Virtual Memory. Computer Systems Principles

CSCE 548 Building Secure Software Dirty COW Race Condition Attack

CS 153 Design of Operating Systems

ECE 650 Systems Programming & Engineering. Spring 2018

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

ECE331: Hardware Organization and Design

Virtual Memory: From Address Translation to Demand Paging

Virtual Memory. CS 3410 Computer System Organization & Programming

Process Address Spaces and Binary Formats

Virtual Memory Paging

CS 318 Principles of Operating Systems

Computer Architecture Lecture 13: Virtual Memory II

VM as a cache for disk

Transcription:

15-213 P6/Linux ory System October 31, 00 Topics P6 address translation Linux memory management Linux fault handling memory mapping DRAM bus interface unit instruction fetch unit processor package P6 memory system external system bus (e.g. PCI) L2 cache i-cache cache bus inst d-cache bit address space 4 KB size, L2, and s 4-way set associative inst entries 8 sets 64 entries 16 sets i-cache and d-cache 16 KB B linesize 8 sets L2 cache unified 8 KB -- 2 MB 2 Review of abbreviations Symbols: Components of the I: index T: tag : virtual offset : virtual number Components of the PPO: offset (same as ) PPN: number CO: byte offset within cache line CI: cache index CT: cache tag Overview of P6 address translation T I (16 sets, (8 sets, 4 lines/set) 7 5 3 s 4

P6 2-level structure 4-byte entries (s) that point to s one per process. must be in memory when its process is running always pointed to by s: 4-byte entries (s) that point to s. s can be d in and out. s s s s s P6 entry () 31 11 9 8 7 6 5 4 3 2 1 0 base addr Avail G PS A CD WT U/S R/W P=1 base address: most significant bits of address (forces s to be 4KB aligned) Avail: available for system programmers G: global (don t evict from on task switch) PS: 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 U/S: user or supervisor mode access R/W: read-only or read-write access P: is present in memory (1) or not (0) 31 1 0 Available for OS ( location in secondary storage) P=0 5 6 P6 entry () 31 11 9 8 7 6 5 4 3 2 1 0 base address Avail G 0 D A CD WT U/S R/W P=1 How P6 s map virtual addresses to ones 10 1 10 2 Virtual address base address: most significant bits of address (forces s to be 4 KB aligned) Avail: available for system programmers G: global (don t evict from 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 U/S: user/supervisor R/W: read/write P: is present in memory (1) or not (0) 31 1 0 Available for OS ( location in secondary storage) P=0 word offset into address of word offset into address of base (if P=1) address of base (if P=1) PPN PPO word offset into and virtual Physical address 7 8

T I s P6 translation (16 sets, 9 7 5 (8 sets, 4 lines/set) P6 entry (not all documented, so this is speculative): / Tag PD V V: indicates a valid (1) or invalid (0) entry PD: is this entry a (1) or a (0)? tag: disambiguates entries cached in the same set /: or entry Structure of the : 16 sets, 4 entries/set 10 16 set 0 set 1 set 2 set 15 1 1 Translating with the P6 virtual address T I 1 2 translation 3 address 4 1. Partition into T and I. 2. Is the for cached in set I? 3. Yes: then build address. 4. No: then read (and if not cached) from memory and build address. T I P6 translation (16 sets, (8 sets, 4 lines/set) 7 5 11 s

Translating with the P6 s (case 1/1) p=1 p=1 13 Case 1/1: and present. MMU Action: MMU build address and fetch word. OS action none Translating with the P6 s (case 1/0) p=1 p=0 14 Case 1/0: present but ing. MMU Action: fault exception handler receives the following args: VA that caused fault fault caused by non-present or -level protection violation read/write user/supervisor Translating with the P6 s (case 1/0, cont) p=1 p=1 15 OS Action: Check for a legal virtual address. Read through. Find free (swapping out current if necessary) Read virtual from disk and copy to virtual Restart faulting instruction by returning from exception handler. Translating with the P6 s (case 0/1) p=0 p=1 16 Case 0/1: ing but present. Introduces consistency issue. potentially every out requires update of disk. Does Linux disallow this? if a is swapped out, then swap out its s too.

Translating with the P6 s (case 0/0) p=0 Case 0/0: and ing. MMU Action: fault exception Translating with the P6 s (case 0/0, cont) p=1 p=0 OS action: swap in. restart faulting instruction by returning from handler. Like case 0/1 from here on. p=0 17 18 T I s P6 cache access (16 sets, 19 7 5 (8 sets, 4 lines/set) cache access (8 sets, 4 lines/set) 7 5 Partition 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.

task_struct mm Linux organizes VM as a collection of areas mm_struct pgd mmap pgd: address vm_prot: read/write perions for this area vm_flags shared with other processes or private to this process vm_area_struct vm_prot vm_flags vm_prot vm_flags vm_prot vm_flags 21 process virtual memory shared libraries text 0x40000000 0x0804a0 0x08048000 0 vm_area_struct r/o r/w r/o Linux fault handling process virtual memory shared libraries text 0 1 read 3 read 2 22 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) ory mapping Creating a new VM area is done via memory mapping create new vm_area_struct and s for area area can be backed by (i.e., get its initial values from) : regular file on disk (e.g., an execu object file)» initial bytes come from a section of a file nothing (e.g., bss)» initial bytes are zeros dirty s are swapped back and forth between a special swap file. Key point: no virtual s are copied into memory until they are referenced! known as demand paging crucial for time and space efficiency 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. 23 24

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 and get its size*/ fd = open("./mmap.c", O_RDONLY); fstat(fd, &stat); size = stat.st_size; 25 /* 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); } same for each process 0xc0 %esp brk process-specific structures ( s, task and mm structs) memory kernel code//stack stack ory mapped region for shared libraries runtime heap (via malloc) uninitialized (.bss) initialized (.) program text (.text) forbidden 0 Exec() revisited kernel VM demand-zero process VM..text libc.so demand-zero..text p 26 To run a new program p in the current process using exec(): free vm_area_structs and s for old areas. create new vm_area_structs and s for new areas. stack, bss,, text, shared libs. text and backed by ELF execu object file. bss and stack initialized to zero. set PC to entry point in.text Linux will swap in code and s as needed. Fork() revisted To create a new process using fork: make copies of the old process s mm_struct, vm_area_structs, and s. at this point the two processes are sharing all of their s. How to get separate spaces without copying all the virtual s from one space to another?» copy on write technique. copy-on-write make s of writeable areas read-only flag vm_area_structs for these areas as private copy-on-write. writes by either process to these s will cause faults.» fault handler recognizes copy-on-write, makes a copy of the, and restores write perions. Net : copies are deferred until absolutely necessary (i.e., when one of the processes tries to modify a shared ). 27