1 / 51

Net 321 : Computer Operating System

Net 321 : Computer Operating System. Lecture # 8 : Main Memory part 2. Chapter 8: Main Memory. BUT – what if the program is still too big ???.

kylene
Download Presentation

Net 321 : Computer Operating System

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Net 321 :Computer Operating System Lecture # 8 : Main Memory part 2 Networks and Communication Department

  2. Chapter 8: Main Memory

  3. BUT – what if the program is still too big ??? • OR – if you are in a multiprogramming environment and can't get enough code of any program in main memory to run (when have pieces of all processes in memory) • One way to solve is SWAPPING (a memory management technique, not multiprogramming technique, used to change the mix of jobs)

  4. Swapping • A process must be in memory to be executed. A process, however, can be swapped temporarily out of memory to a backing store (disk) and then brought back into memory for continued execution. • Use variants of CPU scheduling algorithms (RR, priority, etc.) to decide which processes swap out Example 1 : A round-robin CPU-scheduling algorithm; when a quantum expires (see Fig. 8.5), • The memory manager will start to swap out the process that just finished • and to swap another process into the memory space that has been freed. • In the meantime, the CPU scheduler will allocate a time slice to some other process in memory. • When each process finishes its quantum, it will be swapped with another process Example 2 : A variant of this swapping policy is used for priority-based scheduling algorithms. This variant of swapping is sometimes called roll out, roll in. • Lower-priority process is swapped out so higher-priority process can be loaded and executed

  5. Schematic View of Swapping (figure 8.5)

  6. Swapping cont. • Normally, a process that is swapped out will be swapped back into the same memory space it occupied previously. • This restriction is dictated by the method of address binding. • If binding is done at assembly or load time, then the process cannot be easily moved to a different location. • If execution-time binding is being used, however, then a process can be swapped into a different memory space, because the physical addresses are computed during execution time. • Swapping is constrained by other factors as well. If we want to swap a process, we must be sure that it is completely idle.

  7. Memory management methods

  8. 1.Contiguous Allocation • The memory is usually divided into two partitions: • one for the resident OS • one for the user processes. • We usually want several user processes to reside in memory at the same time. We therefore need to consider how to allocate available memory to the processes that are in the input queue waiting to be brought into memory. • Input queue (job queue )– collection of processes on the disk that are waiting to be brought into memory to run the program • In this contiguous memory allocation, each process is contained in a single contiguous section of memory.

  9. Contiguous Allocation (Cont.) 1. Equal-size partitions • One of the simplest methods for allocating memory is to divide memory into several fixed-sized partitions. Each partition may contain exactly one process. • Thus, the degree of multiprogramming is bound by the number of partitions(any process whose size is less than or equal to the partition size can be loaded into an available partition) • When a partition is free, a process is selected from the input queue and is loaded into the free partition. • When the process terminates, the partition becomes available for another process. • If all partitions are full, the operating system can swap a process out of a partition • A program may not fit in a partition. The programmer must design the program with overlays

  10. Contiguous Allocation (Cont.) • Main memory use is inefficient. Any program, no matter how small, occupies an entire partition. This is called internal fragmentation. • E.g: A program of size 2MB occupies an 8MB partition  wasted space internal to a partition, as the data loaded is smaller than the partition size • This method is no longer in use.

  11. Contiguous Allocation (Cont.) 2.Unequal-size partitions (also fixed) • Can assign each process to the smallest partition within which it will fit • Queue for each partition • Processes are assigned in such a way as to minimize wasted memory within a partition • In equal-size partitions because all partitions are of equal size, it does not matter which partition is used

  12. Example of fixed partitioning of 64-Mbyte memory

  13. Memory assignment for fixed portioning

  14. Contiguous Allocation (Cont.) 3. Dynamic allocation • Initially, all memory is available for user processes and is considered one large block of available memory, a hole. • Hole – block of available memory; holes of various size are scattered throughout memory • When a process arrives and needs memory, we search for a hole large enough for this process. • If we find one, we allocate only as much memory as is needed, keeping the rest available to satisfy future requests • Partitions are of variable length and number • Eventually get holes in the memory. This is called external fragmentation • Operating system maintains information about:a) allocated partitions b) free partitions (hole)

  15. Contiguous Allocation (Cont.) OS OS OS OS process 5 process 5 process 5 process 5 process 9 process 9 process 8 process 10 process 2 process 2 process 2 process 2

  16. The effect of dynamic partitioning

  17. Contiguous Allocation (Cont.) Dynamic Partitioning Placement Algorithm • Operating system must decide which free block to allocate to a process • Best-fit • Worst-fit • First-fit • Next-fit • First-fit and best-fit better than worst-fit in terms of speed and storage utilization

  18. Best-fit algorithm • Allocate the smallest hole that is big enough; must search entire list • Produces the smallest leftover hole. • Chooses the block that is closest in size to the request • Worst performer overall • Since smallest block is found for process, the smallest amount of fragmentationisleft • Memory compaction must be done more often

  19. Worst-fit algorithm • Allocate the largest hole; must also search entire list. • Produces the largest leftover hole. • Worst performer overall

  20. First-fit algorithm • Allocate the first hole that is big enough • Scans memory form the beginning and chooses the first available block that is large enough • Fastest • May have many process loaded in the front end of memory that must be searched over when trying to find a free block

  21. Next-fit algorithm • Scans memory from the location of the last placement • More often allocate a block of memory at the end of memory where the largest block is found

  22. Last allocated block (14M) Worst Fit To allocate 16M Block

  23. 10K 20K 20K 20K 10K 10K 20K Example • The shaded areas are allocated blocks; the white areas are free blocks. • The next FOUR memory requests are 20K, 50K, 10K and 30K (loaded in that order). • Using the following placement algorithms, show the partition allocated for the requests. • First-fit • Best-fit • Next-fit • Worst-fit

  24. 10K 20K 20K 20K 10K 10K 20K Example: First-fit 20 • 20K, 50K, 10K and 30K (in that order). • Allocate for 20K

  25. 10K 20K 20K 20K 10K 10K 20K Example: First-fit 20 50 • 20K, 50K, 10K and 30K (in that order). • Allocate for 20K • Allocate for 50K

  26. 10 10K 20K 20K 20K 10K 10K 20K Example: First-fit 20 50 • 20K, 50K, 10K and 30K (in that order). • Allocate for 20K • Allocate for 50K • Allocate for 10K

  27. 10 10K 20K 20K 20K 10K 10K 20K Example: First-fit 30 20 50 • 20K, 50K, 10K and 30K (in that order). • Allocate for 20K • Allocate for 50K • Allocate for 10K • Allocate for 30K

  28. 10K 20K 20K 20K 10K 10K 20K Example: Best-fit • 20K, 50K, 10K and 30K (in that order).

  29. 10K 20K 20K 20K 10K 10K 20K Example: Best-fit 20 • 20K, 50K, 10K and 30K (in that order). • Allocate for 20K

  30. 10K 20K 20K 20K 10K 10K 20K Example: Best-fit 20 50 • 20K, 50K, 10K and 30K (in that order). • Allocate for 20K • Allocate for 50K

  31. 10 10K 20K 20K 20K 10K 10K 20K Example: Best-fit 20 50 • 20K, 50K, 10K and 30K (in that order). • Allocate for 20K • Allocate for 50K • Allocate for 10K

  32. 10 10K 20K 20K 20K 10K 10K 20K Example: Best-fit 30 20 50 • 20K, 50K, 10K and 30K (in that order). • Allocate for 20K • Allocate for 50K • Allocate for 10K • Allocate for 30K

  33. 10K 20K 20K 20K 10K 10K 20K Example: Next-fit • 20K, 50K, 10K and 30K (in that order). most recently added block

  34. 10K 20K 20K 20K 10K 10K 20K Example: Next-fit 20 • 20K, 50K, 10K and 30K (in that order). • Allocate for 20K most recently added block

  35. 10K 20K 20K 20K 10K 10K 20K Example: Next-fit 20 50 • 20K, 50K, 10K and 30K (in that order). • Allocate for 20K • Allocate for 50K most recently added block

  36. 10 10K 20K 20K 20K 10K 10K 20K Example: Next-fit 50 20 • 20K, 50K, 10K and 30K (in that order). • Allocate for 20K • Allocate for 50K • Allocate for 10K most recently added block

  37. 10 10K 20K 20K 20K 10K 10K 20K Example: Next-fit 50 20 30 • 20K, 50K, 10K and 30K (in that order). • Allocate for 20K • Allocate for 50K • Allocate for 10K • Allocate for 30K most recently added block

  38. 10K 20K 20K 20K 10K 10K 20K Example: Worst fit • 20K, 50K, 10K and 30K (in that order).

  39. 10K 20K 20K 20K 10K 10K 20K Example: Worst fit 20 • 20K, 50K, 10K and 30K (in that order). • Allocate for 20K most recently added block

  40. 10K 20K 20K 20K 10K 10K 20K Example: Worst fit 50 20 • 20K, 50K, 10K and 30K (in that order). • Allocate for 20K • Allocate for 50K most recently added block

  41. 10 10K 20K 20K 20K 10K 10K 20K Example: Worst fit 20 50 • 20K, 50K, 10K and 30K (in that order). • Allocate for 20K • Allocate for 50K • Allocate for 10K most recently added block

  42. 10 10K 20K 20K 20K 10K 10K 20K Example: Worst fit 20 30 50 • 20K, 50K, 10K and 30K (in that order). • Allocate for 20K • Allocate for 50K • Allocate for 10K • Allocate for 30K most recently added block

  43. Fragmentation • External Fragmentation– total memory space exists to satisfy a request, but it is not contiguous • Equal sized partition and unequal sized partition • Internal Fragmentation– allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used • Dynamic allocation

  44. Fragmentation cont. • Solutions : • One solution to the problem of external fragmentation is compaction. The goal is to shuffle the memory contents so as to place all free memory together in one large block. • The simplest compaction algorithm is to move all processes toward one end of memory; all holes move in the other direction, producing one large hole of available memory. This scheme can be expensive. • Another possible solution to the external-fragmentation problem is to permit the logical address space of the processes to be non-contiguous, thus allowing a process to be allocated physical memory wherever the latter is available.

  45. 5K 100K 100K 10K Extra Example • The shaded areas are allocated blocks; the white areas are free blocks. • The next FOUR memory requests are 20K, 5K, 35K and 50K (loaded in that order). • Using the following placement algorithms, show the partition allocated for the requests. • First-fit • Best-fit • Next-fit • Worst-fit most recently added block

  46. Extra example (8.16 at textbook) • Given five memory partitions of 100 KB, 500 KB, 200 KB, 300 KB, and 600 KB (in order), how would each of the first-fit, best-fit, and worst-fit algorithms place processes of 212 KB, 417 KB, 112 KB, and 426 KB (in order)?Which algorithm makes the most efficient use of memory?

  47. Extra example (8.16 at textbook) Answer: • Let p1, p2, p3 & p4 are the names of the processes • First-fit: • P1>>> 100, 500, 200, 300, 600 • P2>>> 100, 288, 200, 300, 600 • P3>>> 100, 288, 200, 300, 183 • 100, 116, 200, 300, 183 <<<<< final set of hole • P4 (426K) must wait • Best-fit: • P1>>> 100, 500, 200, 300, 600 • P2>>> 100, 500, 200, 88, 600 • P3>>> 100, 83, 200, 88, 600 • P4>>> 100, 83, 88, 88, 600 • 100, 83, 88, 88, 174 <<<<< final set of hole

  48. Extra example (8.16 at textbook) • Worst-fit: • P1>>> 100, 500, 200, 300, 600 • P2>>> 100, 500, 200, 300, 388 • P3>>> 100, 83, 200, 300, 388 • 100, 83, 200, 300, 276 <<<<< final set of hole • P4 (426K) must wait • In this example, Best-fit turns out to be the best because there is no wait processes.

  49. Fixed and dynamic partitions advantages and disadvantages

  50. FIXED PARTITIONS • Advantages: • Allows multiprogramming • Compared with single partition systems - • Less wasted space • Better memory utilization • Better processor and I/O utilization • Context Switching faster than Swapping • Disadvantages: • Internal Fragmentation (unused memory inside partitions) • Number of concurrent processes limited by number of partitions • Program limited to size of largest partition

More Related