Memory Management - Demand Paging and Multi-level Page Tables

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

Memory Management. Goals of Memory Management. Mechanism. Policies

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

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

CS 153 Design of Operating Systems Winter 2016

CSE 120 Principles of Operating Systems Spring 2017

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

CSE 120 Principles of Operating Systems

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

stack Two-dimensional logical addresses Fixed Allocation Binary Page Table

Recap: Memory Management

CS 153 Design of Operating Systems Winter 2016

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

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

CS307 Operating Systems Main Memory

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

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

Virtual Memory I. Jo, Heeseung

CS399 New Beginnings. Jonathan Walpole

Main Memory: Address Translation

CS399 New Beginnings. Jonathan Walpole

CS 318 Principles of Operating Systems

CS 134: Operating Systems

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

Address spaces and memory management

CSE 153 Design of Operating Systems

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

VIRTUAL MEMORY. Operating Systems 2015 Spring by Euiseong Seo

VIRTUAL MEMORY II. Jo, Heeseung

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

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

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

Preview. Memory Management

Lecture 4: Memory Management & The Programming Interface

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

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

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

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

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

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

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

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

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

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

Basic Memory Management

Virtual to physical address translation

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

CS370 Operating Systems

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

CS370 Operating Systems

Memory management: outline

6.033 Spring 2018 Lecture #3

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

CS307: Operating Systems

Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses.

The Virtual Memory Abstraction. Memory Management. Address spaces: Physical and Virtual. Address Translation

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

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition

CS3600 SYSTEMS AND NETWORKS

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science

Memory Management. Memory Management

Chapter 7: Main Memory. Operating System Concepts Essentials 8 th Edition

198:231 Intro to Computer Organization. 198:231 Introduction to Computer Organization Lecture 14

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

CIS Operating Systems Memory Management Address Translation. Professor Qiang Zeng Fall 2017

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

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

CS 261 Fall Mike Lam, Professor. Virtual Memory

Segmentation (Apr 5 and 7, 2005)

Introduction to Virtual Memory Management

Main Memory (Part II)

ENGR 3950U / CSCI 3020U Midterm Exam SOLUTIONS, Fall 2012 SOLUTIONS

The memory of a program. Paging and Virtual Memory. Swapping. Paging. Physical to logical address mapping. Memory management: Review

16 Sharing Main Memory Segmentation and Paging

Memory management: outline

CS510 Operating System Foundations. Jonathan Walpole

Solution to the. Gaming Parlor. Programming Project

CS 550 Operating Systems Spring Memory Management: Paging

Virtual Memory. Kevin Webb Swarthmore College March 8, 2018

Chapter 6: Demand Paging

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

Memory Management. Dr. Yingwu Zhu

Virtual Memory III. Jo, Heeseung

Virtual Memory. P & H Chapter 5.4 (up to TLBs) Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University

CS 333 Introduction to Operating Systems Class 2 OS-Related Hardware & Software The Process Concept

Chapters 9 & 10: Memory Management and Virtual Memory

Chapter 8 Memory Management

Main Memory. CISC3595, Spring 2015 X. Zhang Fordham University

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

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

Performance of Various Levels of Storage. Movement between levels of storage hierarchy can be explicit or implicit

Memory Management (2)

The cow and Zaphod... Virtual Memory #2 Feb. 21, 2007

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

CS 550 Operating Systems Spring Memory Management: Page Replacement

Transcription:

