SlideShare a Scribd company logo
1 of 36
Download to read offline
Operating Systems
          CMPSCI 377
        Virtual Memory
                   Emery Berger
University of Massachusetts Amherst




UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
Virtual Memory
    Virtual, not physical memory


        Divided into pages
    

              Page tables, TLB
          


        Provides isolation, protection, optimization
    

    Managed using eviction policies





        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   2
Demand-Paged Virtual Memory
    Key idea: use RAM as cache for disk


        OS transparently moves pages
    

    Requires locality:


        Working set (memory referenced recently)
    

        must fit in RAM
        If not: thrashing (nothing but disk traffic)
    




        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   3
Virtual Memory Pages

    Memory divided into


    fixed-sized pages (e.g.,
    4K, 8K)
        Allocates pages to frames
    
                                                                               A
        in memory
        OS manages pages
    

              Moves, removes,
          

              reallocates
        Copied to and from disk
    




        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science       4
Demand-Paging Diagram




  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   5
Paging + Locality

    Most programs obey

    90/10 “rule”                                              A
        90% of time spent
    

        accessing 10% of                                                       A
                                                                               B
        memory
                                                              B
    Exploit this rule:


        Only keep “live” parts
    

        of process in memory


        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science       6
Virtual Memory

    Processes use virtual addresses


        Addresses start at 0
    

        OS lays process down on pages
    

    MMU (memory-management unit):


        Hardware support for paging
    

        Translates virtual to physical addresses
    

        Uses page table to keep track of frame
    

        assigned to memory page


        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   7
Mapping Virtual to Physical




   UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   8
Address Translation

    Powers of 2:


        Virtual address space:
    

        size 2m
        Page size 2n
    

    High-order m-n bits


    of virtual address
    select page
    Low order n bits


    select offset in page


        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   9
Paging Hardware: Diagram




   UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   10
Translation Lookaside Buffer (TLB)
    TLB: fast, fully associative memory


        Caches page table entries
    

        Stores page numbers (key) and frame (value)
    

        in which they are stored
    Assumption: locality of reference


        Locality in memory accesses =
    

        locality in address translation
    TLB sizes: 8 to 2048 entries


        Powers of 2 simplifies translation
    

        of virtual to physical addresses
        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   11
TLB Action




   UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   12
TLB: Diagram




    v = valid bit: entry is up-to-date

      UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   13
Cost of Using TLB
    Measure in terms of memory access cost




    What is cost if:


        Page table is in memory?
    

        Page table managed with TLB?
    




    Large TLB:


        Improves hit ratio
    

        Decreases average memory cost
    




        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   14
Sharing
    Paging allows sharing of memory across

    processes
        Different virtual addresses,
    
        point to same physical address
    Shared stuff includes code, data


        Compiler marks “text” segment (i.e., code) of
    
        applications (e.g., emacs) - read-only
        OS: keeps track of such segments
    

              Reuses if another instance of app arrives
          


        Copy-on-write
    

    Can greatly reduce memory requirements


        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   15
Key Policy Decisions
    Two key questions: (for any cache):


        When do we read page from disk?
    

        When do we write page to disk?
    




        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   16
Reading Pages
    Read on-demand:


        OS loads page on its first reference
    

        May force an eviction of page in RAM
    

        Pause while loading page = page fault
    

    Can also perform pre-paging:


        OS guesses which page will next be needed,
    
        and begins loading it
    Most systems just do demand paging





        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   17
Demand Paging
    On every reference, check if page is in


    memory (valid bit in page table)
    If not: trap to OS


    OS checks address validity, and


        Selects victim page to be replaced
    

        Invalidates old page
    

        Begins loading new page from disk
    

        Switches to other process
    

        (paging = implicit I/O)
    Note: must restart instruction later



        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   18
Swap Space


    Swap space = where victim pages go


        Partition or special file reserved on disk
    

              Sometimes: special filesystem (“tmpfs”)
          


        What kind of victim pages can be evicted
    

        without going to swap?

    Size of reserved swap space limits what?





        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   19
Swap Space


    Swap space = where victim pages go


        Partition or special file reserved on disk
    

              Sometimes: special filesystem (“tmpfs”)
          


        What kind of victim pages can be evicted
    

        without going to swap?
              Read-only (“text”), untouched anonymous pages
          


    Size of reserved swap space limits what?





        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   20
