Lecture 14 PA2. Lab 2: Demand Paging Implement the following syscalls xmmap, xmunmap, vcreate, vgetmem/vfreemem, srpolicy Deadline: November 4 2015, 10:00.

Slides:



Advertisements
Similar presentations
CSCC69: Operating Systems
Advertisements

EECS 470 Virtual Memory Lecture 15. Why Use Virtual Memory? Decouples size of physical memory from programmer visible virtual memory Provides a convenient.
Caching and Virtual Memory. Main Points Cache concept – Hardware vs. software caches When caches work and when they don’t – Spatial/temporal locality.
Computer Organization CS224 Fall 2012 Lesson 44. Virtual Memory  Use main memory as a “cache” for secondary (disk) storage l Managed jointly by CPU hardware.
Lecture 11 PA2, lock, and CV. Lab 3: Demand Paging Implement the following syscalls xmmap, xmunmap, vcreate, vgetmem/vfreemem, srpolicy Deadline: March.
Memory Management (II)
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Memory Management -3 CS 342 – Operating Systems Ibrahim Korpeoglu Bilkent.
Computer ArchitectureFall 2008 © November 10, 2007 Nael Abu-Ghazaleh Lecture 23 Virtual.
Memory Management and Paging CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Computer ArchitectureFall 2007 © November 21, 2007 Karem A. Sakallah Lecture 23 Virtual Memory (2) CS : Computer Architecture.
CS 333 Introduction to Operating Systems Class 11 – Virtual Memory (1)
Translation Buffers (TLB’s)
Virtual Memory and Paging J. Nelson Amaral. Large Data Sets Size of address space: – 32-bit machines: 2 32 = 4 GB – 64-bit machines: 2 64 = a huge number.
CSE451 Introduction to Operating Systems Spring 2007 Module 12 Memory Management Hardware Support Gary Kimura & Mark Zbikowski April 27, 2007.
Memory Management in Windows and Linux &. Windows Memory Management Virtual memory manager (VMM) –Executive component responsible for managing memory.
Caching and Virtual Memory. Main Points Cache concept – Hardware vs. software caches When caches work and when they don’t – Spatial/temporal locality.
Operating Systems Lecture 11 MIPS TLB Structure Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
Operating Systems ECE344 Ding Yuan Paging Lecture 8: Paging.
1 Virtual Memory. 2 Outline Pentium/Linux Memory System Core i7 Suggested reading: 9.6, 9.7.
Virtual Memory Expanding Memory Multiple Concurrent Processes.
© 2004, D. J. Foreman 1 Virtual Memory. © 2004, D. J. Foreman 2 Objectives  Avoid copy/restore entire address space  Avoid unusable holes in memory.
Chapter 4 Memory Management Virtual Memory.
Virtual Memory 1 Chapter 13. Virtual Memory Introduction Demand Paging Hardware Requirements 4.3 BSD Virtual Memory 4.3 BSD Memory Management Operations.
Pentium III Memory.
1 Memory Management. 2 Fixed Partitions Legend Free Space 0k 4k 16k 64k 128k Internal fragmentation (cannot be reallocated) Divide memory into n (possible.
Review °Apply Principle of Locality Recursively °Manage memory to disk? Treat as cache Included protection as bonus, now critical Use Page Table of mappings.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Demand Paging.
Processes and Virtual Memory
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Implementation.
Virtual Memory Ch. 8 & 9 Silberschatz Operating Systems Book.
Virtual Memory Review Goal: give illusion of a large memory Allow many processes to share single memory Strategy Break physical memory up into blocks (pages)
Virtual Memory 1 Computer Organization II © McQuain Virtual Memory Use main memory as a “cache” for secondary (disk) storage – Managed jointly.
CS203 – Advanced Computer Architecture Virtual Memory.
1 Virtual Memory. 2 Outline Case analysis –Pentium/Linux Memory System –Core i7 Suggested reading: 9.7.
CS161 – Design and Architecture of Computer
Translation Lookaside Buffer
CS161 – Design and Architecture of Computer
Memory Caches & TLB Virtual Memory
Section 9: Virtual Memory (VM)
Modeling Page Replacement Algorithms
Paging Adapted from: © Ed Lazowska, Hank Levy, Andrea And Remzi Arpaci-Dussea, Michael Swift.
CS510 Operating System Foundations
CSE 153 Design of Operating Systems Winter 2018
CSE 153 Design of Operating Systems Winter 2018
From Address Translation to Demand Paging
Modeling Page Replacement Algorithms
Translation Lookaside Buffer
Introduction to the Pentium’s support for “virtual” memory
CSE 451: Operating Systems Autumn 2005 Memory Management
Translation Buffers (TLB’s)
Virtual Memory Overcoming main memory size limitation
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE451 Virtual Memory Paging Autumn 2002
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 451: Operating Systems Autumn 2004 Page Tables, TLBs, and Other Pragmatics Hank Levy 1.
Translation Buffers (TLB’s)
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Lecture 7: Flexible Address Translation
Lecture 8: Efficient Address Translation
CSE 153 Design of Operating Systems Winter 2019
CSE 451: Operating Systems Winter 2005 Page Tables, TLBs, and Other Pragmatics Steve Gribble 1.
CSE 153 Design of Operating Systems Winter 2019
Lecture 9: Caching and Demand-Paged Virtual Memory
Translation Buffers (TLBs)
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
Review What are the advantages/disadvantages of pages versus segments?
Virtual Memory 1 1.
Paging Adapted from: © Ed Lazowska, Hank Levy, Andrea And Remzi Arpaci-Dussea, Michael Swift.
Presentation transcript:

Lecture 14 PA2

Lab 2: Demand Paging Implement the following syscalls xmmap, xmunmap, vcreate, vgetmem/vfreemem, srpolicy Deadline: November , 10:00 PM

Demand Paging – OS From the OS perspective: Evict pages to disk (backing store) when memory is full Pages loaded from disk when referenced again References to evicted pages cause a TLB miss Page table entry (PTE) present bit was false, causes fault OS allocates a page frame, reads page from disk When I/O completes, the OS fills in PTE, marks it present, and restarts faulting process Dirty vs. clean pages Only dirty pages need to be written to disk Clean pages do not – but you need to know where on disk to read them from again

Demand Paging – process From the process perspective: Demand paging is also used when it first starts up When a process is created, it has A brand new page table with all valid bits off No pages in memory When the process starts executing Instructions fault on code and data pages Faulting stops when necessary code/data pages are in memory Only code and data needed by a process needs to be loaded, which will change over time … When the process terminates All related pages reclaimed back to OS

Physica l Memory Layout Virtual Heap (pages 4096 and beyond) (8M-4G) Backing stores (pages ) (8M) Free Frames (pages ) (4M) Kernel Memory (pages ) Kernel Memory, HOLE (pages ) Kernel Memory (pages ) Xinu text, data, bss (pages )

Backing Stores There are 16 backing stores in total: APIs: get_bs/release_bs, read_bs/write_bs Emulated by physical memory Skeleton already given You may want to add some sanity check!

Other Issues The NULL process No private heap Global page table entries The entire 16M physical memory Identity mapping Page fault ISR paging/pfintr.S, paging/pfint.c Support data structures Inverted page table Help functions E.g., finding a backing store from a virtual address

Intel System Programming Outer Page Table (Page Directory) = 1024 page directory entries in a page directory Page Table = 1024 page table entries in a page table Page - 4-KB PDBR = Page Directory Base Register (CR3): points to the start address of Page Directory (Outer Page Table) TLB - lookup in page tables in memory are performed only when the TLBs do not contain the translation information for a requested page. invalidate - automatically invalidated any time the CR3 register is loaded.

From Boot 1.Initialize (zero out the values) backing store - (create data structures) frames - (create data structures) install page fault handler 2.Create new page table for null process: create page directory (outer page table) initialize 1:1 mapping for the first 4096 pages allocate 4 page tables (4x1024 pages) assign each page table entry to the address starting from page number 0 to 1023 these page tables should be shared between processes

From Boot Enable paging set bit 31st of the CR0 register take care that PDBR is set, because subsequent memory address access will be virtual memory addresses 4.Creating new process (e.g., main): create page directory (same as with null process) share the first 4096 pages with null process 5.Context switch every process has separate page directory before ctxsw() load CR3 with the process's PDBR

Using Virtual Memory 1.Allocate pages in backing store 2.Map it to virtual page using xmmap() for example if you do xmmap(A, backingstore, 10) then the mapping would be made to consecutive locations in backingstore for virtual pages: A, A+1, A+2,..., A+9 3.Then try accessing the virtual address 4.If the page is not present a Page Fault is generated

Page Fault 1.Address that caused page fault content of CR2 register 2.Search for the page table entry. Two cases: a). second level page table does not exist b). second level page table exists but the page table entry does not exist How do we know? Use the P flag for page directory/table entry