Memory Management - Demand Paging and Multi-level Page Tables CS 416: Operating Systems Design, Spring 2011 Department of Computer Science Rutgers Sakai: 01:198:416 Sp11 (https://sakai.rutgers.edu)

Topics for the day What happens when a page is not in memory? How do we prevent having page tables take up a huge amount of physical memory themselves? 2 Gayathri Chandrasekaran

Questions from last week that needs clarification Question 1: With 20 bits allocated to the number of pages, the number of page table entries could be : 4bytes * 2 20 pages = 4MB Is this entire 4MB space allocated contiguously in Physical Memory? (My Answer was Yes, But the answer is NO. We will see how it is held today) Are all processes having 4MB of Page Tables? They could have, but in practice, they are allocated at the time of process creation to be size of code + fixed size partitions. The number of page tables entries would be the Maximum number of pages allocated to this process. When there is a page fault, can a process kick out frames belonging to other process? Yes, the OS handles Page replacement. Therefore, it can access the process s page tables and mark the entry corresponding to the frame as invalid. 3

Page Faults When a virtual address translation cannot be performed, it s called a page fault 4 Gayathri Chandrasekaran

Trap to the OS Handling Page Fault Save user Register and Process State Check whether the page reference was legal and determine the location of the page on memory Issue a read from disk to a free frame Block for the disk operation to be complete On receiving Interrupt for disk transfer completion, save other process state Serve the interrupt from the disk and Fix the page table entry Wait for the CPU to be allocated to this process again Restore state and continue execution 5

Page Faults Valid Bit indicates whether a page translation is valid If Valid bit is set to 0, then a page fault will occur Protection Bits tells whether a page is readable, writeable, executable Page fault occurs when we attempt to write a read-only page This is sometimes called Protection Fault 6

Demand Paging Does it make sense to read an entire program into memory at once No! Remember we talked about an example where some code never executes For example, if you never use the Save as PDF function in office What are these holes in the virtual address space mean? 7

What are these holes? Three kinds of holes in a process s page tables: Pages that are on disk Swapped out to disk due to lack of space in Physical Memory owhen a page fault occurs, load the corresponding page from the disk Pages that have not been accessed yet For Example, newly allocated memory owhen a page fault occurs, allocate a new physical page Pages that are invalid For example, the NULL POINTER always points to page at address 0x0 owhen a NULL address is accessed, we get segmentation fault! otrying to access 0x0 creates page fault, and the OS kills the offending process 8

Starting up a process What does a process address space looks like when it starts? 9

Starting up a process What does the process s address space look like when it first starts up 10

Starting up a process What does the process s address space look like when it first starts up 11

Starting up a process What does the process s address space look like when it first starts up 12

Starting up a process What does the process s address space look like when it first starts up 13

Starting up a process What does the process s address space look like when it first starts up 14

Starting up a process What does the process s address space look like when it first starts up 15

Uninitialized Variables and the heap Page faults bring in pages from the executable file for: Code (text segment) pages, Initialized variables What about Un-initialized variables and the heap? Say I have a global variable int c in the program..what happens when the process first accesses it? Page fault occurs OS looks at the page and realizes that it corresponds to a Zero Page Allocates a new frame in the main memory and sets all bytes to ZERO Maps the frame into the address space What about the heap? malloc() just maps new zero pages into the address space Brings in new empty pages into the frame only when page fault occurs 16

More Demand Paging Tricks Paging can be used by processes to share memory A significant portion of many process s address space is identical 17

More Demand Paging Tricks This can be used to let different processes share memory UNIX supports shared memory through the shmget/shmat/shmdt system calls Allocates a region of memory that is shared across multiple processes Some of the benefits of multiple threads per process, but the rest of the processes address space is protected owhy not just use multiple processes with shared memory regions? Memory-mapped files Idea: Make a file on disk look like a block of memory Works just like faulting in pages from executable files In fact, many OS's use the same code for both One wrinkle: Writes to the memory region must be reflected in the file How does this work? owhen writing to the page, mark the modified bit in the PTE owhen page is removed from memory, write back to original file 18

Remember fork() fork() creates an exact copy of a process What does this imply about page tables? When we fork a new process, does it make sense to make a copy of all of its memory? Why or why not? What if the child process doesn't end up touching most of the memory the parent was using? What happens if a process does an exec() immediately after fork()? 19

Copy on Write Share the pages among parent and child, but don t let the child write to any pages directly Parents forks a child, Child gets a copy of the parent s page tables. 20

Copy on Write All Pages (both parent and child) marked read-only Why? 21

Copy on Write What happens when the child writes the pages Protection fault occurs OS copies the page and maps it R/W into child s address space 22

Page Tables Recall that page tables for every process could be as large as 4MB 23

Multi-Level Page Tables Can t hold all of the page tables in memory Solution: Page the page tables Allow portions of the page tables to be kept in memory at one time 24

Multi-Level Page Tables Can t hold all of the page tables in memory Solution: Page the page tables Allow portions of the page tables to be kept in memory at one time 25

Multi-Level Page Tables Can t hold all of the page tables in memory Solution: Page the page tables Allow portions of the page tables to be kept in memory at one time 26

Multi-Level Page Tables Can t hold all of the page tables in memory Solution: Page the page tables Allow portions of the page tables to be kept in memory at one time 27

Multilevel page tables With two levels of page tables, how big is each table? Say we allocate 10 bits to the primary page, 10 bits to the secondary page, 12 bits to the page offset Primary page table is then 2^10 * 4 bytes per PTE == 4 KB Secondary page table is also 4 KB ohey... that's exactly the size of a page on most systems... cool What happens on a page fault? MMU looks up index in primary page table to get secondary page table oassume this is wired to physical memory MMU tries to access secondary page table omay result in another page fault to load the secondary table! MMU looks up index in secondary page table to get PFN CPU can then access physical memory address Issues Page translation has very high overhead oup to three memory accesses plus two disk I/Os!! TLB usage is clearly very important. 28

Multilevel Paging and Performance Since each level is stored as a separate table in memory, covering a logical address to a physical one may take three memory accesses. CPU Generates an address Use the first 10 bits to read a memory location (outer page table) first access Use the first page table to locate the frame for second page table Second access Get the (frame number + offset) and read the actual memory location. Third access Average page fault service time = 8ms Average memory access time = 200ns Let the probability of page fault be p Effective Access time per memory access : (1-p)*200ns + p*8ms 29 CS 416: Operating Systems

Where does caching fit here? After the Physical Address is Identified, the CPU first check the Cache to see if the entire block is already in cache! If yes, accesses are much faster If not, the block is transferred to the cache. 0 1 2 Virtual Memory A B C 3 Memory A Disk B C Cache 30

Inverted Page Table One entry for each real frame of memory. Entry consists of the virtual address of the page stored in that real memory location, with information about the process that owns that page. Decreases memory needed to store each page table, but increases time needed to search the table when a page reference occurs. 31 CS 416: Operating Systems

Inverted Page Table Architecture 32 CS 416: Operating Systems

Page Replacement Algorithms! Next Lecture 33