CS 550 Operating Systems Spring Memory Management: Paging

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

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

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

Virtual Memory. Today. Handling bigger address spaces Speeding translation

12: Memory Management

CS399 New Beginnings. Jonathan Walpole

Operating System Labs. Yuanbin Wu

Operating System Labs. Yuanbin Wu

Virtual Memory. Yannis Smaragdakis, U. Athens

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

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

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

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

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

CS 390 Chapter 8 Homework Solutions

(page 0 of the address space) (page 1) (page 2) (page 3) Figure 12.1: A Simple 64-byte Address Space

Processes and Tasks What comprises the state of a running program (a process or task)?

Preview. Memory Management

Memory management: outline

Virtualizing Memory: Paging. Announcements

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

Memory Management. Today. Next Time. Basic memory management Swapping Kernel memory allocation. Virtual memory

Memory management: outline

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

Operating Systems, Fall

Operating Systems, Fall

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

Virtual Memory Virtual memory first used to relive programmers from the burden of managing overlays.

Memory Management. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Memory Management. Goals of Memory Management. Mechanism. Policies

Memory Management. Dr. Yingwu Zhu

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

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

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

Memory Management Prof. James L. Frankel Harvard University

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

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

Chapter 4 Memory Management

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

ECE331: Hardware Organization and Design

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CS 3733 Operating Systems:

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

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

Processes and Virtual Memory Concepts

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

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

Chapter 4: Memory Management. Part 1: Mechanisms for Managing Memory

Operating Systems Memory Management. Mathieu Delalandre University of Tours, Tours city, France

Memory Management. To do. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

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

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

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

143A: Principles of Operating Systems. Lecture 5: Address translation. Anton Burtsev October, 2018

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

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

20. Paging: Smaller Tables

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

Virtual Memory. CS 351: Systems Programming Michael Saelee

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

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

VIRTUAL MEMORY. Operating Systems 2015 Spring by Euiseong Seo

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

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

Operating Systems and Computer Networks. Memory Management. Dr.-Ing. Pascal A. Klein

Registers Cache Main memory Magnetic disk Magnetic tape

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

Virtual Memory. Virtual Memory

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Operating Systems. 09. Memory Management Part 1. Paul Krzyzanowski. Rutgers University. Spring 2015

memory management Vaibhav Bajpai

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

Memory Management. Chapter 4 Memory Management. Multiprogramming with Fixed Partitions. Ideally programmers want memory that is.

Computer Architecture. Lecture 8: Virtual Memory

Virtual Memory I. Jo, Heeseung

CS153: Memory Management 1

Chapter 8 Memory Management

CISC 7310X. C08: Virtual Memory. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/22/2018 CUNY Brooklyn College

CS370 Operating Systems

CSC 369 Operating Systems

Memory Management. Reading: Silberschatz chapter 9 Reading: Stallings. chapter 7 EEL 358

Objectives and Functions Convenience. William Stallings Computer Organization and Architecture 7 th Edition. Efficiency

Chapter 8. Virtual Memory

MEMORY: SWAPPING. Shivaram Venkataraman CS 537, Spring 2019

Operating System Support

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 24

Memory management OS

Paging: Introduction A Simple Example And Overview

Memory Management - Demand Paging and Multi-level Page Tables

UNIT III MEMORY MANAGEMENT

Recap: Memory Management

Computer Structure. X86 Virtual Memory and TLB

Chapter 9 Memory Management Main Memory Operating system concepts. Sixth Edition. Silberschatz, Galvin, and Gagne 8.1

CS 153 Design of Operating Systems Winter 2016

More on Address Translation. CS170 Fall T. Yang Some of slides from UCB CS162 by Kubiatowicz

ECE 598 Advanced Operating Systems Lecture 10

Chapter Seven. Memories: Review. Exploiting Memory Hierarchy CACHE MEMORY AND VIRTUAL MEMORY

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

Main Memory: Address Translation

Transcription:

CS 550 Operating Systems Spring 2018 Memory Management: Paging 1

Recap: Memory Management Ideally programmers want memory that is large fast non volatile Memory hierarchy small amount of fast, expensive memory cache some medium-speed, medium price main memory Lots of slow, cheap disk storage Memory manager handles the memory hierarchy 2

Recap: (Virtual) Address Space The abstraction that the OS is providing to the running program The running program has an illusion that it is can use the memory space starting at a particular address (e.g., 0x0), and going up to a very large address space (e.g., 32-bits or 64- bits); 0KB 1KB 2KB 15KB 16KB Program Code Heap (free) Stack the code segment: where instructions live the heap segment: contains malloc d data dynamic data structures (it grows downward) (it grows upward) the stack segment: contains local variables arguments to routines, return values, etc. 0KB 64KB 128KB 192KB 256KB 320KB 384KB 448KB 512KB Operating System (code, data, etc.) (free) Process C (code, data, etc.) Process B (code, data, etc.) (free) Process A (code, data, etc.) (free) (free) 3

Recap: Relocation Relocation Address locations in a program are relative. They are added to a base value to map to physical addresses. LIMIT 0 Physical MAX Relative Addresses in original program binary BASE + LIMIT Relocated Addresses in Executing Binary BASE 0 4

Recap: Paging Paging Split up the address space into equal-sized units, which are called pages. OS then decides which pages stay in memory and which get moved to disk. Virtual Address Space of a single Process } Page Entire Physical RAM 5

Recap: Memory Management Unit (MMU) MMU is a hardware module that accompanies the CPU It translates the Virtual Address used by executing instructions to Physical Addresses in the main memory. 6

