Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Similar documents
Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CSE 120 Principles of Operating Systems Spring 2017

CSE 120 Principles of Operating Systems

CS 153 Design of Operating Systems Winter 2016

VIRTUAL MEMORY. Operating Systems 2015 Spring by Euiseong Seo

Page Tables. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Virtual Memory I. Jo, Heeseung

CS 318 Principles of Operating Systems

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

Recap: Memory Management

Memory Management. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Lecture 12: Demand Paging

Virtual Memory. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Virtual Memory III. Jo, Heeseung

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CSE 153 Design of Operating Systems

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

Opera&ng Systems ECE344

File System Implementation. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

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

Outline. V Computer Systems Organization II (Honors) (Introductory Operating Systems) Advantages of Multi-level Page Tables

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

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

CS 153 Design of Operating Systems Winter 2016

Swapping. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

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

Address spaces and memory management

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

VIRTUAL MEMORY II. Jo, Heeseung

CS 153 Design of Operating Systems

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

Memory Management - Demand Paging and Multi-level Page Tables

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Memory Management

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

CS 550 Operating Systems Spring Memory Management: Paging

Basic Memory Management. Basic Memory Management. Address Binding. Running a user program. Operating Systems 10/14/2018 CSC 256/456 1

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

Memory management: outline

Memory management: outline

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

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

Virtual Memory. CS 351: Systems Programming Michael Saelee

Virtual Memory Outline

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

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

! What is main memory? ! What is static and dynamic allocation? ! What is segmentation? Maria Hybinette, UGA. High Address (0x7fffffff) !

Virtual Memory. Samira Khan Apr 27, 2017

Basic Memory Management

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

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

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

Memory Management. Goals of Memory Management. Mechanism. Policies

2-Level Page Tables. Virtual Address Space: 2 32 bytes. Offset or Displacement field in VA: 12 bits

EECS 482 Introduction to Operating Systems

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

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

CS399 New Beginnings. Jonathan Walpole

Multi-Process Systems: Memory (2) Memory & paging structures: free frames. Memory & paging structures. Physical memory

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

Chapter 8: Virtual Memory. Operating System Concepts

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

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

Main Memory: Address Translation

Main Points. Address Transla+on Concept. Flexible Address Transla+on. Efficient Address Transla+on

Computer Architecture. Lecture 8: Virtual Memory

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 13: Address Translation

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

Lecture 13: Address Translation

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

memory management Vaibhav Bajpai

CS153: Memory Management 1

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Goals of Memory Management

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

CS 134: Operating Systems

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

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

OPERATING SYSTEM. Chapter 9: Virtual Memory

CSE 4/521 Introduction to Operating Systems. Lecture 15 Virtual Memory I (Background, Demand Paging) Summer 2018

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

CS370 Operating Systems

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

Virtual Memory. Reading: Silberschatz chapter 10 Reading: Stallings. chapter 8 EEL 358

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

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

Goals of memory management

Virtual to physical address translation

Processes and Virtual Memory Concepts

Computer Systems. Virtual Memory. Han, Hwansoo

Page Replacement Chap 21, 22. Dongkun Shin, SKKU

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

Virtualizing Memory: Paging. Announcements

Virtual Memory. Today. Handling bigger address spaces Speeding translation

Memory System Case Studies Oct. 13, 2008


Transcription:

Paging Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu

Paging Allows the physical address space of a process to be noncontiguous Divide virtual memory into blocks of same size (pages) Divide physical memory into fixed-size blocks (frames) Page (or frame) size is power of 2 (typically 512B 8KB) Eases memory management OS keeps track of all free frames To run a program of size n pages, need to find n free frames and load the program Set up a page table to translate virtual to physical addresses No external fragmentation 2

Paging Overview Physical memory Process B Virtual memory Page 3 Page 2 Page 1 9 7 11 4 Frame 11 Frame 10 Frame 9 Frame 8 Process A Page 0 Page 5 Page 4 Page 3 Page 2 Page 1 Page tables 6 5 10 2 0 3 Frame 7 Frame 6 Frame 5 Frame 4 Frame 3 Frame 2 Frame 1 Page 0 Frame 0 3

Address Translation (1) Translating virtual addresses A virtual address has two parts: <Virtual Page Number (VPN), Offset> VPN is an index into the page table Page table determines Page Frame Number (PFN) Physical address is <PFN, Offset> Usually, VPN >= PFN Page tables Managed by OS Map VPN to PFN One Page Table Entry (PTE) per page in virtual address space 4