Swap Space
    Swap space = where victim pages go


        Partition or special file reserved on disk
    

              Sometimes: special filesystem (“tmpfs”)
          


        Only read-only or undirtied victim pages can
    

        be evicted without going to swap
              “text” (code), untouched anonymous pages
          


    Size of reserved swap space limits


    total virtual memory



        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   21
Cost of Paging
    Worst-case analysis – useless


        Easy to construct adversary example:
    

        every page requires page fault




                               A, B, C, D, E, F, G, H, I, J, A...


                           size of available memory




        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   22
Page Replacement Algorithms
    MIN, OPT (optimal)


    RANDOM


        evict random page
    

    FIFO (first-in, first-out)


        give every page equal residency
    

    LRU (least-recently used)


    MRU (most-recently used)





        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   23
MIN/OPT
    Invented by Belady (“MIN”)


    Now known as “OPT”: optimal page

    replacement
        Evict page to be accessed furthest in the
    

        future
    Provably optimal policy


        Just one small problem...
    

        requires predicting the future
        Still useful point of comparison
    




        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   24
MIN/OPT example




    Page faults: 5




      UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   25
RANDOM
    Evict any page


    Works surprisingly well – why?


    Theoretically: very good,


    but not used in practice:
    takes no advantage of locality




      UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   26
LRU
    Evict page that has not been used in


    longest time (least-recently used)
        Approximation of MIN if recent past is good
    

        predictor of future
        Variant of LRU used in all real operating
    

        systems




        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   27
LRU example




    Page faults: ?




      UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   28
LRU example




    Page faults: 5




      UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   29
LRU, example II




    Page faults: ?




      UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   30
LRU, example II




    Page faults: 12!




      UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   31
FIFO
    First-in, first-out: evict oldest page


        Also has competitive ratio k
    

    But: performs miserably in practice!


        LRU takes advantage of locality
    

        FIFO does not
    

    Suffers from Belady’s anomaly:


        More memory can mean more paging!
    

        LRU & other “stack” algs. do not
    




        UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   32
FIFO & Belady’s Anomaly




   UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   33
MRU


    Evict most-recently used page


    Shines for LRU’s worst-case: loop that

    exceeds RAM size

                             A, B, C, D, A, B, C, D, ...


                         size of available memory

    What we really want: adaptive algorithms

    (e.g., EELRU – Kaplan & Smaragdakis)
      UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   34
The End




   UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   35
LRU: No Belady’s Anomaly




    Why no anomaly for LRU?




     UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science   36

More Related Content

What's hot

Virtual Memory Management
Virtual Memory ManagementVirtual Memory Management
Virtual Memory Managementprimeteacher32
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual Memoryvampugani
 
40 demand paging
40 demand paging40 demand paging
40 demand pagingmyrajendra
 
Virtual memory pre-final-formatting
Virtual memory pre-final-formattingVirtual memory pre-final-formatting
Virtual memory pre-final-formattingmarangburu42
 
Virtual Memory ,Direct memory addressing and indirect memory addressing prese...
Virtual Memory ,Direct memory addressing and indirect memory addressing prese...Virtual Memory ,Direct memory addressing and indirect memory addressing prese...
Virtual Memory ,Direct memory addressing and indirect memory addressing prese...ITM University
 
Processes and Threads
Processes and ThreadsProcesses and Threads
Processes and ThreadsEmery Berger
 
Chapter 9 - Virtual Memory
Chapter 9 - Virtual MemoryChapter 9 - Virtual Memory
Chapter 9 - Virtual MemoryWayne Jones Jnr
 
Presentation on Virtual Memory concepts in computer
Presentation on Virtual Memory concepts in computer Presentation on Virtual Memory concepts in computer
Presentation on Virtual Memory concepts in computer Oshin Kandpal
 
Unit 2chapter 2 memory mgmt complete
Unit 2chapter 2  memory mgmt completeUnit 2chapter 2  memory mgmt complete
Unit 2chapter 2 memory mgmt completeKalai Selvi
 
Operating Systems - Virtual Memory
Operating Systems - Virtual MemoryOperating Systems - Virtual Memory
Operating Systems - Virtual MemoryDamian T. Gordon
 

What's hot (20)

Virtual Memory Management
Virtual Memory ManagementVirtual Memory Management
Virtual Memory Management
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual Memory
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Ch09
Ch09Ch09
Ch09
 
Demand paging
Demand pagingDemand paging
Demand paging
 
