CS 4284 Systems Capstone Godmar Back Virtual Memory – Paging Techniques.

Slides:



Advertisements
Similar presentations
CS 140 Project 3 Virtual Memory
Advertisements

Virtual Memory Management G. Anuradha Ref:- Galvin.
1 Pintos Project #3 Virtual Memory The following slides were created by Xiaomo Liu and others for CS 3204 Fall And Modified by Nick Ryan for Spring.
CS 4284 Systems Capstone Godmar Back Linking and Loading.
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.
CS 153 Design of Operating Systems Spring 2015
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory.
Jaishankar Sundararaman
1 Operating Systems and Protection CS Goals of Today’s Lecture How multiple programs can run at once  Processes  Context switching  Process.
CS 104 Introduction to Computer Science and Graphics Problems
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
CS 3204 Operating Systems Godmar Back Lecture 11.
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
CS 4284 Systems Capstone Godmar Back Virtual Memory – Page Tables.
Operating Systems ECE344 Ding Yuan Paging Lecture 8: Paging.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources.
CS 3204 Operating Systems Godmar Back Lecture 15.
CS 4284 Systems Capstone Godmar Back Virtual Memory – Paging Techniques.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 9: Virtual Memory.
Lecture 11 Page 1 CS 111 Online Working Sets Give each running process an allocation of page frames matched to its needs How do we know what its needs.
Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Lecture Topics: 11/24 Sharing Pages Demand Paging (and alternative) Page Replacement –optimal algorithm –implementable algorithms.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Demand Paging.
Processes and Virtual Memory
CS 3204 Operating Systems Godmar Back Lecture 17.
CS2100 Computer Organisation Virtual Memory – Own reading only (AY2015/6) Semester 1.
CS 390 Unix Programming Environment
1 Pintos Virtual Memory Management Project (CS3204 Spring 2006 VT) Yi Ma.
Virtual Memory Ch. 8 & 9 Silberschatz Operating Systems Book.
Pintos project 3: Virtual Memory Management
CS 3204 Operating Systems Godmar Back Lecture 16.
Introduction Contain two or more CPU share common memory and peripherals. Provide greater system throughput. Multiple processor executing simultaneous.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
COS 318: Operating Systems Virtual Memory Design Issues.
Virtual Memory 1 Computer Organization II © McQuain Virtual Memory Use main memory as a “cache” for secondary (disk) storage – Managed jointly.
1 Contents Memory types & memory hierarchy Virtual memory (VM) Page replacement algorithms in case of VM.
Virtual Memory – Paging Techniques
Virtual Memory.
CS161 – Design and Architecture of Computer
Virtual Memory CSSE 332 Operating Systems
CS161 – Design and Architecture of Computer
Chapter 9: Virtual Memory – Part I
CS703 - Advanced Operating Systems
Paging COMP 755.
Chapter 9: Virtual Memory
Virtual Memory – Page Tables
Swapping Segmented paging allows us to have non-contiguous allocations
CS 5204 Operating Systems Linking and Loading Godmar Back.
CSE 120 Principles of Operating
CSE 153 Design of Operating Systems Winter 2018
CSE 153 Design of Operating Systems Winter 2018
Chapter 9: Virtual-Memory Management
Page Replacement.
CS 4284 Systems Capstone Linking and Loading Godmar Back.
Module IV Memory Organization.
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
CSE 451: Operating Systems Autumn 2005 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Contents Memory types & memory hierarchy Virtual memory (VM)
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 153 Design of Operating Systems Winter 2019
CSE 451: Operating Systems Lecture 10 Paging & TLBs
CSE 153 Design of Operating Systems Winter 2019
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.
CSE 542: Operating Systems
Presentation transcript:

CS 4284 Systems Capstone Godmar Back Virtual Memory – Paging Techniques

CS 4284 Spring 2013 Demand paging Idea: only keep data in memory that’s being used –Needed for virtualization – don’t use up physical memory for data processes don’t access Requires that actual allocation of physical page frames be delayed until first access Many variations –Lazy loading of text & data, mmapped pages & newly allocated heap pages –Copy-on-write

CS 4284 Spring 2013 ustack (1) Lazy Loading kernel ucode (1) kcode kdata kbss kheap 0 C C FFFFFFFF 3 GB 1 GB used free user (1) udata (1) user (1) Pintos loads the first process … P1 Pintos then starts the first process … Process faults because code page is not present … Process faults when touching address in data segment … stack page was allocated eagerly data + code pages are noted in page table, but no physical frame has been allocated

CS 4284 Spring 2013 ustack (2) ustack (1) Stack Growth kernel ucode (1) kcode kdata kbss kheap 0 C C FFFFFFFF 3 GB 1 GB used free user (1) udata (1) user (1) Pintos loads the first process … P1 Pintos then starts the first process … Process faults because code page is not present … Process calls recursive function or allocates large local variable page fault at about here

CS 4284 Spring 2013 Microscopic View of Stack Growth push $ebp sub $20, $esp push $eax push $ebx push $ebp sub $20, $esp push $eax push $ebx 0x8000 esp = 0x8004 esp = 0x8000 esp = 0x7FEC esp = 0x7FE8 intr0e_stub: … call page_fault() … iret intr0e_stub: … call page_fault() … iret Page Fault! void page_fault() { get fault addr determine if it’s close to user $esp Yes: allocate page frame install page in page table No: terminate process } esp = 0x7FE4 Can resume after page fault (and unless f  eip is changed) this will retry the faulting instruction (here: push $eax) –MMU will walk hardware page table again