Address Translation (2) 5

Address Translation (3) Example Virtual address: 32 bits Physical address: 20 bits Page size: 4KB Offset: 12 bits VPN: 20 bits Page table entries: 2 20 Page table size? 0 Virtual address (32bits) 0 0 0 4 A F E VPN 2 7 D 0 3 1 F E 4 6 A 4 Page table PFN Offset 4 6 A F E Physical address (20bits) 6

Protection Separate page table for each process No way to access the physical memory of other processes On context switch, an MMU register is set to point to the base address of the current page table (e.g. CR3 in IA-32) Page-level protection Memory protection is implemented by associating protection bits with each PTE Valid / invalid bit Valid : the page is in the process address space and in use Invalid : the page is not allocated Finer level of protection is possible for valid pages Read-only, Read-write, or execute-only protections 7

Page Table Entry PTE 1 1 1 2 20 V R M Prot Page Frame Number (PFN) V (Valid) bit says whether or not the PTE can be used It is checked each time a virtual address is used R (Reference) bit says whether the page has been accessed It is set when a read or write to the page occurs M (Modify) bit says whether the page is dirty It is set when a write to the page occurs Prot (Protection) bits control which operations are allowed Read, Write, Execute, etc. PFN (Page Frame Number) determines the physical frame 8

Demand Paging OS uses main memory as a (page) cache of all the data allocated by processes in the system Bring a page into memory only when it is needed Pages can be evicted from their physical memory frames Evicted pages go to disk (only dirty pages are written) Movement of pages is transparent to processes Benefits Less I/O needed Less memory needed Faster response More processes 9

Page Fault An exception raised by CPU when accessing invalid PTE Major page faults The page is valid but not loaded into memory OS maintains information on where to find the contents Require disk I/Os Minor page faults Page faults can be resolved without disk I/O Used for lazy allocation (e.g. accesses to stack & heap pages) Accesses to prefetched pages, etc. Invalid page faults Segmentation violation: the page is not in use 10

Handling Page Faults 11

Shared Memory Allows processes to share data using direct memory reference Implementation Have PTEs in both tables map to the same physical frame Each PTE can have different protection values Must update both PTEs when page becomes invalid Mapping shared memory in the virtual address space At the different address: flexible (no address space conflicts), but pointers inside the shared memory are invalid At the same address: less flexible, but shared pointers are valid 12

Memory-Mapped Files (1) Allows processes to perform file I/O using memory references Instead of open(), read(), write(), close(), etc. mmap(): bind a file to a virtual memory region Implementation Initially, all pages in mapped region marked as invalid OS reads a page from file whenever invalid page is accessed OS writes a page to file when evicted from physical memory If page is not dirty, no write needed PTEs map virtual addresses to page frames holding file data <Virtual address base + n> refers to offset n in file 13

Memory-Mapped Files (2) Pros Uniform access for files and memory (just use pointers) Less memory copying Several processes can map the same file allowing the pages in memory to be shared Cons Process has less control over data movement Does not generalize to streamed I/O (pipes, sockets, etc.) 14

Copy-on-Write (1) Defers memory copies as long as possible, hoping to avoid them altogether Implementation Instead of copying pages, create shared mappings to the same page frames in physical memory Shared pages are protected as read-only When data is written to these pages, OS allocates new space in physical memory and directs the write to it Usage fork() Allocating data and heap pages, etc. 15

Copy-on-Write (2) Copy-on-write during fork() Instead of copying all pages, create shared mappings of parent pages in child address space Shared pages are protected as read-only in child Reads happen as usual Writes generate a protection fault and OS copies the page, changes page mapping, and restarts write instruction write Process fork() child process Page table RO RO Physical memory copied 16

Paging: Pros No external fragmentation Fast to allocate and free A list or bitmap for free page frames Allocation: no need to find contiguous free space Free: no need to coalesce with adjacent free space Easy to page out portions of memory to disk Page size is chosen to be a multiple of disk block sizes Use valid bit to detect reference to paged-out pages Can run process when some pages are on disk Easy to protect and share pages 17

Paging: Cons Internal fragmentation Wasted memory grows with larger pages Memory reference overhead Doubles the number memory references per instruction Solution: get hardware support (TLBs) Storage needed for page tables Needs one PTE for each page in virtual address space 32-bit address space with 4KB page size: 2 20 PTEs 4 bytes/pte: 4MB per page table 100 processes in the system: total 400MB of page tables Solution: store valid PTEs only or page the page table 18