Title: Lecture 11: Memory Management
1Lecture 11Memory Management
- Prof. Kenneth M. Mackenzie
- Computer Systems and Networks
- CS2200, Spring 2003
Includes slides from Bill Leahy
2Review 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
3Review 2/4 (mechanism)Process States
New
Terminated
Admitted
Exit
Scheduler Dispatch
Ready
Running
Interrupt
Waiting
4Review 3/4 (phenomenon)CPU Burst Modelplots
of CPU utilization vs. time
CPU- bound
I/O- bound
mixed
5Review 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
6knotes
- 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
7Today( Tuesday, most likely)
- malloc() algorithms
- Overlays?, Relocation?
- break ... return midterms
- Relocation in hardware base/limit, segments
- Paging
- mechanisms
- policy
8malloc chalk talk
9Algorithms
- 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
10Algorithms
- 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
11Relocation in HardwareBase and Bound registers
physical address space
Processor
SEGV trap
lt(bd-bs)
base
bound
Memory
(bound - base)
base
0
12Multiple 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)
13Implementation
- 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
14OS
P1 600
P2 1000
P3 300
15OS
P1 600
P3 300
16OS
P1 600
P4 700
P3 300
17OS
P4 700
P3 300
18OS
P5 500
P4 700
P3 300
19Comments?
- Problems?
- Difficulties?
- Challenges?
- Algorithms?
20Fragmentation
- 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!
21Paging
- Solution to external fragmentation.
- Divide logical address space into non-contiguous
regions of physical memory. - Commonly used technique in many operating systems.
22Basic 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.
23Hardware
Physical Memory
CPU
page
offset
frame
offset
page table
page
frame
24Decimal Example
Physical Memory
Block size 1000 words Memory 1000
Frames Memory ?
CPU
page
offset
frame
offset
page table
page
frame
25Decimal Example
Physical Memory
Block size 1000 words Memory 1000
Frames Memory 1,000,000
CPU
page
offset
frame
offset
page table
page
frame
26Decimal 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?
27Decimal 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?
28Decimal 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
29Questions?
30Whats the right picture?
Physical Address Space
Logical Address Space
31Whats the right picture?
Logical Address Space
Physical Address Space
32Whats the right picture?
Physical Address Space
Logical Address Space
33Whats the right picture?
Physical Address Space
Logical Address Space
34Whats the right picture?
Logical Address Space
Physical Address Space
35Questions?
36Tiny 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