Virtual memory - Paging

Similar documents
The process. one problem

Virtual Memory. Yannis Smaragdakis, U. Athens

Virtual Memory. Today. Handling bigger address spaces Speeding translation

Virtual Memory 2. To do. q Handling bigger address spaces q Speeding translation

Operating System Labs. Yuanbin Wu

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.

CS 134: Operating Systems

Virtual Memory 2. Today. Handling bigger address spaces Speeding translation

Virtual Memory 2. q Handling bigger address spaces q Speeding translation

CSE 120 Principles of Operating Systems

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

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

Chapter 8 Memory Management

CS 153 Design of Operating Systems Winter 2016

Virtual memory. Virtual memory - Swapping. Large virtual memory. Processes

Operating System Labs. Yuanbin Wu

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

Virtual Memory. Kevin Webb Swarthmore College March 8, 2018

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CSE 451: Operating Systems Winter Page Table Management, TLBs and Other Pragmatics. Gary Kimura

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

Memory Management. An expensive way to run multiple processes: Swapping. CPSC 410/611 : Operating Systems. Memory Management: Paging / Segmentation 1

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

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

CS 4284 Systems Capstone. Virtual Memory Page Tables Godmar Back

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

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

Recap: Memory Management

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 27, SPRING 2013

Memory Management. Dr. Yingwu Zhu

Virtual to physical address translation

ADRIAN PERRIG & TORSTEN HOEFLER Networks and Operating Systems ( ) Chapter 6: Demand Paging

143A: Principles of Operating Systems. Lecture 6: Address translation. Anton Burtsev January, 2017

Main Memory: Address Translation

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

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 27, FALL 2012

16 Sharing Main Memory Segmentation and Paging

Virtual Memory #2 Feb. 21, 2018

Memory Hierarchy. Goal: Fast, unlimited storage at a reasonable cost per bit.

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 24

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

Multi-level Page Tables & Paging+ segmentation combined

Virtual Memory. Samira Khan Apr 27, 2017

CS399 New Beginnings. Jonathan Walpole

Motivation, Concept, Paging January Winter Term 2008/09 Gerd Liefländer Universität Karlsruhe (TH), System Architecture Group

Chapter 5: Memory Management

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

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

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

Lecture 22: Virtual Memory: Survey of Modern Systems

Computer Architecture. Lecture 8: Virtual Memory

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

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

ECE 571 Advanced Microprocessor-Based Design Lecture 13

Operating Systems. Paging... Memory Management 2 Overview. Lecture 6 Memory management 2. Paging (contd.)

Chapter 8 Main Memory

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

Memory Management. Dr. Yingwu Zhu

HY225 Lecture 12: DRAM and Virtual Memory

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

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

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

Virtual Memory, Address Translation

VIRTUAL MEMORY II. Jo, Heeseung

ECE 598 Advanced Operating Systems Lecture 14

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

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

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

15 Sharing Main Memory Segmentation and Paging

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

Virtual Memory. 11/8/16 (election day) Vote!

CS 333 Introduction to Operating Systems. Class 11 Virtual Memory (1) Jonathan Walpole Computer Science Portland State University

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

Chapter 6: Demand Paging

Virtualizing Memory: Paging. Announcements

Virtual Memory. Computer Systems Principles

CS 550 Operating Systems Spring Memory Management: Paging

Virtual Memory I. Jo, Heeseung

Address Translation. Tore Larsen Material developed by: Kai Li, Princeton University

Lecture 4: Memory Management & The Programming Interface

1. Creates the illusion of an address space much larger than the physical memory

Memory Management (Chaper 4, Tanenbaum)

Translation Buffers (TLB s)

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

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

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

Chapter 8: Main Memory

Address spaces and memory management

Computer Architecture Lecture 13: Virtual Memory II

Computer Systems. Virtual Memory. Han, Hwansoo

memory management Vaibhav Bajpai

CSE 120 Principles of Operating Systems Spring 2017

ECE 571 Advanced Microprocessor-Based Design Lecture 12

CS252 Spring 2017 Graduate Computer Architecture. Lecture 17: Virtual Memory and Caches

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

Understanding the Design of Virtual Memory. Zhiqiang Lin

A Typical Memory Hierarchy

Chapter 8: Memory-Management Strategies

Transcription:

Virtual memory - Paging Johan Montelius KTH 2017 1 / 32

The process code (.text) data heap stack kernel 0x00000000 0xC0000000 0xffffffff Memory layout for a 32-bit Linux process 2 / 32

Segments - a could be solution Processes in virtual space Address translation by MMU (base and bounds) Physical memory 3 / 32

one problem Physical memory External fragmentation: free areas of free space that is hard to utilize. Solution: allocate larger segments... internal fragmentation. 4 / 32

another problem virtual space used code We re reserving physical memory that is not used. physical memory not used? 5 / 32

Let s try again It s easier to handle fixed size memory blocks. Can we map a process virtual space to a set of equal size blocks? An address is interpreted as a virtual page number (VPN) and an offset. 6 / 32

Remember the segmented MMU MMU exception no virtual addr. // offset < yes within bounds index + physical address segment table 7 / 32

The paging MMU MMU exception virtual addr. // offset VPN +? available physical address page table 8 / 32

the MMU virtual address exception exception Segmentation within bounds Paging page available linear address physical address 9 / 32

