Download presentation
Presentation is loading. Please wait.
1
Chapter3 Memory Management Techniques
2
What is meant by memory management and how to manage memory?
Ready Queue Process need to be executed Memory management is how to organize active processes (processes currently in the ready queue) so that: Processes can be easily reached. Maximize memory space utilization.
3
Show how a loader stores an executable file into the memory assuming:
File of Size =20 memory words (instructions and data). Using Contiguous allocation method. Repeat the problem three different times using: First fit. Best fit. Worst Fit. Executable file (Size =20 memory words) Memory Loader ?
4
Using First Fit Memory OS Process Process Process Process Process
OS 1040 20 Base Limit Start address of process Legal range 999 1000 1010 Process 1040 Process 1060 Executable file (Size =20 memory words) 1070 Process 1100 1125 Process 1150 Loader 1200 Process 1250 1255
5
Using Best Fit Memory OS Process Process Process Process Process
1100 20 Base Limit Start address of process Legal range 1000 1010 Process 1040 Executable file (Size =20 memory words) 1070 Process 1100 Process 1120 1125 Process Loader 1150 1200 Process 1250 1255
6
Using Worst Fit Memory OS Process Process Process Process Process
1150 20 Base Limit Start address of process Legal range 1000 1010 Process 1040 Executable file (Size =20 memory words) 1070 Process 1100 1125 Process Loader 1150 Process 1170 1200 Process 1250 1255
7
How to manage memory in multi-programming environment?
Memory Management In multi-programming environment Paging Swapping Contiguous allocation
8
Swapping: A process can be swapped out of memory to disk, and then brought back into memory for continued execution.
9
Multi-programming environment with “priority scheduling”
Ex1: Multi-programming environment with “priority scheduling” Assume a system with 32 kb memory size. 5kb are used for OS, 10 kb for the low priority process. Hence, the available space is 17 kb. A higher priority process arrives and needs 20 kb. OS (5 kb) Low Priority process (10 kb) Available 17 Kb 27 Kb High Priority process (20 kb) 7 Kb Swap in the high priority process high priority process finishes execution Swap out the low priority process to disk Disk Swap in the low priority process again to resume execution High Priority 20 Kb
10
Contiguous Allocation
What is meant by contiguous allocation, what are its different types? In contiguous allocation, each process is contained in a single contiguous section of memory.
11
Methods for Contiguous Allocation
Simple Method General Method
12
Simple Method Divide memory into several fixed-sized partitions.
Each partition contains one process. Degree of multiprogramming is bound by the number of partitions. 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. its no longer used because it has various drawbacks like: Degree of multiprogramming is bounded by the number of partitions. Internal fragmentations.
13
As shown This method suffers from internal fragmentations.
Assuming a memory of 30 KB divided into three partitions as following: Process 1 (7 KB) Input Queue (in the disk) 10 KB Internal Fragmentation Process 2 (9 KB) 4 KB 8 KB 9 KB 7 KB 10 KB Process 3 (8 KB) 10 KB As shown This method suffers from internal fragmentations. The degree of multiprogramming is bounded to 3 although it can be 4.
14
General Method Initially, all memory is available for user processes, and is considered as one large block of available memory. When a process arrives and needs memory, we search for a hole large enough for this process using. If we find one, we allocate only as much memory as is needed, keeping the rest available to satisfy future requests. First Fit Best Fit Worst Fit
15
X There are three different methods to find the suitable hole for a process?: First fit: allocate the first hole that is big enough (fastest method). Best fit: allocate the smallest hole that is big enough (produces the smallest leftover hole). Worst fit: allocate the largest hole (produces the largest leftover hole which may be more useful than the smaller leftover hole from a best-fit approach.
16
OS Process 4 (4 KB) Process 1 (7 KB) Input Queue (in the disk) Process 5 (9 KB) Process 2 (9 KB) 9 KB 4 KB 8 KB 9 KB 7 KB Process 3 (8 KB) As shown: The degree of multiprogramming changing according to the number of processes in the memory (in ready queue).
17
After a period of time External Fragmentations appear
OS Process 4 Input Queue (in the disk) Process 2 External Fragmentations Process 3 4 KB 8 KB 9 KB 7 KB Process 9 Process 20 As shown: This method suffers from external Fragmentations.
18
Compaction OS OS Compaction:
Process 2 Process 3 OS Process 4 Process 9 Process 20 OS Process 4 Input Queue (in the disk) Process 2 Process 3 4 KB 8 KB 9 KB 7 KB Process 9 A new hole to store a new process Process 20 Compaction: Is a movement of the memory contents to place all free memory in a one large block sufficient to store new process. It is a solution for the external fragmentation but it is expensive and is not always possible.
19
Paging Paging is a memory-management scheme that permits the physical-address space of a process to be noncontiguous. it is commonly used in most operating systems. Divide physical memory into fixed-sized blocks called frames. Divide Process into blocks of same size called pages. Use a page table which contains base address of each page in physical memory. X
20
Example A process P is divided into 4 pages.
1 2 3 Page number Page number Frame number Process P The process will be loaded into 4 frames. The page number is used as index to the page table. The page table contains the frame number for each page.
21
Paging Example Sol: Memory size=32 Byte =32 words.
32-byte memory, each memory word of size =1 byte (can store only one character), the size of page (and frame also)= 4-byte. Show how to store 4 pages process into memory using a page table. according to your page table, what are the physical addresses corresponding to the logical addresses 4 and 13. Sol: Memory size=32 Byte =32 words. Page size = Frame size = 4 bytes =4 words. Number of Frames = 32/4 = 8 Frames (addressed from 0 7)
22
Logical address Page 0 Contents Physical address Page 0 Page 1 Page 2 Page 3 4 Page process Frame 0 Frame 1 Frame 2 Frame 3 Frame 4 Frame 5 Frame 6 Frame 7
23
Advantages of paging: Problems in paging: No external fragmentation.
Allow the process components to be noncontiguous. Problems in paging: A possibility of internal fragmentations that can not be used. Q: Explain when you have internal fragmentations when using the paging technique. Sol: when the contents of the last page of the process is less than the frame size, then the remaining part of the frame will be an internal fragmentations that can not be used.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.