Intel P6 Systemprogrammering 2007 Föreläsning 5 P6/Linux Memory System



Similar documents
Virtual Memory. How is it possible for each process to have contiguous addresses and so many of them? A System Using Virtual Addressing

Carnegie Mellon Virtual Memory of a Linux Process Process-specific data structs (ptables, Different for

Lecture 17: Virtual Memory II. Goals of virtual memory

CS5460: Operating Systems

Virtual vs Physical Addresses

Linux/UNIX System Programming. POSIX Shared Memory. Michael Kerrisk, man7.org c February 2015

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

The Quest for Speed - Memory. Cache Memory. A Solution: Memory Hierarchy. Memory Hierarchy

6.033 Computer System Engineering

This Unit: Virtual Memory. CIS 501 Computer Architecture. Readings. A Computer System: Hardware

VM Architecture. Jun-Chiao Wang, 15 Apr NCTU CIS Operating System lab Linux kernel trace seminar

Virtualization in Linux KVM + QEMU

4.1 PAGING MODES AND CONTROL BITS

Chapter 10: Virtual Memory. Lesson 03: Page tables and address translation process using page tables

W4118 Operating Systems. Instructor: Junfeng Yang

W4118: segmentation and paging. Instructor: Junfeng Yang

& Data Processing 2. Exercise 3: Memory Management. Dipl.-Ing. Bogdan Marin. Universität Duisburg-Essen

Memory Management Outline. Background Swapping Contiguous Memory Allocation Paging Segmentation Segmented Paging

How To Understand How A Process Works In Unix (Shell) (Shell Shell) (Program) (Unix) (For A Non-Program) And (Shell).Orgode) (Powerpoint) (Permanent) (Processes

REAL TIME SYSTEMS. Piotr MALECKI

COS 318: Operating Systems. Virtual Memory and Address Translation

Chapter 1 Computer System Overview

Overview. CISC Developments. RISC Designs. CISC Designs. VAX: Addressing Modes. Digital VAX

Operating System Overview. Otto J. Anshus

Operating Systems. 05. Threads. Paul Krzyzanowski. Rutgers University. Spring 2015

This Unit: Main Memory. CIS 501 Introduction to Computer Architecture. Memory Hierarchy Review. Readings

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-17: Memory organisation, and types of memory

Xen and the Art of. Virtualization. Ian Pratt

Addendum Intel Architecture Software Developer s Manual

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

Shared Memory Introduction

CS:APP Chapter 4 Computer Architecture. Wrap-Up. William J. Taffe Plymouth State University. using the slides of

Multi-Threading Performance on Commodity Multi-Core Processors

How To Write To A Linux Memory Map On A Microsoft Zseries (Amd64) On A Linux (Amd32) (

Linux kernen. Version , arch. DIKU Intel, SMP. . NEL, Kernel,

Operating System Software

How To Write A Page Table

Multi-core architectures. Jernej Barbic , Spring 2007 May 3, 2007

I/O. Input/Output. Types of devices. Interface. Computer hardware

Leak Check Version 2.1 for Linux TM

Computer Organization and Architecture. Characteristics of Memory Systems. Chapter 4 Cache Memory. Location CPU Registers and control unit memory

OPERATING SYSTEM - MEMORY MANAGEMENT

Paging: Introduction A Simple Example And Overview

Processes and Non-Preemptive Scheduling. Otto J. Anshus

System Calls and Standard I/O

Virtual Memory. Chapter 4

Operating Systems. Privileged Instructions

Virtualization. Explain how today s virtualization movement is actually a reinvention

361 Computer Architecture Lecture 14: Cache Memory

Virtual Shared Memory (VSM)

POSIX. RTOSes Part I. POSIX Versions. POSIX Versions (2)

Linux Kernel Architecture

StrongARM** SA-110 Microprocessor Instruction Timing

An Implementation Of Multiprocessor Linux

Chapter 12. Paging an Virtual Memory Systems

Memory ICS 233. Computer Architecture and Assembly Language Prof. Muhamed Mudawar

Hardware Assisted Virtualization

Bringing PowerPC Book E to Linux

Chapter 11 I/O Management and Disk Scheduling

umps software development

Sistemi Operativi. Lez. 21/22 : Memoria Virtuale in JOS

Chapter 6. Inside the System Unit. What You Will Learn... Computers Are Your Future. What You Will Learn... Describing Hardware Performance

Operating Systems and Networks


The Linux Kernel: Process Management. CS591 (Spring 2001)

We r e going to play Final (exam) Jeopardy! "Answers:" "Questions:" - 1 -

Hybrid Virtualization The Next Generation of XenLinux

OPERATING SYSTEM - VIRTUAL MEMORY

Why Computers Are Getting Slower (and what we can do about it) Rik van Riel Sr. Software Engineer, Red Hat

Chapter 6, The Operating System Machine Level

Configuring CoreNet Platform Cache (CPC) as SRAM For Use by Linux Applications

Chapter 10: Virtual Memory. Lesson 08: Demand Paging and Page Swapping

Binary search tree with SIMD bandwidth optimization using SSE

Multi-core Programming System Overview

Virtual Memory Behavior in Red Hat Linux Advanced Server 2.1

Lecture 10: Dynamic Memory Allocation 1: Into the jaws of malloc()

Chapter 7 Memory Management

Project 3A. CS 170, Tao Yang

There s a kernel security researcher named Dan Rosenberg whose done a lot of linux kernel vulnerability research

Kernel Virtual Machine

COS 318: Operating Systems. I/O Device and Drivers. Input and Output. Definitions and General Method. Revisit Hardware

A3 Computer Architecture

Virtualization. Dr. Yingwu Zhu

COS 318: Operating Systems

USB 2.0 Flash Drive User Manual

The Linux Virtual Filesystem

1. Computer System Structure and Components

Fast Arithmetic Coding (FastAC) Implementations

Application Note 195. ARM11 performance monitor unit. Document number: ARM DAI 195B Issued: 15th February, 2008 Copyright ARM Limited 2007

Lecture 25 Symbian OS

Traditional IBM Mainframe Operating Principles

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

CHAPTER 7: The CPU and Memory

Transcription:

Intel P6 Systemprogrammering 07 Föreläsning 5 P6/Linux ory System Topics P6 address translation Linux memory management Linux page fault handling memory mapping Internal Designation for Successor to Pentium Which had internal designation P5 Fundamentally Different from Pentium Out-of-order, superscalar operation Designed to handle server applications Requires high performance memory system Resulting Processors PentiumPro (1996) Pentium II (1997) Incorporated MMX instructions» special instructions for parallel processing L2 cache on same chip Pentium III (1999) Incorporated Streaming SIMD Extensions» More instructions for parallel processing Pentium F5 2 Systemprogrammering 07 P6 ory System DRAM bus interface unit instruction fetch unit processor package external system bus (e.g. PCI) L2 cache i-cache cache bus inst d-cache bit address space KB page size, L2, and s -way set associative inst entries 8 sets 6 entries sets i-cache and d-cache KB B line size 8 sets L2 cache unified 8 KB -- 2 MB Review of Abbreviations Symbols: Components of the virtual address (VA) I: index T: tag : virtual page offset : virtual page number Components of the PPO: page offset (same as ) PPN: page number CO: byte offset within cache line CI: cache index CT: cache tag F5 3 Systemprogrammering 07 F5 Systemprogrammering 07

Overview of P6 Address Translation T virtual address (VA) 10 10 I ( sets, entries/set) s F5 5 Systemprogrammering 07 result L2 and DRAM (8 sets, lines/set) 7 5 P6 2-level Table Structure -byte page entries (s) that point to page tables one page per process. page must be in memory when its process is running always pointed to by s: -byte page table entries (s) that point to pages. page tables can be paged in and out. page Up to page tables s F5 6 Systemprogrammering 07 s s s P6 Directory Entry () P6 Table Entry () 31 11 9 8 7 6 5 3 2 1 0 base addr Avail G PS A CD WT U/S R/W P=1 31 11 9 8 7 6 5 3 2 1 0 base address Avail G 0 D A CD WT U/S R/W P=1 base address: most significant bits of page table address (forces page tables to be KB aligned) Avail: These bits available for system programmers G: global page (don t evict from on task switch) PS: page size K (0) or M (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 base address: most significant bits of page address (forces pages to be KB aligned) Avail: available for system programmers G: global page (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 page U/S: user/supervisor R/W: read/write P: page is present in memory (1) or not (0) 31 1 0 Available for OS (page location in secondary storage) P=0 F5 7 Systemprogrammering 07 F5 8 Systemprogrammering 07

How P6 Tables Map Virtual Addresses to Physical Ones address of page 10 1 word offset into page page address of page table base (if P=1) 10 2 word offset into page table page table address of page base (if P=1) PPN PPO Virtual address word offset into and virtual Physical address F5 9 Systemprogrammering 07 page Representation of Virtual Address Space Directory Simplified Example Flags page virtual address space P: Is entry in memory? M: Has this part of VA space been mapped? PT 3 PT 2 PT 0 15 1 13 11 10 9 8 7 6 5 3 2 1 0 Addr Addr In On Unmapped F5 10 Systemprogrammering 07 P6 Translation P6 T virtual address (VA) 10 10 I ( sets, entries/set) s result L2 anddram (8 sets, lines/set) 7 5 entry (not all documented, so this is speculative): 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 /: page or page table entry Structure of the : sets, entries/set 1 1 / Tag PD V entry entry entry entry entry entry entry entry entry entry entry entry entry entry entry entry set 0 set 1 set 2 set 15 F5 11 Systemprogrammering 07 F5 Systemprogrammering 07

Translating with the P6 P6 page table translation virtual address T I 1 2 page table translation 3 PPN PPO address 1. Partition into T and I. 2. Is the for cached in set I? 3. Yes: : then build address.. No: : then read (and if not cached) from memory and build address. T 10 10 I virtual address (VA) ( sets, entries/set) result L2 anddram (8 sets, lines/set) 7 5 s F5 13 Systemprogrammering 07 F5 1 Systemprogrammering 07 Translating with the P6 Tables (case 1/1) p=1 p=1 Case 1/1: page table and page present. MMU Action: MMU builds address and fetches word. OS action none F5 15 Systemprogrammering 07 Translating with the P6 Tables (case 1/0) Case 1/0: page table present but page p=1 p=0 ing. MMU Action: page fault exception handler receives the following args: VA that caused fault fault caused by nonpresent page or pagelevel protection violation read/write user/supervisor F5 Systemprogrammering 07

Translating with the P6 Tables (case 1/0, cont) p=1 p=1 PPN OS Action: Check for a legal virtual address. Read through. Find free 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. F5 17 Systemprogrammering 07 PPO Translating with the P6 Tables (case 0/1) p=0 p=1 Case 0/1: page table ing 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 pages too. F5 18 Systemprogrammering 07 Translating with the P6 Tables (case 0/0) p=0 p=0 Case 0/0: page table and page ing. MMU Action: page fault exception F5 19 Systemprogrammering 07 Translating with the P6 Tables (case 0/0, cont) p=1 p=0 OS action: swap in page table. restart faulting instruction by returning from handler. Like case 1/0 from here on. F5 Systemprogrammering 07

P6 Cache Access Cache Access T virtual address (VA) 10 10 I s ( sets, entries/set) result L2 anddram (8 sets, lines/set) 7 5 L2 anddram (8 sets, 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. F5 21 Systemprogrammering 07 F5 22 Systemprogrammering 07 Observation Speeding Up Access Physical virtual address (VA) 7 5 PPN Addr. Trans. Bits that determine CI identical in virtual and address Can index into cache while address translation taking place Then check with CT from address Virtually indexed, ly tagged Cache carefully sized to make this possible F5 23 Systemprogrammering 07 PPO No Change CI Tag Check Linux Organizes VM as Collection of Areas task_struct mm pgd: mm_struct pgd mmap page address vm_prot: read/write perions for this area vm_flags shared with other processes or private to this vm_area_struct vm_prot vm_flags vm_prot vm_flags vm_prot vm_flags process virtual memory shared libraries process F5 2 Systemprogrammering 07 text 0x0000000 0x080a0 0x0808000 0

vm_area_struct r/o r/w r/o Linux Fault Handling process virtual memory shared libraries text 0 1 read read 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) F5 25 Systemprogrammering 07 3 2 ory 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 memory until they are referenced! known as demand paging crucial for time and space efficiency F5 26 Systemprogrammering 07 User-Level ory Mapping mmap() Example: Fast File Copy 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. #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); } F5 27 Systemprogrammering 07 F5 28 Systemprogrammering 07

same for each process 0xc0 %esp brk 0 process-specific structures (page tables, 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 Exec() Revisited kernel VM demand-zero process VM..text libc.so demand-zero..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,, text, shared libs. text and 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 pages as needed. F5 29 Systemprogrammering 07 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-on-write. writes by either process to these pages will cause page faults. Net result:» fault handler recognizes copy-on-write, makes a copy of the page, and restores write perions. copies are deferred until absolutely necessary (i.e., when one of the processes tries to modify a shared page). F5 30 Systemprogrammering 07 ory System Summary Cache ory Purely a speed-up technique Behavior invisible to application programmer and OS Implemented totally in hardware Virtual ory Supports many OS-related functions Process creation» Initial» Forking children Task switching Protection Combination of hardware & software implementation Software management of tables, allocations Hardware access of tables Hardware caching of table entries () F5 31 Systemprogrammering 07