40 demand paging
40 demand paging40 demand paging
40 demand paging
 
Virtual memory pre-final-formatting
Virtual memory pre-final-formattingVirtual memory pre-final-formatting
Virtual memory pre-final-formatting
 
virtual memory
virtual memoryvirtual memory
virtual memory
 
OSCh10
OSCh10OSCh10
OSCh10
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Virtual Memory ,Direct memory addressing and indirect memory addressing prese...
Virtual Memory ,Direct memory addressing and indirect memory addressing prese...Virtual Memory ,Direct memory addressing and indirect memory addressing prese...
Virtual Memory ,Direct memory addressing and indirect memory addressing prese...
 
Processes and Threads
Processes and ThreadsProcesses and Threads
Processes and Threads
 
Chapter 9 - Virtual Memory
Chapter 9 - Virtual MemoryChapter 9 - Virtual Memory
Chapter 9 - Virtual Memory
 
Presentation on Virtual Memory concepts in computer
Presentation on Virtual Memory concepts in computer Presentation on Virtual Memory concepts in computer
Presentation on Virtual Memory concepts in computer
 
Mem mgt
Mem mgtMem mgt
Mem mgt
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual Memory
 
Unit 2chapter 2 memory mgmt complete
Unit 2chapter 2  memory mgmt completeUnit 2chapter 2  memory mgmt complete
Unit 2chapter 2 memory mgmt complete
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual Memory
 
Operating Systems - Virtual Memory
Operating Systems - Virtual MemoryOperating Systems - Virtual Memory
Operating Systems - Virtual Memory
 
virtual memory
virtual memoryvirtual memory
virtual memory
 

Viewers also liked

Virtual memory
Virtual memoryVirtual memory
Virtual memoryAnuj Modi
 
Os Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memorysgpraju
 
Paging and Segmentation in Operating System
Paging and Segmentation in Operating SystemPaging and Segmentation in Operating System
Paging and Segmentation in Operating SystemRaj Mohan
 
Virtual memory
Virtual memoryVirtual memory
Virtual memoryvatsaanadi
 
Virtual memory managment
Virtual memory managmentVirtual memory managment
Virtual memory managmentSantu Kumar
 
Operating System-Memory Management
Operating System-Memory ManagementOperating System-Memory Management
Operating System-Memory ManagementAkmal Cikmat
 
Operating Systems and Memory Management
Operating Systems and Memory ManagementOperating Systems and Memory Management
Operating Systems and Memory Managementguest1415ae65
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual MemoryArchith777
 
Virtual memory
Virtual memoryVirtual memory
Virtual memoryMohd Arif
 
Segmentation in Operating Systems.
Segmentation in Operating Systems.Segmentation in Operating Systems.
Segmentation in Operating Systems.Muhammad SiRaj Munir
 
Implementation of page table
Implementation of page tableImplementation of page table
Implementation of page tableguestff64339
 
Operating Systems: Virtual Memory
Operating Systems: Virtual MemoryOperating Systems: Virtual Memory
Operating Systems: Virtual MemoryDamian T. Gordon
 
Virtual Memory - Part1
Virtual Memory - Part1Virtual Memory - Part1
Virtual Memory - Part1Amir Payberah
 
Virtual Memory - Part2
Virtual Memory - Part2Virtual Memory - Part2
Virtual Memory - Part2Amir Payberah
 

Viewers also liked (20)

Virtual memory ppt
Virtual memory pptVirtual memory ppt
Virtual memory ppt
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
VIRTUAL MEMORY
VIRTUAL MEMORYVIRTUAL MEMORY
VIRTUAL MEMORY
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Os Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memory
 
Paging and Segmentation in Operating System
Paging and Segmentation in Operating SystemPaging and Segmentation in Operating System
Paging and Segmentation in Operating System
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Virtual memory managment
Virtual memory managmentVirtual memory managment
Virtual memory managment
 
Operating System-Memory Management
Operating System-Memory ManagementOperating System-Memory Management
Operating System-Memory Management
 
Operating Systems and Memory Management
Operating Systems and Memory ManagementOperating Systems and Memory Management
Operating Systems and Memory Management
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual Memory
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Vm
VmVm
Vm
 
Segmentation in Operating Systems.
Segmentation in Operating Systems.Segmentation in Operating Systems.
Segmentation in Operating Systems.
 
