COS122 Tutorial 6 Sept 28-29, 2023 PDF

Summary

This document is a tutorial for COS122, covering memory management. It includes a recap of memory management terms and a section dedicated to memory partitioning techniques.

Full Transcript

CHAPTER 7 MEMORY MANAGEMENT Recap Exercise Questions RECAP : MEMORY MANAGEMENT TERMS Frame A fixed-length block of main memory. A fixed-length block of data that resides in secondary memory Page (such as disk). A page of data may temporarily be copied into a...

CHAPTER 7 MEMORY MANAGEMENT Recap Exercise Questions RECAP : MEMORY MANAGEMENT TERMS Frame A fixed-length block of main memory. A fixed-length block of data that resides in secondary memory Page (such as disk). A page of data may temporarily be copied into a frame of main memory. A variable-length block of data that resides in secondary memory. An entire segment may temporarily be copied into an available Segment region of main memory (segmentation) or the segment may be divided into pages which can be individually copied into main memory (combined segmentation and paging). RECAP MEMORY MANAGEMENT REQUIREMENTS Memory Management is intended to satisfy the following requirements: Logical Physical Relocation Protection Sharing Organization Organization 3 RECAP MEMORY PARTITIONING Technique Description Strengths Weaknesses Main memory is divided into a Inefficient use of memory due to internal number of static partitions at Simple to implement; fragmentation; Fixed Partitioning system generation time. A process little operating system maximum number of may be loaded into a partition of overhead. active processes is equal or greater size. fixed. Inefficient use of Partitions are created dynamically, No internal so that each process is loaded into a fragmentation; more processor due to the Dynamic Partitioning need for compaction to partition of exactly the same size as efficient use of main counter external that process. memory. fragmentation. Main memory is divided into a number of equal-size frames. Each process is divided into a number of equal-size pages of the same length No external A small amount of Simple Paging as frames. A process is loaded by fragmentation. internal fragmentation. loading all of its pages into available, not necessarily contiguous, frames. No internal Each process is divided into a fragmentation; improved number of segments. A process is memory utilization and Simple Segmentation loaded by loading all of its External fragmentation. reduced overhead segments into dynamic partitions that need not be contiguous. compared to dynamic partitioning. As with simple paging, except that No external it is not necessary to load all of the fragmentation; higher Virtual Memory degree of Overhead of complex pages of a process. Nonresident Paging multiprogramming; memory management. pages that are needed are brought in large virtual address later automatically. space. No internal As with simple segmentation, fragmentation, higher except that it is not necessary to degree of Virtual Memory load all of the segments of a Overhead of complex multiprogramming; Segmentation process. Nonresident segments that large virtual address memory management. are needed are brought in later space; protection and automatically. sharing support. RECAP DYNAMIC PARTITIONING PLACEMENT ALGORITHMS Best-fit First-fit Next-fit Chooses the Begins to scan Begins to scan block that is memory from memory from closest in size the beginning the location of to the request and chooses the last the first placement and available block chooses the that is large next available enough block that is large enough BUDDY SYSTEM QUESTION ONE Consider a system with 128KB of memory, initially empty. Requests are received for blocks of memory of 5K, 25K, 35K, and 20K. Show how the buddy system would deal with each request, showing the memory layout at each stage. SOLUTION (1) The buddy system will allocate the smallest block that is large enough to satisfy the request. To achieve the smallest largest block the system efficiently manages memory by dividing it into powers of 2 blocks called buddies into two until the satisfactory block size is achieved. For convenience let Request A = 5k, B = 25k, C = 35k and D =20k SOLUTION (1) The buddy system will allocate the smallest block that is large enough to satisfy the request. To achieve the smallest largest block the system keeps splitting the buddies into two until the satisfactory block size is achieved. For convenience let Request A = 5k, B = 25k, C = 35k and D =20k SOLUTION (1) SOLUTION (1) SOLUTION (1) SOLUTION (1) SOLUTION (1) SOLUTION (1) Request A of 5K will be allocated an 8K block Request B of 25K will be allocated a 32 block Request C of 35K will be allocated a 64K block Request D of 20K block will not be allocated because there is no block big enough to accommodate it. CHAPTER 7: QUESTION TWO The following diagram shows an example of memory configuration under dynamic partitioning, after a number of placement and swapping-out operations have been carried out. Addresses go from left to right; grey areas indicate blocks occupied by processes; white areas indicate free memory blocks. The last process placed is 2 Mbytes and is marked with an X. Only one process was swapped out after that. CHAPTER 7: SOLUTION (2a) What was the maximum size of the swapped-out process? CHAPTER 7: SOLUTION (2a) CHAPTER 7: SOLUTION (2a) When the 2-MB process is placed, it fills the left most portion of the free block selected for placement. Because the diagram shows an empty block to the left of X, the process swapped out after X was placed must have created that empty block. Therefore, the maximum size of the swapped-out process is 2MB. Note: you are free to try other scenarios of other free blocks. CHAPTER 7: SOLUTION (2b) What was the size of the free block just before it was partitioned by X? The free block consisted of the 6MB still empty plus the 2MB space occupied by X, for a total of 8 MB. CHAPTER 7 : SOLUTION (2c) A new 3-Mbyte allocation request must be satisfied next. Indicate the intervals of memory where a partition will be created for the new process under the following four placement algorithms: best-fit, first-fit, next-fit, and worst-fit. For each algorithm, draw a horizontal segment under the memory strip and label it clearly. FF NF WF BF RECAP: PAGING ◼ Partition memory into equal fixed-size chunks that are relatively small ◼ Process is also divided into small fixed-size chunks of the same size RECAP: PAGE TABLE ◼ Maintained by operating system for each process ◼ Contains the frame location for each page in the process ◼ Processor must know how to access for the current process ◼ Used by processor to produce a physical address RECAP: SEGMENTATION CHAPTER 7: QUESTION THREE Consider a computer system that uses paging with a page size of 4 KB. The logical address space for a process is 64 MB, and the physical memory size is 256 MB. a) Determine the total number of bits in the logical address. Note: To make paging convenient it is dictated that the page size and frame size be a power of 2 so we will work in binary (base 2). Note the logical address space is 64MB. But in binary 1KB = 1024 bytes = 210 , 1MB = 220 Therefore, 64MB = (26.220) = (226) bytes. Finally, Number of bits = log 2 (226) = 26 bits Total number of bits in logical address is 26 bits CHAPTER 7: QUESTION (3b) Calculate the number of bits required for the page number and the number of bits for the page offset. Remember page size is 4KB = (22.210) = (212) bytes Hence bits specifying page offset = log 2 (212) = 12 bits Recall that, a logical address has two components (the page number and offset) Thus, the number of bits for the page number = 26 − 12 = 14 bits CHAPTER 7: QUESTION (3c) Find the total number of pages in the logical address space. To find the total number of pages in the logical address space, we need to calculate how many pages of the given page size (4 KB) can fit in the entire 64 MB logical address space: Total pages = Logical address space size / Page Size = 64Mb/4KB = (226)/(212) = (214) 16384 pages CHAPTER 7: QUESTION (3d) Determine the maximum number of page frames available in the physical memory. To find the maximum number of page frames available in physical memory, we divide the physical memory size (256MB) by the page size (4 KB): Max page frames = Physical memory size / Page Size =(28. 220)/(212) = (216) 65536-page frames QUESTIONS? [email protected]

Use Quizgecko on...
Browser
Browser