1 / 41

Net 321 : Computer Operating System

Net 321 : Computer Operating System. Lecture # 8 : Main Memory part 2. Chapter 8: Main Memory. Swapping.

inge
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. 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. • 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 • A variant of this swapping policy is used for priority-based scheduling algorithms. This variant of swapping is sometimes called roll out, roll in.

  4. Schematic View of Swapping (figure 8.5)

  5. 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.

  6. 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 – 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.

  7. 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

  8. 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.

  9. 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

  10. Example of fixed partitioning of 64-Mbyte memory

  11. Memory assignment for fixed portioning

  12. 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)

  13. 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

  14. The effect of dynamic partitioning

  15. 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

  16. 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

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

  18. 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

  19. 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

  20. Last allocated block (14M) To allocate 16M Block

  21. 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

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

  23. 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

  24. 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

  25. 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

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

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

  28. 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

  29. 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

  30. 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

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

  32. 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

  33. 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

  34. 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

  35. 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

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

  37. 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

  38. 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

  39. 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

  40. 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

  41. Fragmentation • External Fragmentation– total memory space exists to satisfy a request, but it is not contiguous • Internal Fragmentation– allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used • 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.

More Related