Implementation of page table
Implementation of page tableImplementation of page table
Implementation of page table
 
Operating Systems: Virtual Memory
Operating Systems: Virtual MemoryOperating Systems: Virtual Memory
Operating Systems: Virtual Memory
 
Virtual Memory - Part1
Virtual Memory - Part1Virtual Memory - Part1
Virtual Memory - Part1
 
Virtual Memory - Part2
Virtual Memory - Part2Virtual Memory - Part2
Virtual Memory - Part2
 
Memory management
Memory managementMemory management
Memory management
 

Similar to Operating Systems - Virtual Memory

Operating Systems - Architecture
Operating Systems - ArchitectureOperating Systems - Architecture
Operating Systems - ArchitectureEmery Berger
 
Operating Systems - Introduction
Operating Systems - IntroductionOperating Systems - Introduction
Operating Systems - IntroductionEmery Berger
 
Operating Systems - Dynamic Memory Management
Operating Systems - Dynamic Memory ManagementOperating Systems - Dynamic Memory Management
Operating Systems - Dynamic Memory ManagementEmery Berger
 
Operating Systems - Advanced File Systems
Operating Systems - Advanced File SystemsOperating Systems - Advanced File Systems
Operating Systems - Advanced File SystemsEmery Berger
 
LECTURE13nvjlfdihbkzbjvzbfmdnmzbxckbn.ppt
LECTURE13nvjlfdihbkzbjvzbfmdnmzbxckbn.pptLECTURE13nvjlfdihbkzbjvzbfmdnmzbxckbn.ppt
LECTURE13nvjlfdihbkzbjvzbfmdnmzbxckbn.pptNikhilKumarJaiswal2
 
Operating Systems - Intro to C++
Operating Systems - Intro to C++Operating Systems - Intro to C++
Operating Systems - Intro to C++Emery Berger
 
Garbage Collection without Paging
Garbage Collection without PagingGarbage Collection without Paging
Garbage Collection without PagingEmery Berger
 
Operating Systems - Queuing Systems
Operating Systems - Queuing SystemsOperating Systems - Queuing Systems
Operating Systems - Queuing SystemsEmery Berger
 
Memory Management for High-Performance Applications
Memory Management for High-Performance ApplicationsMemory Management for High-Performance Applications
Memory Management for High-Performance ApplicationsEmery Berger
 
Inception Pack Vol 2: Bizarre premium
Inception Pack Vol 2: Bizarre premiumInception Pack Vol 2: Bizarre premium
Inception Pack Vol 2: Bizarre premiumThe Planning Lab
 
Operating Systems - Garbage Collection
Operating Systems - Garbage CollectionOperating Systems - Garbage Collection
Operating Systems - Garbage CollectionEmery Berger
 
How to build a state-of-the-art rails cluster
How to build a state-of-the-art rails clusterHow to build a state-of-the-art rails cluster
How to build a state-of-the-art rails clusterTim Lossen
 
Virtualization for Emerging Memory Devices
Virtualization for Emerging Memory DevicesVirtualization for Emerging Memory Devices
Virtualization for Emerging Memory DevicesTakahiro Hirofuchi
 
Lightweight Grids With Terracotta
Lightweight Grids With TerracottaLightweight Grids With Terracotta
Lightweight Grids With TerracottaPT.JUG
 
Virtualmemorypre final-formatting-161019022904
Virtualmemorypre final-formatting-161019022904Virtualmemorypre final-formatting-161019022904
Virtualmemorypre final-formatting-161019022904marangburu42
 
Operating Systems - Concurrency
Operating Systems - ConcurrencyOperating Systems - Concurrency
Operating Systems - ConcurrencyEmery Berger
 

Similar to Operating Systems - Virtual Memory (20)

Operating Systems - Architecture
Operating Systems - ArchitectureOperating Systems - Architecture
Operating Systems - Architecture
 
Operating Systems - Introduction
Operating Systems - IntroductionOperating Systems - Introduction
Operating Systems - Introduction
 
Operating Systems - Dynamic Memory Management
Operating Systems - Dynamic Memory ManagementOperating Systems - Dynamic Memory Management
Operating Systems - Dynamic Memory Management
 
Operating Systems - Advanced File Systems
Operating Systems - Advanced File SystemsOperating Systems - Advanced File Systems
Operating Systems - Advanced File Systems
 
