Chapter 7: Memory Management - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

Chapter 7: Memory Management

Description:

Data areas were allocated within the load module ... A program must use 'overlays' if too big 'Internal fragmentation' results if program too small ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 32
Provided by: markt2
Category:

less

Transcript and Presenter's Notes

Title: Chapter 7: Memory Management


1
Chapter 7 Memory Management
  • CS 472 Operating Systems
  • Indiana University Purdue University Fort Wayne

2
Memory management
  • In a uniprogramming system, memory is divided
    into one partition for the OS and another
    partition for the user program
  • In a multiprogramming system, the user area is
    subdivided so each process has its own partition
  • This allows multiple processes to run
    concurrently
  • A strategy for doing this is known as memory
    management

3
Memory management
  • Memory should be efficiently allocated so that a
    maximum number of processes can coexist
  • We want to have at least one process in the ready
    queue when the processor becomes available
  • Some requirements
  • Ability to relocate a program
  • Each partition should be protected
  • Processes should be able to establish shared
    memory areas

4
Review of addressing
absolute address
  • Relative address
  • an offset from the load address
  • Absolute address
  • address of a physical memory location
  • used, for example, with memory-mapped I/O

load address
program
relative address
5
Early systems
  • Compiled programs in early systems used only
    absolute addresses
  • The load address needed to be specified at
    compile time
  • Data areas were allocated within the load module
  • If the program was loaded elsewhere, references
    would be off
  • Hard to combine separately compiled program units

6
Later systems with relative addressing
  • Alinker program is introduced to combine
    separately compiled program units
  • The linker needs to modify relative addresses of
    each separate unit to reflect the load address of
    the first unit
  • Linker output is an .exe file
  • Absolute addresses (say, for memory-mapped I/O)
    are not changed

7
Linker
myProgram.exe
load address
unit1.obj
modified relative addresses
unit2.obj
unit3.obj
8
Protection
  • A process should not be able to reference memory
    locations in another process without permission
  • Hardware support needed for protection
  • Not possible to check dynamically calculated
    addresses at compile time
  • All addresses must be checked at run time

9
Hardware support for relative addressing
interrupt
relative address

compare
absolute address
base register
bounds register
load address
load address size
10
Hardware and relative addressing . . .
  • Allows a program to be built out of separately
    compiled units
  • Bounds register provides protection to other
    users
  • Allows the program to be swapped out of memory
    and then swapped back in at a different load
    address
  • This is called dynamic relocation

11
Memory management techniques
  • Fixed partitioning
  • Dynamic partitioning
  • Buddy system
  • Simple paging
  • Simple segmentation
  • Virtual memory with paging
  • Virtual memory with segmentation

In order of increasing sophistication
12
Fixed partitioning
memory

operating system
  • The number and size of partitions is fixed
  • The sizes can be the same or different
  • A program must use overlays if too big
  • Internal fragmentation results if program too
    small
  • This is wasted space at the end of a partition
  • See next slide

13
Fixed partitioning

operating system
  • Placement algorithm for partitions of mixed size
  • Feed all new processes from a single queue
  • For the next process, allocate the smallest
    available partition that will hold the process

process 2
process 1
process 3
fragmentation
14
Dynamic partitioning
memory

operating system
  • No fixed number of partitions
  • Partition size process size
  • no internal fragmentation
  • External fragmentation
  • As processes come and go, many scattered small
    holes grow between processes
  • See next slide

process 1
process 2
process 3
process 4
External fragmentation
15
Dynamic partitioning
memory

operating system
  • Compaction needed
  • time consuming
  • requires dynamic relocation
  • Placement algorithm choices
  • best-fit, first-fit, and next-fit
  • First-fit is simplest and best
  • Best-fit leads to smaller fragments
  • These are usually too small to use

process 5
process 6
process 2
process 7
process 4
External fragmentation
16
Buddy system
  • A compromise between the rigidity of fixed
    partitioning and the complexity and overhead of
    dynamic partitioning
  • Allocates blocks of size 2k
  • Tries to allow a variety of block sizes while
    avoiding excess internal fragmentation

17
Buddy system
  • Initial memory is one block of 2U bytes
  • For a memory request of size s, find the smallest
    i such that 2i-1lt s 2i
  • Successively divide blocks in half until size 2i
    is reached
  • Allocate one block, save the buddy
  • Maintain a list of holes of each size
  • When two buddies of size 2i become available,
    merge them into a hole of size 2i1

18
(No Transcript)
19
(No Transcript)
20
Simple paging
  • Partition memory into page frames of fixed
    equal size
  • Divide each process into pages of the same size
    as page frames
  • Any page may be loaded into any page frame
  • Simple means all pages of a process must be
    loaded into page frames when the process is
    started

21
Simple paging
  • The OS maintains a page table for each process
  • Table consists of page table entries (PTEs)
  • Entry n in the table is the PTE of page n
  • The PTE of page n gives the frame number where
    the page is loaded
  • Internal fragmentation exists only on the last
    page of each process
  • No external fragmentation

22
Assignment of pages to free page frames
23
Assignment of pages to free page frames
24
Corresponding page tables
25
Address translation
  • Must be done automatically by hardware
  • Uses the page tables
  • Each logical address consists of two parts
  • page number
  • offset within the page

logical address
page number offset
26
Address translation
  • Consider a logical address of nm bits
  • leftmost n bits are the page number
  • rightmost m bits are the offset
  • Use the page number as an index into the process
    page table
  • Obtain the bits of the frame number from the PTE
  • Append the offset to the frame number and obtain
    the physical address that corresponds to the
    logical address

27
(No Transcript)
28
Simple segmentation
  • Similar to simple paging except programmer
    modularizes process into segments s0, s1, s2, . .
    .
  • Segments may be of different sizes (smaller than
    a maximum size)
  • Each segment is loaded into a dynamic partition
  • Each segment has a load address and a length
  • Simple means that all segments must be loaded
    into partitions when the process starts
  • External fragmentation exists

29
Address translation
  • The OS maintains a segment table for each
    process
  • Address translation must be done automatically by
    hardware
  • Each logical address consists of two parts
  • segment number
  • offset within the segment
  • If the offset exceeds the segment length, the
    process is terminated with a memory violation

30
  • Address translation

31
Appendix 7A
  • Good review of linking and loading
  • See pages 326 - 331
Write a Comment
User Comments (0)
About PowerShow.com