CS 4284 Spring 2013 Fault Resumption Requires that faulting CPU instruction be restartable –Most CPUs are designed this way Very powerful technique –Entirely transparent to user program: user program is frozen in time until OS decides what to do Can be used to emulate lots of things –Programs that just ignore segmentation violations (!?) (here: resume with next instruction – retrying would fault again) –Subpage protection (protect entire page, take fault on access, check if address was to an valid subpage region) –Virtual machines (original IBM/360 design was fully virtualizable; vmware, qemu – run entire OS on top of another OS) –Garbage collection (detect how recently objects have been accessed) –Distributed Shared Memory

CS 4284 Spring 2013 Distributed Shared Memory Idea: allows accessing other machine’s memory as if it were local Augment page table to be able to keep track of network locations: –local virtual address  (remote machine, remote address) On page fault, send request for data to owning machine, receive data, allocate & write to local page, map local page, and resume –Process will be able to just use pointers to access all memory distributed across machines – fully transparent Q.: how do you guarantee consistency? –Lots of options

CS 4284 Spring 2013 ustack (1) Heap Growth kernel ucode (1) kcode kdata kbss kheap 0 C C FFFFFFFF 3 GB 1 GB used free user (1) udata (1) user (1) Pintos loads the first process … P1 Pintos then starts the first process … Process faults because code page is not present … Process needs memory to place malloc() objects in Process calls sbrk(addr) udata (2) Process faults when touching new memory

CS 4284 Spring 2013 ustack (1) mmap() kernel ucode (1) kcode kdata kbss kheap 0 C C FFFFFFFF 3 GB 1 GB used free user (1) udata (1) user (1) Pintos loads the first process … P1 Pintos then starts the first process … Process faults because code page is not present … Process opens file, calls mmap(fd, addr) ummap (1) Process faults when touching mapped file Page fault handler allocs page, maps it, reads data from disk:

CS 4284 Spring 2013 Copy-On-Write Sometimes, want to create a copy of a page: –Example: Unix fork() creates copies of all parent’s pages in the child Optimization: –Don’t copy pages, copy PTEs – now have 2 PTEs pointing to frame –Set all PTEs read-only –Read accesses succeed –On Write access, copy the page into new frame, update PTEs to point to new & old frame Looks like each have their own copy, but postpone actual copying until one is writing the data –Hope is at most one will ever touch the data – never have to make actual copy

CS 4284 Spring 2013 Lazy Loading & Prefetching Typically want to do some prefetching when faulting in page –Reduces latency on subsequent faults Q.: how many pages? which pages? –Too much: waste time & space fetching unused pages –Too little: pay (relatively large) page fault latency too often Predict which pages the program will access next (how?) Let applications give hints to OS –If applications knows –Example: madvise(2) –Usual conflict: what’s best for application vs what’s best for system as a whole

CS 4284 Spring 2013 Page Eviction Suppose page fault occurs, but no free physical frame is there to allocate Must evict frame –Find victim frame (how – later) –Find & change old page table entry pointing to the victim frame –If data in it isn’t already somewhere on disk, write to special area on disk (“swap space”) –Install in new page table entry –Resume Requires check on page fault if page has been swapped out – fault in if so Some subtleties with locking: –How do you prevent a process from writing to a page some other process has chosen to evict from its frame? –What do you do if a process faults on a page that another process is in the middle of paging out?

CS 4284 Spring 2013 Page Eviction Example victim frame: phys addr = … PTE: process id = ? (if appl.), virtual addr = ?, dirty bit = ?, accessed bit = ?, Process A needs a frame decides it wants this frame Q.: how will it find the PTE, if any, that points to it? Linux uses a so-called “rmap” for that that links frames to PTE

CS 4284 Spring 2013 Managing Swap Space Continuous region on disk –Preferably on separate disk, but typically a partition on same disk Different allocation strategies are possible –Simplest: when page must be evicted, allocate swap space for page; deallocate when page is paged back in –Or: allocate swap space upfront –Should page’s position in swap space change? What if same page is paged out multiple times? Can be managed via bitmap –Free/used bits for each page that can be stored –Pintos: note 1 page == 8 sectors

CS 4284 Spring 2013 Locking Frames Aka “pinned” or “wired” pages or frames If another device outside the CPU (e.g., DMA by network controller) accesses a frame, it cannot be paged out –Device driver must tell VM subsystem about this Also useful if you want to avoid a page fault while kernel code is accessing a user address, such as during a system call.

Accessing User Pointers & Paging Kernel must check that user pointers are valid –P2: easy, just check range & page table Harder when swapping: –validity of a pointer may change between check & access (if another process sneaks in and selects frame mapped to an already checked page for eviction) Possible solution: –verify & lock, then access, then unlock (Alternative is to handle page faults on user addresses in kernel mode) CS 4284 Spring 2013 if (verify_user(addr)) process_terminate(); // what if addr’s frame is just now // swapped out by another process? *addr = value;