INFLOW-2014-NVM-Compression
INFLOW-2014-NVM-CompressionINFLOW-2014-NVM-Compression
INFLOW-2014-NVM-Compression
 
LECTURE13nvjlfdihbkzbjvzbfmdnmzbxckbn.ppt
LECTURE13nvjlfdihbkzbjvzbfmdnmzbxckbn.pptLECTURE13nvjlfdihbkzbjvzbfmdnmzbxckbn.ppt
LECTURE13nvjlfdihbkzbjvzbfmdnmzbxckbn.ppt
 
Operating Systems - Intro to C++
Operating Systems - Intro to C++Operating Systems - Intro to C++
Operating Systems - Intro to C++
 
Garbage Collection without Paging
Garbage Collection without PagingGarbage Collection without Paging
Garbage Collection without Paging
 
Operating Systems - Queuing Systems
Operating Systems - Queuing SystemsOperating Systems - Queuing Systems
Operating Systems - Queuing Systems
 
Quixote
QuixoteQuixote
Quixote
 
Memory Management for High-Performance Applications
Memory Management for High-Performance ApplicationsMemory Management for High-Performance Applications
Memory Management for High-Performance Applications
 
Inception Pack Vol 2: Bizarre premium
Inception Pack Vol 2: Bizarre premiumInception Pack Vol 2: Bizarre premium
Inception Pack Vol 2: Bizarre premium
 
Operating Systems - Garbage Collection
Operating Systems - Garbage CollectionOperating Systems - Garbage Collection
Operating Systems - Garbage Collection
 
Segmentation and paging
Segmentation and paging Segmentation and paging
Segmentation and paging
 
ch9_virMem.pdf
ch9_virMem.pdfch9_virMem.pdf
ch9_virMem.pdf
 
How to build a state-of-the-art rails cluster
How to build a state-of-the-art rails clusterHow to build a state-of-the-art rails cluster
How to build a state-of-the-art rails cluster
 
Virtualization for Emerging Memory Devices
Virtualization for Emerging Memory DevicesVirtualization for Emerging Memory Devices
Virtualization for Emerging Memory Devices
 
Lightweight Grids With Terracotta
Lightweight Grids With TerracottaLightweight Grids With Terracotta
Lightweight Grids With Terracotta
 
Virtualmemorypre final-formatting-161019022904
Virtualmemorypre final-formatting-161019022904Virtualmemorypre final-formatting-161019022904
Virtualmemorypre final-formatting-161019022904
 
Operating Systems - Concurrency
Operating Systems - ConcurrencyOperating Systems - Concurrency
Operating Systems - Concurrency
 

More from Emery Berger

Doppio: Breaking the Browser Language Barrier
Doppio: Breaking the Browser Language BarrierDoppio: Breaking the Browser Language Barrier
Doppio: Breaking the Browser Language BarrierEmery Berger
 
Dthreads: Efficient Deterministic Multithreading
Dthreads: Efficient Deterministic MultithreadingDthreads: Efficient Deterministic Multithreading
Dthreads: Efficient Deterministic MultithreadingEmery Berger
 
Programming with People
Programming with PeopleProgramming with People
Programming with PeopleEmery Berger
 
Stabilizer: Statistically Sound Performance Evaluation
Stabilizer: Statistically Sound Performance EvaluationStabilizer: Statistically Sound Performance Evaluation
Stabilizer: Statistically Sound Performance EvaluationEmery Berger
 
DieHarder (CCS 2010, WOOT 2011)
DieHarder (CCS 2010, WOOT 2011)DieHarder (CCS 2010, WOOT 2011)
DieHarder (CCS 2010, WOOT 2011)Emery Berger
 
Operating Systems - File Systems
Operating Systems - File SystemsOperating Systems - File Systems
Operating Systems - File SystemsEmery Berger
 
Operating Systems - Networks
Operating Systems - NetworksOperating Systems - Networks
Operating Systems - NetworksEmery Berger
 
Operating Systems - Distributed Parallel Computing
Operating Systems - Distributed Parallel ComputingOperating Systems - Distributed Parallel Computing
Operating Systems - Distributed Parallel ComputingEmery Berger
 
Operating Systems - Advanced Synchronization
Operating Systems - Advanced SynchronizationOperating Systems - Advanced Synchronization
Operating Systems - Advanced SynchronizationEmery Berger
 
Operating Systems - Synchronization
Operating Systems - SynchronizationOperating Systems - Synchronization
Operating Systems - SynchronizationEmery Berger
 
