Tutorial 8 March 9, 2012 TA: Europa Shang

Slides:



Advertisements
Similar presentations
Project 5: Virtual Memory
Advertisements

Chapter 3 Memory Management
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
CS4432: Database Systems II Buffer Manager 1. 2 Covered in week 1.
CSCC69: Operating Systems
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
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.
CSCC69: Operating Systems Tutorial 7 Some slides are borrowed from CSCC69 offered in winter 2012.
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
Virtual Memory Introduction to Operating Systems: Module 9.
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 34: Chapter 5 Today’s topic –Virtual Memories 1.
Jaishankar Sundararaman
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
Memory Management (II)
Memory Management and Paging CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Translation Buffers (TLB’s)
Virtual Memory Management B.Ramamurthy. Paging (2) The relation between virtual addresses and physical memory addres- ses given by page table.
1 Virtual Memory Management B.Ramamurthy Chapter 10.
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
Operating Systems Chapter 8
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
Operating Systems ECE344 Ding Yuan Paging Lecture 8: Paging.
1 Memory Management 4.1 Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms 4.5 Modeling page replacement algorithms.
Virtual Memory Expanding Memory Multiple Concurrent Processes.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory.
Memory Management Fundamentals Virtual Memory. Outline Introduction Motivation for virtual memory Paging – general concepts –Principle of locality, demand.
Virtual Memory 1 Chapter 13. Virtual Memory Introduction Demand Paging Hardware Requirements 4.3 BSD Virtual Memory 4.3 BSD Memory Management Operations.
Fundamentals of Programming Languages-II Subject Code: Teaching SchemeExamination Scheme Theory: 1 Hr./WeekOnline Examination: 50 Marks Practical:
Virtual Memory 1 1.
CPS110: Page replacement Landon Cox. Replacement  Think of physical memory as a cache  What happens on a cache miss?  Page fault  Must decide what.
Review °Apply Principle of Locality Recursively °Manage memory to disk? Treat as cache Included protection as bonus, now critical Use Page Table of mappings.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 9: Virtual-Memory Management.
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
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Implementation.
CS2100 Computer Organisation Virtual Memory – Own reading only (AY2015/6) Semester 1.
Virtual Memory Ch. 8 & 9 Silberschatz Operating Systems Book.
Pintos project 3: Virtual Memory Management
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
10.1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples.
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.
Chapter 9: Virtual Memory
Translation Lookaside Buffer
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Lecture 11 Virtual Memory
Memory Hierarchy Ideal memory is fast, large, and inexpensive
Virtual Memory Chapter 7.4.
Virtual Memory User memory model so far:
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.
Chapter 9: Virtual Memory
Chapter 9: Virtual-Memory Management
Translation Lookaside Buffer
Translation Buffers (TLB’s)
Contents Memory types & memory hierarchy Virtual memory (VM)
CSE451 Virtual Memory Paging Autumn 2002
Translation Buffers (TLB’s)
Computer Architecture
Paging and Segmentation
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.
CSE 542: Operating Systems
Virtual Memory 1 1.
Module IV Memory Organization.
Presentation transcript:

Tutorial 8 March 9, 2012 TA: Europa Shang CSC369: Operating System Tutorial 8 March 9, 2012 TA: Europa Shang

Assignment 3 Implement paging by writing the following functions: lpage_fault: handles a page fault lpage_evit: evicts an logical page from physical memory page_replace: implements the page replacement policy Sequential Replacement: FIFO Second Chance Replacement: Clock No code reading questions

Virtual Memory Processes need more logical address space than physically available Need to manage what is in memory Swap pages on request When a page is requested but not in memory? Page fault When there is no more space in main memory to bring in pages? Replace and evict

MIPS TLB TLB keeps track of mapping from virtual to physical pages On memory read/write, check the entries in the TLB in parallel (associative lookup): Entry is found: TLB hit Entry not found: TLB miss Causes EX_TLBL for loads: reads Causes EX_TLBS for stores: writes Protection fault: trying to write to read-only memory causes EX_MOD (modify) TLB Exceptions mips_trap calls vm_fault for any TLB exception Different types of VM_FAULT_* are passed on Eventually gets to lpage_fault

LPAGE The lpage entry maps the virtual address to the address in physical memory and in swap space On creation, Request a block of swap space Set physical address to INVALID Update swap pointer The lpage structure keeps track of where the page stores In physical memory : lp_paddr On disk: lp_swapaddr Low bits of lp_addr used to hold flags, e.g. DIRTY, PINNED Read comments in src/kern/include/vmprivate.h

LPAGE Operations lpage_create: creates an logical page object lpage_destroy: deallocates a logical page, releases any RAM or swap pages involved lpage_lock: acquires the lock on an lpage lpage_unlock: releases the lock on an lpage lpage_lock_and_pin: locks the lpage page and pins the underlying physical page in the coremap. lpage_copy: creates a new lpage and copy data from another lpage lpage_zerofill: creates a new lpage and arrange for it to be cleared to all zeros lpage_fault: handles a fault on a specific lpage lpage_evict: evicts an lpage from physical memory

