[09]memory management 01

Upload: carlos-simarillion

Post on 02-Jun-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 [09]Memory Management 01

    1/35

    Operating SystemConcepts

    Ku-Yaw Chang

    [email protected]

    Assistant Professor, Department ofComputer Science and Information Engineering

    Da-Yeh University

    mailto:[email protected]:[email protected]
  • 8/10/2019 [09]Memory Management 01

    2/35

    2Ku-Yaw Chang Chapter 9 Memory Management

    Chapter 9 Memory Management

    Keep several processes in memory to increase

    CPU utilization

    Memory management algorithms

    Require hardware support

    Common strategies

    Paging

    Segmentation

  • 8/10/2019 [09]Memory Management 01

    3/35

  • 8/10/2019 [09]Memory Management 01

    4/35

    4Ku-Yaw Chang Chapter 9 Memory Management

    9.1 Background

    Program must be brought (loaded) into memory and

    placed within a process for it to be run.

    Address binding

    A mapping from one address space to anotherA typical instruction-execution cycle

    Fetchan instruction from memory

    Decodethe instruction

    May cause operands to be fetched from memory Executethe instruction

    Storeresults back into memory

  • 8/10/2019 [09]Memory Management 01

    5/35

    5Ku-Yaw Chang Chapter 9 Memory Management

    9.1.1 Address Binding

    Input queue

    A collection of processes on the disk that are waiting

    to be brought into memory to run the program.

    A user program will go through several stepsbefore being executed

    Addresses in source program are symbolic

    A compiler binds these symbolic addresses to

    relocatable addresses

    A loader binds these relocatable addresses to

    absolute addresses

  • 8/10/2019 [09]Memory Management 01

    6/35

    6Ku-Yaw Chang Chapter 9 Memory Management

    9.1.1 Address Binding

    Compile time

    Absolute code can

    be generated

    Know at compiletime where the

    process will reside

    in memory

    MS-DOS .COM-

    format programsare absolute code

  • 8/10/2019 [09]Memory Management 01

    7/35

    7Ku-Yaw Chang Chapter 9 Memory Management

    9.1.1 Address Binding

    Load time

    Relocatable code

    can be generated

    Not known atcompile time where

    the process will

    reside in memory

    Final binding is

    delayed until loadtime

  • 8/10/2019 [09]Memory Management 01

    8/35

    8Ku-Yaw Chang Chapter 9 Memory Management

    9.1.1 Address Binding

    Execution time

    The process can be

    moved from one

    memory segmentto another

    Binding must be

    delayed until run

    time

    Special hardwaremust be available

  • 8/10/2019 [09]Memory Management 01

    9/35

    9Ku-Yaw Chang Chapter 9 Memory Management

    9.1.2 Logical- Versus Physical-

    Address SpaceLogicaladdress An address generated by the CPU

    Compile-time and load-time

    Also called virtual address

    Logical-address spaceThe set of all logical addresses

    Physicaladdress An address seen by the memory unit

    The one loaded into the memory-address unit Execution time

    Logical and physical address spaces differ

    Physical-address space

  • 8/10/2019 [09]Memory Management 01

    10/35

    10Ku-Yaw Chang Chapter 9 Memory Management

    9.1.2 Logical- Versus Physical-

    Address Space

    Memory-Management Unit (MMU)

    A hardware device

    Run-time mapping from virtual to physical addresses

    Different methods to accomplish such a mappingLogical addresses

    0to max

    Physical addresses

    R+ 0 to R+ max

  • 8/10/2019 [09]Memory Management 01

    11/35

  • 8/10/2019 [09]Memory Management 01

    12/35

    12Ku-Yaw Chang Chapter 9 Memory Management

    9.1.3 Dynamic Loading

    The entire program and data must be in memoryfor its execution The size of a process is limited to the size pf physical

    memory.

    Dynamic Loading All routines are kept on disk in a relocatable load

    formatThe main program is loaded into memory and is executed

    A routine is not loaded until it is called

    Advantage An unused routine is never loaded

  • 8/10/2019 [09]Memory Management 01

    13/35

    13Ku-Yaw Chang Chapter 9 Memory Management

    9.1.4 Dynamic Linking and

    Shared Libraries

    Dynamic Linking

    Linking is postponed until execution time

    Small piece of code, called stub, used to locate the

    appropriate memory-resident library routine

    OS checks if routine is in processes memory address

    If yes, load the routine into memory

    Stub replaces itself with the address of the routine, and

    executes the routine.

    Dynamic linking is particularly useful for libraries.

  • 8/10/2019 [09]Memory Management 01

    14/35

    14Ku-Yaw Chang Chapter 9 Memory Management

    9.1.5 Overlays

    Keep in memory only those instructions and data

    that are needed at any given time

    Needed when process is larger than amount of

    memory allocated to itFeatures

    Implemented by user

    No special support needed from operating system

    Programming design is complex

  • 8/10/2019 [09]Memory Management 01

    15/35

    15Ku-Yaw Chang Chapter 9 Memory Management

    9.1.5 Overlays

  • 8/10/2019 [09]Memory Management 01

    16/35

    16Ku-Yaw Chang Chapter 9 Memory Management

    Chapter 9 Memory Management

    1. Background

    2. Swapping

    3. Contiguous Memory

    Allocation

    4. Paging

    5. Segmentation

    6. Segmentation with

    Paging

    7. Summary

    8. Exercises

  • 8/10/2019 [09]Memory Management 01

    17/35

    17Ku-Yaw Chang Chapter 9 Memory Management

    Swapping

    A process can be

    Swapped temporarily out of memory to a backing

    store

    Commonly a fast disk

    Brought back into memory for continued execution

    A process swapped back into

    The same memory space

    Binding is done at assembly or load time

    A different memory space

    Execution-time binding

  • 8/10/2019 [09]Memory Management 01

    18/35

    18Ku-Yaw Chang Chapter 9 Memory Management

    Swapping of two processes

  • 8/10/2019 [09]Memory Management 01

    19/35

  • 8/10/2019 [09]Memory Management 01

    20/35

    20Ku-Yaw Chang Chapter 9 Memory Management

    Swapping

    Major part of the swap time is transfer time

    Directly proportional to the amount of memory

    swapped

    Factors

    How much memory is actually used

    To reduce swap time

    Be sure the process is completely idlePending I/O

  • 8/10/2019 [09]Memory Management 01

    21/35

    21Ku-Yaw Chang Chapter 9 Memory Management

    Chapter 9 Memory Management

    1. Background

    2. Swapping

    3. Contiguous Memory

    Allocation

    4. Paging

    5. Segmentation

    6. Segmentation with

    Paging

    7. Summary

    8. Exercises

  • 8/10/2019 [09]Memory Management 01

    22/35

    22Ku-Yaw Chang Chapter 9 Memory Management

    Contiguous Memory Allocation

    Memory

    One for the resident operating system

    In either low or high memory

    Location of the interrupt vector

    One for the user processes

    Contiguous memory allocation

    Each process is contained in a single contiguous

    section of memory

  • 8/10/2019 [09]Memory Management 01

    23/35

    23Ku-Yaw Chang Chapter 9 Memory Management

    Memory Protection

    A relocation register with a limit register

  • 8/10/2019 [09]Memory Management 01

    24/35

    24Ku-Yaw Chang Chapter 9 Memory Management

    Memory Allocation

    Fixed-sized partitions Simplest

    Each partition contain exactly one processDegree of multiprogramming is bounded

    Strategies

    First fitBest fit

    Worst fit

    Problem External fragmentation

    Internal fragmentation50-percent rule Given N allocated blocks

    Another 0.5 N blocks will be lost

  • 8/10/2019 [09]Memory Management 01

    25/35

  • 8/10/2019 [09]Memory Management 01

    26/35

    26Ku-Yaw Chang Chapter 9 Memory Management

    Chapter 9 Memory Management

    1. Background

    2. Swapping

    3. Contiguous Memory

    Allocation

    4. Paging

    5. Segmentation

    6. Segmentation with

    Paging

    7. Summary

    8. Exercises

  • 8/10/2019 [09]Memory Management 01

    27/35

  • 8/10/2019 [09]Memory Management 01

    28/35

    28Ku-Yaw Chang Chapter 9 Memory Management

    Paging hardware

  • 8/10/2019 [09]Memory Management 01

    29/35

    29Ku-Yaw Chang Chapter 9 Memory Management

    Paging Model

  • 8/10/2019 [09]Memory Management 01

    30/35

    30Ku-Yaw Chang Chapter 9 Memory Management

    Paging Example

  • 8/10/2019 [09]Memory Management 01

    31/35

    31Ku-Yaw Chang Chapter 9 Memory Management

    Free Frames

    Before Allocation After Allocation

  • 8/10/2019 [09]Memory Management 01

    32/35

    32Ku-Yaw Chang Chapter 9 Memory Management

    Chapter 9 Memory Management

    1. Background

    2. Swapping

    3. Contiguous Memory

    Allocation

    4. Paging

    5. Segmentation

    6. Segmentation with

    Paging

    7. Summary

    8. Exercises

  • 8/10/2019 [09]Memory Management 01

    33/35

    33Ku-Yaw Chang Chapter 9 Memory Management

    Chapter 9 Memory Management

    1. Background

    2. Swapping

    3. Contiguous Memory

    Allocation

    4. Paging

    5. Segmentation

    6. Segmentation with

    Paging

    7. Summary

    8. Exercises

  • 8/10/2019 [09]Memory Management 01

    34/35

    34Ku-Yaw Chang Chapter 9 Memory Management

    Chapter 9 Memory Management

    1. Background

    2. Swapping

    3. Contiguous Memory

    Allocation

    4. Paging

    5. Segmentation

    6. Segmentation with

    Paging

    7. Summary

    8. Exercises

  • 8/10/2019 [09]Memory Management 01

    35/35

    35Ku Yaw Chang Chapter 9 Memory Management

    Chapter 9 Memory Management

    1. Background

    2. Swapping

    3. Contiguous Memory

    Allocation

    4. Paging

    5. Segmentation

    6. Segmentation with

    Paging

    7. Summary

    8. Exercises