osclass 181112-2

Embed Size (px)

Citation preview

  • 7/30/2019 osclass 181112-2

    1/26

  • 7/30/2019 osclass 181112-2

    2/26

    Program must be brought into memory andplaced within a process for it to be executed.

    Input queue collection of processes on the diskthat are waiting to be brought into memory forexecution.

    Select one process from input queue to load it

    into memory for execution. After execution(terminates) memory space becomes available.

  • 7/30/2019 osclass 181112-2

    3/26

    Address binding of instructions and data tomemory addresses can happen at three differentstages:

    Compile time: If memory location known a priori,absolute code can be generated. Since it starts fromthat location.

    Load time: Must generate reloadable code if memorylocation is not known at compile time.

    Execution time: Binding delayed until run time if theprocess can be moved during its execution from onememory segment to another. Need hardware supportfor address maps (e.g., base and limit registers).

  • 7/30/2019 osclass 181112-2

    4/26

    Multistep processing of a user program

  • 7/30/2019 osclass 181112-2

    5/26

    The concept of a logical address space that is bound to aseparate physical address space is central to propermemory management.

    Logical address : Generated by the CPU; also referred to asvirtual address.

    Physical address: Address seen by the memory unit.

    Logical and physical addresses are the same in compile-

    time and load-time address-binding schemes; logical(virtual) and physical addresses differ in execution-timeaddress-binding scheme.

    The set of all logical address generated by a program.

  • 7/30/2019 osclass 181112-2

    6/26

    The run-time mapping from virtual to physicaladdresses is done by the memory management unit(MMU), which is a hardware device.

    The user program deals with logical addresses; itnever sees the real physical addresses.

    Two different types of addresses:

    Logical: range 0 to max. Physical: range R+0 to R+max; where R is a base value.

    The user generates only logical addresses and thinksthat the process runs in locations 0 to max.

  • 7/30/2019 osclass 181112-2

    7/26

    In MMU scheme, the value in the relocation register is addedto every address generated by a user process at the time it issent to memory.

    Example: Dynamic relocation using a relocation register.

  • 7/30/2019 osclass 181112-2

    8/26

    Dynamic loading is used to obtain bettermemory space.

    An unused routine will never been used.

    It is particularly useful when large amount of

    code.

    It does not requires any special support fromthe OS.

  • 7/30/2019 osclass 181112-2

    9/26

    It is similar to Dynamic loading.

    Here linking is postponed until the time ofexecution.

    It avoids to copy the whole language librariesincluded in the executable image.

  • 7/30/2019 osclass 181112-2

    10/26

    A process can be swapped temporarily out ofmemory to a backing store, and then broughtback into memory for continued execution.

    Take Round robin scheduler as example, whentime quantum expires the memory swap out theprocess and swap in another process.

    Roll out, roll in In priority-based schedulingalgorithms; lower-priority process is swappedout if higher-priority process arrives and wantsservice, can be loaded and executed.

  • 7/30/2019 osclass 181112-2

    11/26

    A process that is swapped out will be swappedback into the same memory space that itoccupied previously.

    Normally CPU maintains the ready queue for thebacking store.

    When CPU needs it calls the dispatcher.

    If we want to swap, it should be completely idle. Like without any pending i/o requests.

  • 7/30/2019 osclass 181112-2

    12/26

  • 7/30/2019 osclass 181112-2

    13/26

    Main memory usually is divided into two

    partitions: For the resident operating system

    For the user processes.

  • 7/30/2019 osclass 181112-2

    14/26

    The issues of memory protection is Protecting OS from user processes. Protecting user processes from another process.

    Relocation register: It contains the value of thesmallest physical address.

    Limit register: It contains the range of the logical

    address. Each logical address must be less than the Limit

    register and is dynamically adding the relocationregister. This mapped address is sent to the memory.

  • 7/30/2019 osclass 181112-2

    15/26

  • 7/30/2019 osclass 181112-2

    16/26

    The memory can be divided into several fixed sizedcomponents is called Partitions.

    The block of available memory called as Hole.

    This may be at various sizes scattered throughout thememory.

  • 7/30/2019 osclass 181112-2

    17/26

    To satisfy the request of size n from a list of free holes.There are three approaches.

    First fit: Allocates the first hole that is big enough.

    Best fit: Allocates the smallest hole that is big enough,but it searches the entire list. It produces the smallestleftover hole.

    Worst fit: Allocates the largest hole, it also searchesthe whole list. It produces the largest leftover hole.

  • 7/30/2019 osclass 181112-2

    18/26

    Simply wasting of the memory. Memory that is internal to the partition but is not used called Internal

    fragmentation. Memory that is outside to the partition and is too small to used by any

    process is called External Fragmentation.

  • 7/30/2019 osclass 181112-2

    19/26

    Divide physical memory into fixed-sized blocks calledframes (typically between 512 bytes and 8192 bytes).

    Paging is a memory management technique whereDivision of logical memory into blocks of same sizecalled pages. i.e., divide each process into same size of frames.

    Operating system maintains a page table for eachprocess. Page table contains the frame location for each process

    page. memory address = page number + offset

  • 7/30/2019 osclass 181112-2

    20/26

  • 7/30/2019 osclass 181112-2

    21/26

    Here the logicaladdress is dividedinto twocomponents.

    1. Page number (p)2. Page offset(d)

    Page number p is an index intoa page table that contains baseaddress of each page in physicalmemory.

    Page offset d is

    a displacement,combined withbase address todefine the physicalmemory addressthat is sent to the

    memory unit.

  • 7/30/2019 osclass 181112-2

    22/26

    Page table is kept in main memory.

    Page-table base register (PTBR) points to the page table.

    Page-table length register (PRLR) indicates size of thepage table.

    In this scheme every data/instruction access requires twomemory accesses. One for the page table and another for

    the data/instruction. The two memory access problem can be solved by the use

    of a special fast-lookup hardware cache called associativememory or Translation Look-aside Buffers (TLBs)

  • 7/30/2019 osclass 181112-2

    23/26

  • 7/30/2019 osclass 181112-2

    24/26

    Associative Lookup = time unit

    Assume time to access memory is 1 microsecond

    Hit ratio percentage of times that a page number isfound in the TLB.

    Hit ratio =

    Effective Access Time (EAT)

    EAT = (1 + )+ (2 + )(1 )= 2 +

  • 7/30/2019 osclass 181112-2

    25/26

    Memory protection implemented byassociating protection bit with each frame

    Valid-invalid bit attached to each entry in thepage table: valid indicates that the associated page is in the

    process logical address space, and is thus a legalpage.

    invalid indicates that the page is not in theprocess logical address space

  • 7/30/2019 osclass 181112-2

    26/26

    Vvalid bit.Iinvalid bit.