MC2: High-Performance Garbage Collection for Memory-Constrained Environments
MC2: High-Performance Garbage Collection for Memory-Constrained EnvironmentsMC2: High-Performance Garbage Collection for Memory-Constrained Environments
MC2: High-Performance Garbage Collection for Memory-Constrained EnvironmentsEmery Berger
 
Vam: A Locality-Improving Dynamic Memory Allocator
Vam: A Locality-Improving Dynamic Memory AllocatorVam: A Locality-Improving Dynamic Memory Allocator
Vam: A Locality-Improving Dynamic Memory AllocatorEmery Berger
 
Quantifying the Performance of Garbage Collection vs. Explicit Memory Management
Quantifying the Performance of Garbage Collection vs. Explicit Memory ManagementQuantifying the Performance of Garbage Collection vs. Explicit Memory Management
Quantifying the Performance of Garbage Collection vs. Explicit Memory ManagementEmery Berger
 
DieHard: Probabilistic Memory Safety for Unsafe Languages
DieHard: Probabilistic Memory Safety for Unsafe LanguagesDieHard: Probabilistic Memory Safety for Unsafe Languages
DieHard: Probabilistic Memory Safety for Unsafe LanguagesEmery Berger
 
Exterminator: Automatically Correcting Memory Errors with High Probability
Exterminator: Automatically Correcting Memory Errors with High ProbabilityExterminator: Automatically Correcting Memory Errors with High Probability
Exterminator: Automatically Correcting Memory Errors with High ProbabilityEmery Berger
 
Exploiting Multicore CPUs Now: Scalability and Reliability for Off-the-shelf ...
Exploiting Multicore CPUs Now: Scalability and Reliability for Off-the-shelf ...Exploiting Multicore CPUs Now: Scalability and Reliability for Off-the-shelf ...
Exploiting Multicore CPUs Now: Scalability and Reliability for Off-the-shelf ...Emery Berger
 
Composing High-Performance Memory Allocators with Heap Layers
Composing High-Performance Memory Allocators with Heap LayersComposing High-Performance Memory Allocators with Heap Layers
Composing High-Performance Memory Allocators with Heap LayersEmery Berger
 
Reconsidering Custom Memory Allocation
Reconsidering Custom Memory AllocationReconsidering Custom Memory Allocation
Reconsidering Custom Memory AllocationEmery Berger
 
CRAMM: Virtual Memory Support for Garbage-Collected Applications
CRAMM: Virtual Memory Support for Garbage-Collected ApplicationsCRAMM: Virtual Memory Support for Garbage-Collected Applications
CRAMM: Virtual Memory Support for Garbage-Collected ApplicationsEmery Berger
 

More from Emery Berger (19)

Doppio: Breaking the Browser Language Barrier
Doppio: Breaking the Browser Language BarrierDoppio: Breaking the Browser Language Barrier
Doppio: Breaking the Browser Language Barrier
 
Dthreads: Efficient Deterministic Multithreading
Dthreads: Efficient Deterministic MultithreadingDthreads: Efficient Deterministic Multithreading
Dthreads: Efficient Deterministic Multithreading
 
Programming with People
Programming with PeopleProgramming with People
Programming with People
 
Stabilizer: Statistically Sound Performance Evaluation
Stabilizer: Statistically Sound Performance EvaluationStabilizer: Statistically Sound Performance Evaluation
Stabilizer: Statistically Sound Performance Evaluation
 
DieHarder (CCS 2010, WOOT 2011)
DieHarder (CCS 2010, WOOT 2011)DieHarder (CCS 2010, WOOT 2011)
DieHarder (CCS 2010, WOOT 2011)
 
Operating Systems - File Systems
Operating Systems - File SystemsOperating Systems - File Systems
Operating Systems - File Systems
 
Operating Systems - Networks
Operating Systems - NetworksOperating Systems - Networks
Operating Systems - Networks
 
Operating Systems - Distributed Parallel Computing
Operating Systems - Distributed Parallel ComputingOperating Systems - Distributed Parallel Computing
Operating Systems - Distributed Parallel Computing
 
Operating Systems - Advanced Synchronization
Operating Systems - Advanced SynchronizationOperating Systems - Advanced Synchronization
Operating Systems - Advanced Synchronization
 