Recap: Page Table An array that stores the mapping from virtual page numbers (VPN) to physical frame number (PFN) The OS maintains One page table per userspace process. And usually another page table for kernel memory. VPN PFN 7

Address Translation Consider a machine that has a 32-bit virtual address size and 4 KByte page size. 1.How large is the virtual address space? 2^32 = 4 GB 1.How many virtual pages could a process have? 4GB/4KB = 2^20 2. How many page-table entries (for one process) are there in the page table? 4GB/4KB = 2^20 3. How many address bits are needed to select a page Log2(2^20) = 20 4. How many address bits are needed for the byte offset within a 4-KB page Log2(4KB) =Log2(2^12) = 12 8

Address Translation Given the 4 KByte page size, a 32-bit virtual address is divided into: 31 30 29 28 12 11 10 1 0 VPN Byte offset 9

Recap: Virtual Address Translation For Small Address Space Internal operation of MMU with 16 4 KB pages 10

Quiz Consider a machine that has a 32-bit virtual address space and 8KByte page size. 1.How many virtual pages could a process have? 2.How many bits in a 32-bit address are needed to determine the virtual page number of the address? 3.How many bits in a 32-bit address represent the byte offset into a page? 11

Quiz Answers Consider a machine that has a 32-bit virtual address space and 8KByte page size. 1. How many virtual pages could a process have? 4GB/8KB = 512*1024 = 2^9*2^10 = 2^19 2. How many bits in a 32-bit address are needed to determine the virtual page number of the address? log2(4gb/8kb) = log2(2^19) = 19 bits 3. How many bits in a 32-bit address represent the byte offset into a page? log2(8kb) = log2(2^13) = 13 Also, 32 19 = 13 bits 12

Problems Consider a machine that has a 32-bit virtual address space and 4 KByte page size. 1.How many virtual pages could a process have? 4GB/4KB = 2^20 2. How many page-table entries (for one process) are there in the page table? 4GB/4KB = 2^20 3. How many address bits are needed to select a page Log2(2^20) = 20 4. How many address bits are needed for the byte offset within a 4-KB page Log2(4KB) =Log2(2^12) = 12 13

Problems 32-bit address space with 4KB pages 4 bytes per page table entry (PTE): 4 2 20 = 4 MB Is this a big deal? If there are 100 processes, 400 MB space is needed just for storing page tables! We cannot keep page tables in any special on-chip hardware. Instead, page tables are stored in kernel memory. 14

Solution 1: Bigger pages 32 bit address, 4 KB pages 20 bit VPN, 12 bit offset 2^20 = 1M pages (entries) 4MB per process 32 bit address, 16 KB pages 18 bit VPN, 14 bit offset 2^18 = 256K pages (entries) 1MB per process 32 bit address, 1 MB pages 12 bit VPN, 20 bit offset 2^12 = 4 K pages (entries) 16 KB per process Problems? Internal fragmentation Reality: 4KB or 8KB pages. 15

Fragmentation Fragmentation is a phenomenon in which storage space is used inefficiently, reducing capacity or performance and often both. Types of fragmentation Internal fragmentation: the wasted space within each allocated block because of rounding up from the actual requested allocation to the allocation granularity. External fragmentation: the various free spaced holes that are generated in either your memory or disk space. 16

Solution 2: Multi-level page tables The high-level idea to get rid of those invalid/unused regions in the page table instead of keeping them all in memory. The basic idea Divide up the page table into equal-sized regions. if an entire region of page-table entries is invalid, don t allocate space for that region at all. 17

Virtual Address Translation For Large Address Space Second-level page tables 32 bit address with 4 KB pages: Top-level page table Two-level page tables But how does MMU know where to find PT? Registers (CR2 on Intel) 18

Virtual Address Translation For Large Address Space Second-level page tables 32 bit address with 2 page table fields Top-level page table Two-level page tables But how does MMU know where to find PT? Registers (CR2 on Intel) 19

A detailed multi-level example 14 bit address size, with 64-byte pages How many bits for offset, VPN? How many PTE in a linear page table? 6 bit offset (log2(64) = 6) 8 bit VPN (2^8=256 PTEs for a linear page table) Single-level page tables For the linear page table, we need to allocate 256 PTEs. Assume we divide the 256 PTEs to 16 chunks sub page tables, with each chunk (or sub page tables) containing 256 / 16 = 16 PTEs. Then, the page directory (PD) contain 16 entries, each points to one of the 16 sub page tables. 20

14 bit address (8 bit VPN, 6 bit offset) 16 entries in page directory 4 bit for page directory index Each sub page table have 16 PTEs 4 bit for page table index 21

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Single-level page table Page Directory Second-level Page Table Multi-level page tables 22

Single-level page tables 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Page Directory Second-level Page Table Multi-level page tables Instead of allocate 256 PTEs for the whole page table (linear-page table), 2-level page table only needs to allocate 48 PTEs. 23

Typical Page Table Entry (PTE) Page Frame number = physical page number for the virtual page represented by the PTE Referenced bit: Whether the page was accessed since last time the bit was reset. Modified bit: Also called Dirty bit. Whether the page was written to, since the last time the bit was reset. Protection bits: Whether the page is readable? writeable? executable? contains higher privilege code/data? Present/Absent bit: Whether the PTE contains a valid page frame #. Used for marking swapped/unallocated pages. 24

Paging is slow Where is the page table of the running process stored? Page-table base register: physical address of the starting location of the page table Pseudo-code of address translation with paging VPN = (VirtualAddress & VPN_MASK) >> SHIFT PTEAddr = PageTableBaseRegister + (VPN * sizeof(pte)) offset = VirtualAddress & OFFSET_MASK PhysAddr = (PFN << SHIFT) offset 25