Thrashing & Working Set

download Thrashing & Working Set

of 19

Transcript of Thrashing & Working Set

  • 8/7/2019 Thrashing & Working Set

    1/19

    Operating SystemsProf. Navneet Goyal

    Department of Computer Science & Information Systems

    BITS, Pilani

  • 8/7/2019 Thrashing & Working Set

    2/19

    Topics for Today Thrashing

    Working Set

  • 8/7/2019 Thrashing & Working Set

    3/19

  • 8/7/2019 Thrashing & Working Set

    4/19

    Principle of Locality

    Program and data references within aprocess tend to cluster

    Only a few pieces of a process will beneeded over a short period of time

    Possible to make intelligent guesses aboutwhich pieces will be needed in the future

    This suggests that virtual memory maywork efficiently

  • 8/7/2019 Thrashing & Working Set

    5/19

    Locality In A Memory-Reference Pattern

  • 8/7/2019 Thrashing & Working Set

    6/19

    Thrashing If a process does not have enough

    pages, the page-fault rate is very high.This leads to:

    low CPU utilization operating system thinks that it needs to

    increase the degree of multiprogramming

    another process added to the system

    Thrashing | a process is busy swappingpages in and out

  • 8/7/2019 Thrashing & Working Set

    7/19

    Thrashing (Cont.)

  • 8/7/2019 Thrashing & Working Set

    8/19

    Demand Paging and Thrashing

    Why does demand paging work?Locality model

    Process migrates from onelocality to another

    Localities may overlap

    Why does thrashing occur?7 size of locality > total memorysize

  • 8/7/2019 Thrashing & Working Set

    9/19

    Working-Set Model ( |working-set window| a fixed number of

    page referencesExample: 10,000 instruction

    WSSi (working set size ofProcess Pi) =

    total number of pages referenced in the mostrecent ( (varies in time)

    if( too small will not encompass entirelocality

    if( too large will encompass several localities

    if( = g will encompass entire program

    D = 7 WSSi | total demand frames

    ifD > m Thrashing

    Policy ifD > m, then suspend one of the

    processes

  • 8/7/2019 Thrashing & Working Set

    10/19

  • 8/7/2019 Thrashing & Working Set

    11/19

    Keeping

    Track of t

    heW

    orking Set Approximate with interval timer + a reference

    bit

    Example: ( = 10,000

    Timer interrupts after every 5000 time units Keep in memory 2 bits for each page

    Whenever a timer interrupts copy and sets thevalues of all reference bits to 0

    If one of the bits in memory = 1 page inworking set

    Why is this not completely accurate?

    Improvement = 10 bits and interrupt every 1000time units

  • 8/7/2019 Thrashing & Working Set

    12/19

    Page Size

    Smaller page size, less amount of internalfragmentation

    Smaller page size, more pages required

    per process More pages per process means larger

    page tables Larger page tables means large portion of

    page tables in virtual memory Secondary memory is designed to

    efficiently transfer large blocks of data soa large page size is better

  • 8/7/2019 Thrashing & Working Set

    13/19

    Page Size

    Small page size, large number of pageswill be found in main memory

    As time goes on during execution, thepages in memory will all contain portionsof the process near recent references.Page faults low.

    Increased page size causes pages tocontain locations further from any recentreference. Page faults rise.

  • 8/7/2019 Thrashing & Working Set

    14/19

  • 8/7/2019 Thrashing & Working Set

    15/19

    Frame Allocation: Issues Smaller no. of frames to a process more

    processes can reside in MM increases probability

    that OS will find at least one ready process

    Despite Principle of Locality, Page faults rate will behigh

    Beyond a certain size, additional allocation will have

    no noticeable effect on page fault rate because of

    Principle of Locality

  • 8/7/2019 Thrashing & Working Set

    16/19

    Frame Allocation Schemes

    Fixed Allocation

    Equal Allocation

    Proportional Allocation Priority Allocation

  • 8/7/2019 Thrashing & Working Set

    17/19

    Fixed AllocationEqual allocation e.g., if 100 frames and 5 processes,

    give each 20 pages.

    Proportional allocation Allocate according to the size

    of process.

    mS

    spa

    m

    sS

    ps

    iii

    i

    ii

    v!!

    !

    !

    !

    forallocation

    framesofnumbertotal

    processofsize

    5964137127

    564137

    10

    127

    1064

    2

    1

    2

    1

    }v!

    }v!

    !

    !!

    a

    a

    s

    sm

  • 8/7/2019 Thrashing & Working Set

    18/19

    Priority Allocation

    Use a proportional allocation scheme

    using priorities rather than size.

    If process Pigenerates a page fault,

    select for replacement one of its frames.

    select for replacement a frame from a process

    with lower priority number.

  • 8/7/2019 Thrashing & Working Set

    19/19

    Global vs. Local Allocation

    Global replacement processselects a replacement frame fromthe set of all frames; one processcan take a frame from another.

    Local replacement each processselects from only its own set of

    allocated frames.