Lecture 11: Memory Management - PowerPoint PPT Presentation

1 / 36
About This Presentation
Title:

Lecture 11: Memory Management

Description:

story: malloc() - overlays - relocation - segments - pages ... near-impossible. aside: position-independent code and dynamically-linked libraries ... – PowerPoint PPT presentation

Number of Views:96
Avg rating:3.0/5.0
Slides: 37
Provided by: Rand235
Category:

less

Transcript and Presenter's Notes

Title: Lecture 11: Memory Management


1
Lecture 11Memory Management
  • Prof. Kenneth M. Mackenzie
  • Computer Systems and Networks
  • CS2200, Spring 2003

Includes slides from Bill Leahy
2
Review 1/4 (mechanism) Process Control Block
(PCB)
PCB entry
PCB for P3
link
saved registers
PCB for P2
save area
saved PC
PCB for P1
memory limits
other stuff
current PCB
PCB for P0
3
Review 2/4 (mechanism)Process States
New
Terminated
Admitted
Exit
Scheduler Dispatch
Ready
Running
Interrupt
Waiting
4
Review 3/4 (phenomenon)CPU Burst Modelplots
of CPU utilization vs. time
CPU- bound
I/O- bound
mixed
5
Review 4/4 (policy)Scheduling
time process ---- ------- 0
A 10 B 20 A 30
C 40 A 50 C 60 A 70
C 80 A 90 A 100 A 110
A 120 A 130 A 140 150 160
FCFS Round-Robin Priority, e.g. SJF Dynamic
priority Example Round-Robin average wait
time? (40 0 30) / 3 23.3ms
6
knotes
  • story malloc() -gt overlays -gt relocation -gt
    segments -gt pages
  • malloc() want to alloc/dealloc memory.
    first-fit/best-fit/worst-fit 50 external
    fragmentation. buddy algorithm. Wow... wouldnt
    a visual simulation be cute here??? something to
    illustrate 50 fragmentation?
  • overlays what if you dont have enough memory??
  • relocation compact by moving things around??
    near-impossible.
  • aside position-independent code and
    dynamically-linked libraries
  • prob lem is namespace at what time do you bind
    names to physical locations?
  • relocation hardware back to the base/limit
    picture developed earlier
  • note protection benefits as well as relocation
    benefits
  • no immediately help for overlay problem
    segements permit multiple areas/process to help.
    note that segments or regions are a concept
    whether or not you have hardware support for
    them!
  • doesnt help external fragmentation problem
    still can expect to waste 50 of your space.
  • Paging divide unverse into fixed-size units
  • no external fragmentation trivial to find a
    block to use because theyre all the same
  • internal fragmentation about 1/2 page per
    segment (not a disaster)
  • translation mechanics
  • demand-paging mechanics

7
Today( Tuesday, most likely)
  • malloc() algorithms
  • Overlays?, Relocation?
  • break ... return midterms
  • Relocation in hardware base/limit, segments
  • Paging
  • mechanisms
  • policy

8
malloc chalk talk
  • process layout

9
Algorithms
  • First-fit
  • Can search from either end
  • Start at beginning or where left off
  • Best-fit
  • Allocate smallest hole that is big enough
  • Must search entire list (or keep sorted list)
  • Produces smallest leftover hole
  • Worst-fit
  • Allocate largest hole
  • produces largest leftover hole

10
Algorithms
  • First-fit (FASTER)
  • Can search from either end
  • Start at beginning or where left off
  • Best-fit
  • Allocate smallest hole that is big enough
  • Must search entire list (or keep sorted list)
  • Produces smallest leftover hole
  • Worst-fit (WORST PERFORMANCE)
  • Allocate largest hole
  • produces largest leftover hole

11
Relocation in HardwareBase and Bound registers
physical address space
Processor
SEGV trap
lt(bd-bs)
base
bound
Memory
(bound - base)
base
0
12
Multiple Partition Allocation
  • Want multiple users in memory at same time
  • Simple technique MFT (OS/360)
  • Fixed size partitions
  • One process per partition
  • Didnt seem too flexible in 1966!
  • More Flexible MVT
  • Start with OS and large free space
  • Free space (or spaces) known as hole (or holes)

13
Implementation
  • We have multiple processes in memory
  • Only one is active
  • We load the relocation and limit register for the
    process that is running
  • We might store the relocation and limit register
    values for non-running jobs in their PCB
  • The OS must manage this

14
OS
P1 600
P2 1000
P3 300
15
OS
P1 600
P3 300
16
OS
P1 600
P4 700
P3 300
17
OS
P4 700
P3 300
18
OS
P5 500
P4 700
P3 300
19
Comments?
  • Problems?
  • Difficulties?
  • Challenges?
  • Algorithms?

20
Fragmentation
  • External
  • Space between processes
  • Over time using N blocks may result in 0.5N
    blocks being unused
  • Internal Fragmentation
  • For the sake of efficiency typically give process
    more than is needed
  • Solution Compaction
  • May be costly
  • But need contiguous spaces!

21
Paging
  • Solution to external fragmentation.
  • Divide logical address space into non-contiguous
    regions of physical memory.
  • Commonly used technique in many operating systems.

22
Basic Method
  • Break Physical memory into fixed-sized blocks
    called Frames.
  • Break Logical memory into the same-sized blocks
    called Pages.
  • Disk also broken into blocks of the same size.

23
Hardware
Physical Memory
CPU
page
offset
frame
offset
page table
page
frame
24
Decimal Example
Physical Memory
Block size 1000 words Memory 1000
Frames Memory ?
CPU
page
offset
frame
offset
page table
page
frame
25
Decimal Example
Physical Memory
Block size 1000 words Memory 1000
Frames Memory 1,000,000
CPU
page
offset
frame
offset
page table
page
frame
26
Decimal Example
Physical Memory
Block size 1000 words Memory ? Frames Memory
10,000,000
CPU
page
offset
frame
offset
page table
page
frame
Assume addresses go up to 10,000,000. How big
is page table?
27
Decimal Example
Physical Memory
Block size 1000 words Memory 10,000
Frames Memory 10,000,000 words
CPU
page
offset
frame
offset
page table
page
10,000 Entries
frame
Assume addresses go up to 10,000,000. How big
is page table?
28
Decimal Example
Physical Memory
Block size 1000 words Memory 10,000
Frames Memory 10,000,000 words
CPU
42
356
256
356
page table
256
42
29
Questions?
30
Whats the right picture?
Physical Address Space
Logical Address Space
31
Whats the right picture?
Logical Address Space
Physical Address Space
32
Whats the right picture?
Physical Address Space
Logical Address Space
33
Whats the right picture?
Physical Address Space
Logical Address Space
34
Whats the right picture?
Logical Address Space
Physical Address Space
35
Questions?
36
Tiny Example32-byte memory with 4-byte pages
Physical memory 0 1 2 3 4 i 5 j 6 k 7 l 8 m 9 n 10
o 11 p 12 13 14 15 16 17 18 19 20 a 21 b 22 c 23
d 24 e 25 f 26 g 27 h 28 29 30 31
Logical memory 0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i
9 j 10 k 11 l 12 m 13 n 14 o 15 p
Page Table
0 1 2 3
5 6 1 2
Write a Comment
User Comments (0)
About PowerShow.com