Presentation is loading. Please wait.

Presentation is loading. Please wait.

From Monoprogramming to multiprogramming with swapping

Similar presentations


Presentation on theme: "From Monoprogramming to multiprogramming with swapping"— Presentation transcript:

1 From Monoprogramming to multiprogramming with swapping
Memory Management From Monoprogramming to multiprogramming with swapping

2 Memory Hierarchy Small amount of expensive, fast, volatile cache
Larger amount of still fast, but slower, volatile ram Vast amount of inexpensive, not volatile, but slow secondary storage

3 Memory Manager Keeps track of which parts of memory are in use
Allocate memory to processes when needed Deallocate memory when processes complete

4 Monoprogramming Memory is divided between o/s, process, device drivers
o/s signals user when process is finished. Waits for command to load another Two drawbacks: A single process can run. Time wasted waiting on i/o Processes (include o/s) are exposed to malicious or badly written code

5 monoprogramming a) Pre-1960 mainframes b) Embedded systems
c) Early PCs

6 Multiprogramming Run process A when process B is waiting
Degree of multiprogramming Processes spend up to 80% of time waiting for i/o Suppose process spends fraction, t, waiting for i/o If N processes, probability that all are waiting is tN Then CPU use is 1 - tN N is called degree of multiprogramming

7 Example Suppose we want 95% CPU use Suppose we want 90% CPU use
ln 5 – ln 100 = n * (ln 8 – ln 10) N ~ 13.6

8 Multiprograming Requires that we rethink Memory
16 kb program runs alone. Finishes os loads new program. Finishes Now suppose os tries to multiprogram. Instead of evicting old program, adds new one above it. jmp 28 causes an error Problem: both programs reference static, physical addresses -

9 First Things First Multiprogramming requires solution to two problems
protection: process 1 may not overwrite process 2 relocation: remap process memory to different parts of physical memory Address Space The set of addresses available to a process Each process has its own address space Key idea: address 28 in process 1 is not the same physical address as address 28 in process 2

10 Solution to Basic multiprogramming Problem Base and Limit Registers
Simple solution to relocation problem. Base register holds the beginning address of the process Limit register holds length of the process jmp 28 jumps base register + 28

11 Problem Degree of multiprogramming limited by the amount of memory
Windows/OS X/Linux 50 – 100 processes may be started up at boot time Two General Solutions Swapping Load each process Run it for a little while Save it to disk Virtual Memory Load only parts of processes

12 Swapping (Solution 1 to multiprogramming Problem)
Memory allocation changes as processes come into memory and leave it. The shaded regions are unused memory

13 Swapping Issues Problem 1
Swapping creates holes in memory (external fragmentation) Can be relieved through (very expensive) memory compaction Problem 2 Have assumed that programs have a fixed size But many programming languages allow for dynamically allocated memory If free store is adjacent to a process, it can be claimed If not, the growing process will have to be moved to a hole large enough to accommodate it or swapped out and suspended.

14 Size Issue allocate extra space at load time
Distinguish between dynamically allocated heap memory and local stack memory

15 Keeping Track of Growing/Shrinking Memory with bit maps and Linked Lists
A part of memory with five processes and three holes. The tickmarks show the memory allocation units. The shaded regions (0 in the bitmap) are free. The corresponding bitmap Linked list memory management Problems with bit maps Large allocation unit results in holes in the last unit of the process Small allocation unit requires large bitmap Bitmap must be searched at each load to look for the right size space

16 Is X adjacent to another process?
Process Terminates Is X adjacent to another process?

17 Finding a whole large enough for the process
First fit Scan linked list looking for the first whole that is big enough Results in fragmentation Next fit Start search where last search ended to avoid small hole clustering Best fit Scan all of memory looking for the best fit Sounds good, but results in many tiny and useless holes Worst fit OK. Look for the largest available hole. Also produces fragmentation There are other possibilities, including a doubly linked list to make merging easier. Fragmentation is a problem with all possibilites


Download ppt "From Monoprogramming to multiprogramming with swapping"

Similar presentations


Ads by Google