Page Fault - 2 Case a) allocate a frame -> initialize (zero out the page table frame) update the page directory entry with base address of the page table frame Now this case becomes Case (b)

Page Fault - 3 Case b) Locate backing store id of the faulted page, the page number in the backing store. Find a free frame to store the page from backing store if found: use the free frame if not found: evict a page frame (Page Replacement Algorithm) Update the page table entry for the page and possibly for evicted page frame

Using Virtual Memory 1.Allocate pages in backing store 2.Map it to virtual page using xmmap() for example if you do xmmap(A, backingstore, 10) then the mapping would be made to consecutive locations in backingstore for virtual pages: A, A+1, A+2,..., A+9 3.Then try accessing the virtual address 4.If the page is not present a Page Fault is generated 5.Finally: Flush TLB content, by reloading CR3 with page directory address

Virtual address has page table offset as well as page directory offset. PageTableNumber(31-22) PageNumber(21-12) Offset(11-0) Page Directory/Table Entry Format PFA page frame address Avail available to OS 8 0 must be 0 7 L PTE -- Must be 0. Dir Entry -- 4MB page 6 D dirty (PTE only -- documented as undefined in directory entry) 5 A accessed 4 PCD page cache disable (can't cache data on this page) 3 PWT page write transparent (tell external cache to use write-through strategy for this page) 2 U user accessible 1 W writeable 0 P present