VM_OBJECT A vm_object is a data structure that defines a a valid block of process virtual memory Defiend in src/kern/include/vmprivate.h Created by as_define_region Each vm_object contains a base virtual address and an array of logical pages The address space is a collection of vm_objects Redzone: a possible guard band against other vm_objects Simple operations: create, destroy, copy, etc. lpage and vm_object From virtual address, can the corresponding vm_object In the vm_object, can find the index of the corresponding lpage structure

Coremap Logical pages are nice, but we ultimately need to work with physical memory Need to keep track of physical pages Coremap maps pages in memory to their virtual address. Reverse page table One entry per page frame Indexed by physical page number Contain the virtual page number of address space that is occupying the page frame.

Coremap TLB management and handling Page replacement policy Keep track of the number of Maximum number of physical pages Number of kernel pages Number of user pages Number of pages that are free Maintain information whether a page has been pinned for manipulation

COREMAP_ENTRY struct coremap_entry { struct lpage *cm_lpage; volatile int cm_tlbix:7; unsigned cm_cpunum:5; unsigned cm_kernel:1, cm_notlast:1, cm_allocated:1; unsigned cm_pinned:1; }; A coremap entry has bit flags that indicate if pages are kernel pages, pinned (busy), etc. May add other flags to support your design

COREMAP_ENTRY v.s. LPAGE Each lpage is a logical piece of memory The memory may be in memory or in swap (on disk) A lpage points to the location of its data The coremap maps the physical memory storage When you need physical memory, consult the coremap to see what memory is free. A coremap entry points to a lpage

COREMAP Operations tlb_replace: returns index of TLB entry to replace TLB replacement algorithm. tlb_invalidate: marks a given TLB entry as invalid tlb_clear: flushes the TLB by loading it with invalid entries tlb_unmap: searches the TLB for a specific virtual address translation and invalidates it if it exits mips_getslot: gets a TLB slot for use, replacing an existing one if necessary and performing any at- replacement actions page_replace: returns an index into the coremap for the selected victim page

COREMAP Operations coremap_bootstrap: allocates memory for the coremap and initlaizes its entries do_evict: performs the eviction of the specific slot in coremap do_page_replace: starting point for the page replacement code, calls page_replace and do_evict mark_page_allocated: update coremap entries for newly allocated pages and update coremap counters Called from coremap_alloca_one_page and coremap_alloc_multipages coremap_free: deallocates a specific physical address and any subsequent pages allocated in the same block coremap_pin: marks a specific page pinned for manipulation of its contents coremap_unpin: unpins a specific page mmu_map: enters a translation into the MMU.

Page Faults Minor fault: desired page is in memory but not found in TLB Update the TLB and coremap coremap.c : mmu_map Major fault: desired page is not in memory It’s either in swap space, or hasn’t been created yet How do you know if it’s a major fault? lp_paddr is INVALID_PADDR if the page is not in memory Page hasn’t been created yet A new page is allocated to the process and initialized (zero-filled) In src/kern/vm/addrspace.c: as_fault Page is on disk We need to swap the page into memory from swap space

Page Replacement Updating the victim’s PTE to show that it is in swap Evicting/invalidating victim’s PTE from the TLB Copying it to disk iff its dirty Loading the new page into memory Updating the new page’s PTE and inserting it into the TLB

Synchronization OS/161 assumes that lpage, vm_objects and address spaces are not shared But one thread may access an lpage belonging to another thread, in order to evict a page Don’t need locks when accessing address space and vm_objects, but lpages do need synchronization Bit lock is used to save space: lpage_lock, lpage_unlock Locks for the Virtual Memory system global_paging_lock: limits number of pages pinned at any one time swaplock: synchronizes swapmap and counters Used by swap_alloc, swap_free, swap_reserve, swap_unreserve cm_pinned: locks pages that are being used One bit lock per lpage Lock ordering, i.e., you should acquire in this order global_paging_lock BEFORE coremap pages BEFORE lpages

PAGE_REPLACE page_replace takes no arguments and returns an index into the coremap for the selected victim page. You will write two versions of this function. Sequential Page Replacement Clock Page Replacement Configuration ASST3-FIFO ASST3-CLOCK

PAGE_REPLACE: FIFO Sequential Page Replacement Tips Select page to be evicted from the coremap sequentially. Skip pinned pages and kernel pages Tips Map need a global variable for the head of the queue

PAGE_REPLACE: LRU Clock Page Replacement Tips Scans pages in coremap sequentially. Skip pinned pages, kernel pages, and pages with the reference bit set. Turn off the reference bit if a page is skipped because the reference bit was 1. Tips May need a bit field in coremap_entry for the reference bit May need a global variable for the clock hand May need to modify several functions for the reference bit

LPAGE_FAULT and LPAGE_EVICT lpage_fault: handles a fault on a specific lpage. If a page is resident in memory, get a physical page from coremap and swap it in. lpage_evict: evicts an lpage from physical memory to swap space Action: Evict the contents of the page at lp_paddr by writing it to lp_swapaddr on the swap device (if it is dirty), and mark lp_paddr as invalid Called by do_evict when a physical page is chosen for eviction Synchronization Stats counters should be updated under global lock protection Read the comments in the code