SLIDE 1
Memory Management One of the most important OS jobs. Review memory - - PowerPoint PPT Presentation
Memory Management One of the most important OS jobs. Review memory - - PowerPoint PPT Presentation
Memory Management One of the most important OS jobs. Review memory hierarchy sizes, speed, cost Growing memories -> growing programs need for swapping and paging The simplest way to use memory is to have one program in memory sharing
SLIDE 2
SLIDE 3
FIFO vs. pick largest job to not waste memory (poor for small jobs). CPU utilization = 1 – p^n (p = time process waits for I/O, n = degree of multiprogramming). More processes = more efficient use
- f cpu.
Memory Management
SLIDE 4
Absolute (real) memory address vs. relative memory address. Relocation problem. Programs start at address 0 + have
- ffset.
Also must protect address space from
- ther programs.
Memory Management
SLIDE 5
If there isn't enough RAM to hold all the processes, secondary memory + swapping can be used. With swapping whole processes move back and forth between RAM and disk. May be brought back into a different place in memory. Use variable length partitions for better memory utilization. May get many small holes in memory
- do memory compaction (slow)
Memory Management
SLIDE 6
How much memory should be allocated to a process?
- Fixed size – give exact amount needed
- Growth and shrinking
- grow into a hole, or have to be
moved or swap somebody out.
- allocate some space to allow growth.
Need a way to keep track of allocated memory (+ to which process) + free memory.
Memory Management
SLIDE 7
Bit maps are one way to keep track of allocated and free memory.
- A 1 indicates used and a 0 unused.
- Each bit represents one allocation
unit (4 bytes, 8 bytes). Linked lists are another way to keep track of memory.
Memory Management
SLIDE 8
Need an algorithm to decide which hole to give to a process. Four fit algorithms.
- First Fit – give process first hole in list
that is big enough. Break it into two parts (process and a smaller hole). Fast.
- Next Fit – Similar to First fit except
instead of searching from beginning start where left off. Performs slightly
worse than first fit.
Memory Management
SLIDE 9
- Best Fit – Find the smallest hole that
will work. Slower than first fit. Wastes more memory because creates small holes.
- Worst Fit – Use biggest hole and
leave the biggest possible new hole.
Doesn't work well in simulation. Another idea is Quick Fit. Have lists of more commonly requested sizes. Can find a good size hole fast. Merging free memory back is hard.
Memory Management
SLIDE 10
Data Structure Thoughts
- One list with both processes and holes
- slower to find a hole
- faster to free up memory.
- Two lists – one for processes and one
for holes.
- can order hole list and speed up
best fit.
- harder to reallocate.
Any other ideas?
Memory Management
SLIDE 11
Memory blocks are available of size 2k, L <= k <= U 2L = smallest size block allowed 2U = largest block allocated (entire available memory) Start by considering available memory as
- ne block. Then break it down into two
buddies of equal size. Continue until smallest block needed for process is created or found. (think binary search).
The Buddy System
SLIDE 12
When memory is released empty buddies can be merged back into a single block. Two free blocks can only be combined if they are buddies, and buddies have addresses that differ only in one bit. Two one-byte blocks are buddies iff they differ in the last bit, two two byte blocks are buddies iff they differ in the second to last bit and so on. (Go over an example)
The Buddy System
SLIDE 13
Buddy System Example
1 MB Start off with 1 MB to manage A=128k, 128k free, 256k free, 512k free B requests 240k A requests 100k C requests 64k A=128k, 128k free, B=256k, 512k free A=128k, C=64k, 64k free, B=256k, 512k free
SLIDE 14
Buddy System Example
A=128k,C=64k, 64k free, B=256k,D=256k, 256k free Release B A=128k,C=64k, 64k free,256k free,D=256k, 256k free Release A
128k free,C=64k,64k free,256k free,D=256k,256k free
E requests 75k
E=128k,C=64k,64k free,256k free,D=256k,256k free
D requests 256k
SLIDE 15
Buddy System Example
Release C E=128k,128k free,256k free, D=256k,256k free Release E 512k free, D=256k,256k free Release D 1 MB
SLIDE 16