Operating Systems - Synchronization
Operating Systems - SynchronizationOperating Systems - Synchronization
Operating Systems - Synchronization
 
MC2: High-Performance Garbage Collection for Memory-Constrained Environments
MC2: High-Performance Garbage Collection for Memory-Constrained EnvironmentsMC2: High-Performance Garbage Collection for Memory-Constrained Environments
MC2: High-Performance Garbage Collection for Memory-Constrained Environments
 
Vam: A Locality-Improving Dynamic Memory Allocator
Vam: A Locality-Improving Dynamic Memory AllocatorVam: A Locality-Improving Dynamic Memory Allocator
Vam: A Locality-Improving Dynamic Memory Allocator
 
Quantifying the Performance of Garbage Collection vs. Explicit Memory Management
Quantifying the Performance of Garbage Collection vs. Explicit Memory ManagementQuantifying the Performance of Garbage Collection vs. Explicit Memory Management
Quantifying the Performance of Garbage Collection vs. Explicit Memory Management
 
DieHard: Probabilistic Memory Safety for Unsafe Languages
DieHard: Probabilistic Memory Safety for Unsafe LanguagesDieHard: Probabilistic Memory Safety for Unsafe Languages
DieHard: Probabilistic Memory Safety for Unsafe Languages
 
Exterminator: Automatically Correcting Memory Errors with High Probability
Exterminator: Automatically Correcting Memory Errors with High ProbabilityExterminator: Automatically Correcting Memory Errors with High Probability
Exterminator: Automatically Correcting Memory Errors with High Probability
 
Exploiting Multicore CPUs Now: Scalability and Reliability for Off-the-shelf ...
Exploiting Multicore CPUs Now: Scalability and Reliability for Off-the-shelf ...Exploiting Multicore CPUs Now: Scalability and Reliability for Off-the-shelf ...
Exploiting Multicore CPUs Now: Scalability and Reliability for Off-the-shelf ...
 
Composing High-Performance Memory Allocators with Heap Layers
Composing High-Performance Memory Allocators with Heap LayersComposing High-Performance Memory Allocators with Heap Layers
Composing High-Performance Memory Allocators with Heap Layers
 
Reconsidering Custom Memory Allocation
Reconsidering Custom Memory AllocationReconsidering Custom Memory Allocation
Reconsidering Custom Memory Allocation
 
CRAMM: Virtual Memory Support for Garbage-Collected Applications
CRAMM: Virtual Memory Support for Garbage-Collected ApplicationsCRAMM: Virtual Memory Support for Garbage-Collected Applications
CRAMM: Virtual Memory Support for Garbage-Collected Applications
 

Recently uploaded

unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 

Recently uploaded (20)

unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 