a note on the X86 architecture The x86-32 architecture supports both segmentation and paging. A virtual address is translated to a linear address using a segmentation table. The linear address is then translated to a physical address by paging. Linux and Windows do not use use segmentation to separate code, data nor stack. The X86-64 (the 64-bit version of the x86 architecture) has drooped many features for segmentation. Still used to control access rights of memory operations. Still used to manage thread local storage and CPU specific data. 10 / 32

the process Processes in virtual space Only pages actually used need to be in memory. Physical memory 11 / 32

three pages virtual space available not available (page fault) not allocated (segmentation fault) physical memory 12 / 32

The page table entry example Linux on (32bit) x86 31 12 20-bit frame number User/Supervisor Present R/W If the page index is 20 bits, does the frame number need to be 20 bits? 13 / 32

Physical Address Extension (PAE) In 1995 the x86 architecture provided 24-bit frame numbers. The CPU could thus address 64 Gibyte of physical address space (24-bit frame, 12-bit offset). Each process still had a 32-bit virtual address space, (20-bit page number, 12-bit offset) i.e. 4 Gibyte. The x86_64 architecture supports 48-bit virtual address space and up to 52-bit physical address space. Linux supports 48-bit virtual address (47-bit user space) and up to 46-bit physical address space (64 Tibyte). Check your address space in /proc/cpuinfo. Physical memory is in reality limited by chipset, motherboard, memory modules etc. Check your available memory in /proc/meminfo. 14 / 32

largest server Largest server on the market, SGI 3000, can scale up to 256 CPUs and 64 Tibyte of RAM (NUMA) - running Linux. 15 / 32

Speed matters movl 0x11111222, %eax we need a page table base register, PTBR the virtual page number, VPN, is 0x11111 read the page table entry from PTBR + (0x11111 * 8) extract frame number PFN from the entry the offset is 0x222 read the memory location at (PFN << 12) + 0x222 An extra memory operation for each memory reference. 16 / 32

TLB: hardware support The CPU keeps a translation look-aside buffer, TLB, with the most recent page table entries. The buffer is implemented using a content-addressable memory keyed by the virtual page number. If the page table entry is found - great! If the page table entry is not found - access the real page table in memory. 17 / 32

Who handles a TLB miss RISC architecture MIPS, Sparc, ARM The hardware rises an interrupt. The operating system jumps to a trap handler. The operating system will access the TLB and update the TLB. CISC architecture x86 The hardware knows where to find the page table (CR3 register). The hardware will access the page table and updates the TLB. 18 / 32

TLB replacement policy Which TLB entry should we remove if the TLB is full? 31 20-bit frame number Global 12 User/Supervisor Reference Present 1 Dirty R/W 19 / 32

Process switching What happens when we switch process? The TLB contains the cached translations of the running process, when switching process the TLB must (in general) be flushed. Do we have to flush the whole TLB? Is this best handled by the hardware or operating system? Can we do pre-fetching of page table entries? 20 / 32

The paging MMU with TLB virtual addr. // offset VPN TLB PFN + VPN PTE + PTBR physical address Page table in memory 21 / 32

Size matters Using 4 Kibyte pages (12 bits) for a 4 Gibyte address space (32 bits) will result in 1Mi (20 bits) page table entries. Each page table entry is 4 bytes. A page table has the size of 4 Mibyte. Each process has its own page table. For 100 processes we need room for 400 Mibyte of page tables. Problem! 22 / 32

The solution - not. Why not use pages of size 4 Mibyte? Use a 22 bit offset and 10 bit virtual page number. Page table 4 Kibyte (1024 entries, 4 byte each). Case closed! 4 Mibyte pages are used and do have advantages but it is not a general solution. 23 / 32

Mostly empty space code (.text) data heap stack kernel 0x00000000 0xC0000000 0xffffffff Map only the areas that are actually used. 24 / 32

Hybrid approach - paged segmented memory What if each segment was rarely larger than 1Ki pages of 4Kibyte. 31 29 12 0 seg 18-bit page number 12-bit offset base page page table base/bound frame number bound 25 / 32

Multi-level page table 31 22 12 0 10-bit directory index 10-bit page index 12-bit offset page directory page table page 26 / 32

Mostly empty space page directory each page table can map 4 Mibyte virtual address space 27 / 32

More than two levels 31 29 2120 12 0 12-bit offset 9-bit page table index 9-bit page middle directory index 2-bit page global directory index Scheme used in PAE, where each entry has a 24-bit physical base address. Trace the translation of a 32-bit virtual address to a 36-bit physical address. 28 / 32

Linux on x86_64 architectures A 64-bit address but only 48-bits are used. Bits 63-47 are either 1, kernel space, or 0, user space. The 48 bits are divided into: 9-bit page global directory index 9-bit page upper directory index 9-bit page lower directory index 9-bit page table index 12-bit offset A page table entry is 8 bytes and contains a 40-bit physical address base address. The 40-bit base is combined with the 12-bit index to a 52-bit physical address. 29 / 32

Inverted page tables Why not do something completely different? We will probably not have more than say 8 Gibyte of main memory. If we divide this into 4 Kibyte frames we have 2 Mi frames. Assume maintain a table with 2 Mi entries that describes which process and page that occupies the frame. To translating a virtual address we simply search the table (efficient if we use a hash table). Used by some models of PowerPC, Ultra Sparc and Itanium. 30 / 32

Summary Segmentation is not an ideal solution (why?). Small fixed size pages is a solution. Speed of translation is a problem (what is the solution?) The size of the page table is a problem (and you know how to solve it). Inverted page tables - an alternative approach. 31 / 32

AC/DC - TLB TLB - dynamite, makes paging possible. 32 / 32