Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ch. 4 Memory Mangement Parkinson’s law: “Programs expand to fill the memory available to hold them.”

Similar presentations


Presentation on theme: "Ch. 4 Memory Mangement Parkinson’s law: “Programs expand to fill the memory available to hold them.”"— Presentation transcript:

1 Ch. 4 Memory Mangement Parkinson’s law: “Programs expand to fill the memory available to hold them.”

2 Memory hierarchy RegistersCacheRAM How can the OS help processes share RAM? How can the OS help processes share RAM? Hard disk CD, DVD Tape

3 Basic memory management Types: 1. Moves process back and forth between main memory and disk (swapping and paging). 2. Those that do not (move processes back and forth).

4 Basic memory management Monoprogramming w/out swapping or paging only 1 programs runs at a time only 1 programs runs at a time OS is also in memory OS is also in memory load  execute to completion  load next Early mainframes Embedded systems, palmtop computers MS DOS

5 Basic memory management Multiprogramming w/ fixed partitions Divide memory into n fixed size partitions Divide memory into n fixed size partitions All the same size or some larger, some smaller? Single job queue or multiple job queues?

6 Basic memory management Multiprogramming w/ fixed partitions issues: 1. Unused partition space is wasted. 2. Multiple queues partitions (often larger) may go unused partitions (often larger) may go unused 3. Single queue Large partitions wasted on small jobs Large partitions wasted on small jobs Or if we favor larger jobs, smaller (often interactive) jobs may be starved. Or if we favor larger jobs, smaller (often interactive) jobs may be starved.

7 Modeling multiprogramming Let p be the probability that a process waits on I/O. Given n such processes, what is the probability that all n processes are waiting on I/O at the same time? p 1 * p 2 * … * p n = p n p 1 * p 2 * … * p n = p n Therefore, for a given p and n, the CPU utilization = 1-p n (Assumes that all n processes are independent but that is not the case for 1 CPU or if we need exclusive I/O! But we’ll employ the “ostrich algorithm and live with it!)

8 CPU utilization Given that we have enough memory to support 10 processes and each process spends 80% of its time doing I/O, what’s CPU utilization?

9 CPU utilization Given that we have enough memory to support 10 processes and each process spends 80% of its time doing I/O, what’s CPU utilization? Given n=10, p=0.80 Given n=10, p=0.80 So CPU utilization = 1-0.8 10 So CPU utilization = 1-0.8 10 (about 0.90 or 90%) (about 0.90 or 90%)

10 CPU utilization

11 Suppose we have 32MB. The OS uses 16MB. Each user program uses 4MB and has an 80% I/O wait. How many users, n, can we support in memory at once? Given the above n, what is our CPU utilization?

12 CPU utilization Suppose we have 32MB. The OS uses 16MB. Each user program uses 4MB and has an 80% I/O wait. How many users, n, can we support in memory at once? 4 = (32-16)/4 4 = (32-16)/4 Given the above n, what is our CPU utilization? (1-0.80 4 )=0.60 or 60% (1-0.80 4 )=0.60 or 60% What is our CPU utilization if we add 16M?

13 CPU utilization Now we have 48MB. The OS uses 16MB. Each user program uses 4MB and has an 80% I/O wait. How many users, n, can we support in memory at once? 8 = (48-16)/4 8 = (48-16)/4 Given the above n, what is our CPU utilization? (1-0.80 8 )=0.83 or 83% (1-0.80 8 )=0.83 or 83% So we went from 60% to 83% with 16M more. So we went from 60% to 83% with 16M more. What is our CPU utilization if we add 16M?

14 CPU utilization Now we have 64MB. The OS uses 16MB. Each user program uses 4MB and has an 80% I/O wait. How many users, n, can we support in memory at once? 12 = (64-16)/4 12 = (64-16)/4 Given the above n, what is our CPU utilization? (1-0.80 12 )=0.93 or 93% (1-0.80 12 )=0.93 or 93% So we went from 83% to 93% with 16M more. So we went from 83% to 93% with 16M more.

15 Relocation and protection Relocation – a program should be able to execute in any partition of memory (starting at any physical address) Protection – a process should have read/write access to data memory, read access to its own code memory, read access to some parts of the OS, and no access to other parts Base/limit registers = early method

16 swapping We want more processes than memory! 2 solutions: 1. Swapping 1.bring in each process in its entirety 2.run it for a while 3.put it back on disk 2. Virtual memory (paging)

17 swapping Memory compaction (like disk fragmentation) memory may become fragmented into little pieces so we may have to more all processes down into lowest memory. memory may become fragmented into little pieces so we may have to more all processes down into lowest memory.

18 swapping

19 swapping What if the memory needs of a process changes over time?

20 swapping Memory management – How do we keep track of what memory is being used and what memory is available? 1. Bitmaps 2. Linked lists

21 Swapping: memory management w/ bitmaps Divide memory into equal size allocation units (e. g., 1K “chunks”). Bit = 0 means the chunk is free; bit = 1 means that chunk is in use. Small chunks -> large bitmap Large chunks -> small bitmap Large chunks -> waste Large chunks -> waste

22 Swapping: memory management w/ linked lists Linked list of allocated and free memory segments. Segment = memory used by process or hole (free memory) between processes Segment = memory used by process or hole (free memory) between processes Usually sorted by address Usually sorted by address May be implemented as one list (of both used and free) as as two separate lists May be implemented as one list (of both used and free) as as two separate lists

23 Swapping: memory management w/ linked lists Allocation methods: 1. First fit – simple, fast; leaves large holes 2. Next fit – continue searching from where ff last left off 3. Best fit – slower than ff; wastes memory = leaves many small, useless holes 4. Worst fit – not very good 5. Quick fit – keeps lists with common hole sizes

24 Virtual memory


Download ppt "Ch. 4 Memory Mangement Parkinson’s law: “Programs expand to fill the memory available to hold them.”"

Similar presentations


Ads by Google