Operating Systems - Virtual Memory

  • 1. Operating Systems CMPSCI 377 Virtual Memory Emery Berger University of Massachusetts Amherst UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
  • 2. Virtual Memory Virtual, not physical memory  Divided into pages  Page tables, TLB  Provides isolation, protection, optimization  Managed using eviction policies  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 2
  • 3. Demand-Paged Virtual Memory Key idea: use RAM as cache for disk  OS transparently moves pages  Requires locality:  Working set (memory referenced recently)  must fit in RAM If not: thrashing (nothing but disk traffic)  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 3
  • 4. Virtual Memory Pages Memory divided into  fixed-sized pages (e.g., 4K, 8K) Allocates pages to frames  A in memory OS manages pages  Moves, removes,  reallocates Copied to and from disk  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 4
  • 5. Demand-Paging Diagram UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 5
  • 6. Paging + Locality Most programs obey  90/10 “rule” A 90% of time spent  accessing 10% of A B memory B Exploit this rule:  Only keep “live” parts  of process in memory UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 6
  • 7. Virtual Memory Processes use virtual addresses  Addresses start at 0  OS lays process down on pages  MMU (memory-management unit):  Hardware support for paging  Translates virtual to physical addresses  Uses page table to keep track of frame  assigned to memory page UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 7
  • 8. Mapping Virtual to Physical UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 8
  • 9. Address Translation Powers of 2:  Virtual address space:  size 2m Page size 2n  High-order m-n bits  of virtual address select page Low order n bits  select offset in page UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 9
  • 10. Paging Hardware: Diagram UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 10
  • 11. Translation Lookaside Buffer (TLB) TLB: fast, fully associative memory  Caches page table entries  Stores page numbers (key) and frame (value)  in which they are stored Assumption: locality of reference  Locality in memory accesses =  locality in address translation TLB sizes: 8 to 2048 entries  Powers of 2 simplifies translation  of virtual to physical addresses UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 11
  • 12. TLB Action UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 12
  • 13. TLB: Diagram v = valid bit: entry is up-to-date  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 13
  • 14. Cost of Using TLB Measure in terms of memory access cost  What is cost if:  Page table is in memory?  Page table managed with TLB?  Large TLB:  Improves hit ratio  Decreases average memory cost  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 14
  • 15. Sharing Paging allows sharing of memory across  processes Different virtual addresses,  point to same physical address Shared stuff includes code, data  Compiler marks “text” segment (i.e., code) of  applications (e.g., emacs) - read-only OS: keeps track of such segments  Reuses if another instance of app arrives  Copy-on-write  Can greatly reduce memory requirements  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 15
  • 16. Key Policy Decisions Two key questions: (for any cache):  When do we read page from disk?  When do we write page to disk?  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 16
  • 17. Reading Pages Read on-demand:  OS loads page on its first reference  May force an eviction of page in RAM  Pause while loading page = page fault  Can also perform pre-paging:  OS guesses which page will next be needed,  and begins loading it Most systems just do demand paging  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 17
  • 18. Demand Paging On every reference, check if page is in  memory (valid bit in page table) If not: trap to OS  OS checks address validity, and  Selects victim page to be replaced  Invalidates old page  Begins loading new page from disk  Switches to other process  (paging = implicit I/O) Note: must restart instruction later  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 18
  • 19. Swap Space Swap space = where victim pages go  Partition or special file reserved on disk  Sometimes: special filesystem (“tmpfs”)  What kind of victim pages can be evicted  without going to swap? Size of reserved swap space limits what?  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 19
  • 20. Swap Space Swap space = where victim pages go  Partition or special file reserved on disk  Sometimes: special filesystem (“tmpfs”)  What kind of victim pages can be evicted  without going to swap? Read-only (“text”), untouched anonymous pages  Size of reserved swap space limits what?  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 20
  • 21. Swap Space Swap space = where victim pages go  Partition or special file reserved on disk  Sometimes: special filesystem (“tmpfs”)  Only read-only or undirtied victim pages can  be evicted without going to swap “text” (code), untouched anonymous pages  Size of reserved swap space limits  total virtual memory UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 21
  • 22. Cost of Paging Worst-case analysis – useless  Easy to construct adversary example:  every page requires page fault A, B, C, D, E, F, G, H, I, J, A... size of available memory UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 22
  • 23. Page Replacement Algorithms MIN, OPT (optimal)  RANDOM  evict random page  FIFO (first-in, first-out)  give every page equal residency  LRU (least-recently used)  MRU (most-recently used)  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 23
  • 24. MIN/OPT Invented by Belady (“MIN”)  Now known as “OPT”: optimal page  replacement Evict page to be accessed furthest in the  future Provably optimal policy  Just one small problem...  requires predicting the future Still useful point of comparison  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 24
  • 25. MIN/OPT example Page faults: 5  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 25
  • 26. RANDOM Evict any page  Works surprisingly well – why?  Theoretically: very good,  but not used in practice: takes no advantage of locality UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 26
  • 27. LRU Evict page that has not been used in  longest time (least-recently used) Approximation of MIN if recent past is good  predictor of future Variant of LRU used in all real operating  systems UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 27
  • 28. LRU example Page faults: ?  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 28
  • 29. LRU example Page faults: 5  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 29
  • 30. LRU, example II Page faults: ?  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 30
  • 31. LRU, example II Page faults: 12!  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 31
  • 32. FIFO First-in, first-out: evict oldest page  Also has competitive ratio k  But: performs miserably in practice!  LRU takes advantage of locality  FIFO does not  Suffers from Belady’s anomaly:  More memory can mean more paging!  LRU & other “stack” algs. do not  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 32
  • 33. FIFO & Belady’s Anomaly UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 33
  • 34. MRU Evict most-recently used page  Shines for LRU’s worst-case: loop that  exceeds RAM size A, B, C, D, A, B, C, D, ... size of available memory What we really want: adaptive algorithms  (e.g., EELRU – Kaplan & Smaragdakis) UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 34
  • 35. The End UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 35
  • 36. LRU: No Belady’s Anomaly Why no anomaly for LRU?  UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 36