Docsity

Memory Management Techniques: Dynamic Linking, Swapping, Allocation, Fragmentation, Paging, Slides of Operating Systems

Partial preview of the text

Download Memory Management Techniques: Dynamic Linking, Swapping, Allocation, Fragmentation, Paging and more Slides Operating Systems in PDF only on Docsity!

Lecture 17

Chapter 8: Main Memory (cont)

Chapter 9: Virtual Memory

Binding of Instructions and Data to Memory

  • Address binding of instructions and data to memory addresses can happen at three different stages - Compile time : - If memory location known a priori,generated; absolute code can be - must recompile code if starting location changes - Load time : - Must generateat compile time relocatable code if memory location is not known - Execution time : - Binding delayed until run time if the process can be movedduring its execution from one memory segment to another. - Need hardware support for address maps (e.g., base and limit registers)

Dynamic Linking

  • Linking postponed until execution time
  • Small piece of code, stub , used to locate the appropriate memory- resident library routine
  • Stub replaces itself with the address of the routine, and executes the routine
  • Operating system needed to check if routine is in processes’ memory address
  • Dynamic linking is particularly useful for libraries
  • System also known as shared libraries
    • versions

Swapping

  • A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution
  • Backing store – fast disk large enough to accommodate copies of all memory images for all users;
  • Roll out, roll in – swapping variant used for priority-based scheduling algorithms;
  • Swapped process should be idle
    • I/O problem
  • Major part of swap time is transfer time
  • Modified versions of swapping are found on many systems

Contiguous Allocation (Cont)

  • Multiple-partition allocation
    • Hole – block of available memory;
      • holes of various size are scattered throughout memory
    • When a process arrives, it is allocated memory from a hole large enough to accommodate it
    • Operating system maintains information about: a) allocated partitions b) free partitions (hole) OS process 5 process 8 process 2

OS process 5

process 2

OS process 5

process 2

process 9

OS process 5 process 9

process 2

process 10

Dynamic Storage-Allocation Problem

  • First-fit : Allocate the first hole that is big enough
  • Best-fit : Allocate the smallest hole that is big enough; must search entire list, unless ordered by size - Produces the smallest leftover hole
  • Worst-fit : Allocate the largest hole; must also search entire list - Produces the largest leftover hole
  • First-fit and best-fit better than worst-fit in terms of speed and storage utilization.
  • First-fit generally fastest.

How to satisfy a request of size n from a list of free holes

Paging

  • Logical address space of a process can be noncontiguous;
    • process is allocated physical memory whenever the latter is available
  • Divide physical memory into fixed-sized blocks called frames
    • size is power of 2, between 512 bytes and 8,192 bytes
  • Divide logical memory into blocks of same size called pages
  • Keep track of all free frames
  • To run a program of size n pages,
    • need to find n free frames and load program
  • Set up a page table to translate logical to physical addresses
  • Internal fragmentation

Paging Hardware

Page number

Page offset

Effective Access Time

  • Associative Lookup = ε time unit
  • Assume memory cycle time is 1 microsecond
  • Hit ratio – percentage of times that a page number is found in the associative registers; ratio related to number of associative registers
  • Hit ratio = α
  • Effective Access Time (EAT)

EAT = (1 + ε) α + (2 + ε)(1 – α) Docsity.com

Shared Pages

  • Shared code
    • One copy of read-only (reentrant) code shared among processes - Non-self-modifying code
    • Shared code must appear in same location in the logical address space of all processes
  • Private code and data
    • Each process keeps a separate copy of the code and data

Structure of the Page Table

  • Hierarchical Paging
  • Hashed Page Tables
  • Inverted Page Tables

Two-Level Paging Example

  • A logical address (on 32-bit machine with 1K page size) is divided into:
    • a page number consisting of 22 bits
    • a page offset consisting of 10 bits
  • Since the page table is paged, the page number is further divided into:
    • a 12-bit page number
    • a 10-bit page offset
  • Thus, a logical address is as follows:

where pi is an index into the outer page table, and p 2 is the displacement within the page of the outer page table

page number (^) page offset p i p 2 d 12 10 10

Three-level Paging Scheme

Very large table!

Still very large!