Download presentation
1
Chapter 6: Memory Management
2
Basics Requirements that drive memory designs
Purpose of memory manager is to administer the use the use of the primary memory. Primary memory and CPU are the fundamental resources used by every process. REQUIREMENT ON PRIMARY MEMORY The primary memory access time must be as small as possible. This need influences both software and hardware design The primary memory must be as large as possible. Using virtual memory, software and hardware can make the memory appear to be larger than it actually is The primary memory must be cost-effective. The cost cannot be more than a small percentage of the total cost of the computer.
3
3 Functions of Memory Manager
The purpose of the memory manager is to allocate primary memory space to processes to map the process address space into the allocated portion of the primary memory to minimize access times using a cost- effective amount of primary memory
4
Memory allocation In an environment that supports dynamic memory allocation, the memory manager must keep a record of the usage of each allocatable block of memory. Memory allocation is the process assigning blocks of memory on request. There are 3 memory allocation: i. First Fit, Worst Fit, Best Fit ii. Buddy System Iii. Suballocators
5
3.2 Variable Partitioning
There are three algorithms for searching the list of free (free list) blocks for a specific amount of memory. First Fit Best Fit Worst Fit When recycling free blocks, there is a choice as to where to add the blocks to the free list. Free list kept: Memory allocation(address) Increasing size(best fit) Decreasing size (worst fit) Increasing time
6
first fit First Fit : Allocate the first free block that is large enough for the new process. This is a fast algorithm. Another strategy is first fit, which simply scans the free list until a large enough hole is found. Despite the name, first-fit is generally better than best-fit because it leads to less fragmentation. Variation of first fit known ad next fit, continues each search for a suitable block
7
Initial memory mapping
first fit OS P1 12 KB <FREE> 10 KB P2 20 KB <FREE> 16 KB P3 6 KB <FREE> 4 KB Initial memory mapping
8
first fit OS P1 12 KB <FREE> 10 KB P2 20 KB <FREE> 16 KB
P4 of 3KB arrives
9
first fit OS P1 12 KB P4 3 KB <FREE> 7 KB P2 20 KB
P4 of 3KB loaded here by FIRST FIT
10
first fit OS P1 12 KB P4 3 KB <FREE> 7 KB P2 20 KB
P5 of 15KB arrives
11
first fit OS P1 12 KB P4 3 KB <FREE> 7 KB P2 20 KB P5 15 KB
P5 of 15 KB loaded here by FIRST FIT
12
Best fit Best Fit : Allocate the smallest block among those that are large enough for the new process. In this method, the OS has to search the entire list, or it can keep it sorted and stop when it hits an entry which has a size larger than the size of new process. This algorithm produces the smallest left over block. Problem: Requires more time for searching all the list or sorting it. It leads to the creation of lots of little holes that are not big enough to satisfy any requests. This situation is called fragmentation, and is a problem for all memory- management strategies, although it is particularly bad for best-fit.
13
Initial memory mapping
best fit OS P1 12 KB <FREE> 10 KB P2 20 KB <FREE> 16 KB P3 6 KB <FREE> 4 KB Initial memory mapping
14
best fit OS P1 12 KB <FREE> 10 KB P2 20 KB <FREE> 16 KB
P4 of 3KB arrives
15
best fit OS P1 12 KB <FREE> 10 KB P2 20 KB <FREE> 16 KB
P4 of 3KB loaded here by BEST FIT
16
best fit OS P1 12 KB <FREE> 10 KB P2 20 KB <FREE> 16 KB
P5 of 15KB arrives
17
best fit OS P1 12 KB <FREE> 10 KB P2 20 KB P5 15 KB
P5 of 15 KB loaded here by BEST FIT
18
worst fit Worst Fit : Allocate the largest block among those that are large enough for the new process. The memory manager places process in the largest block of unallocated memory available. The ideas is that this placement will create the largest hole after the allocations, thus increasing the possibility that, compared to best fit, another process can use the hole created as a result of external fragmentation.
19
Initial memory mapping
worst fit OS P1 12 KB <FREE> 10 KB P2 20 KB <FREE> 16 KB P3 6 KB <FREE> 4 KB Initial memory mapping
20
worst fit OS P1 12 KB <FREE> 10 KB P2 20 KB <FREE> 16 KB
P4 of 3KB arrives
21
worst fit OS P1 12 KB <FREE> 10 KB P2 20 KB P4 3 KB
P4 of 3KB Loaded here by WORST FIT
22
worst fit OS P1 12 KB <FREE> 10 KB P2 20 KB P4 3 KB
No place to load P5 of 15K
23
worst fit OS P1 12 KB <FREE> 10 KB P2 20 KB P4 3 KB
No place to load P5 of 15K Compaction is needed !!
24
compaction Compaction is a method to overcome the external fragmentation problem. All free blocks are brought together as one large block of free space. Compaction requires dynamic relocation. Certainly, compaction has a cost and selection of an optimal compaction strategy is difficult. One method for compaction is swapping out those processes that are to be moved within the memory, and swapping them into different memory locations
25
Memory mapping before compaction
OS P1 12 KB <FREE> 10 KB P2 20 KB P4 3 KB <FREE> 13 KB P3 6 KB <FREE> 4 KB Memory mapping before compaction
26
compaction OS P1 12 KB P2 20 KB P4 3 KB P3 6 KB Secondary storage
Swap out P2
27
compaction OS P1 12 KB P2 20 KB P4 3 KB Swap in P3 6 KB P2 Secondary
storage
28
compaction OS P1 12 KB P2 20 KB P4 3 KB P3 6 KB Secondary storage
Swap out P4
29
compaction OS P1 12 KB P2 20 KB P4 3 KB P3 6 KB Secondary Swap in
storage Swap in P4 with a different starting address
30
compaction OS P1 12 KB P2 20 KB P4 3 KB P3 6 KB Secondary storage
Swap out P3
31
compaction OS P1 12 KB P2 20 KB P4 3 KB P3 6 KB Swap in P3 Secondary
storage
32
compaction OS P1 12 KB P2 20 KB P4 3 KB P3 6 KB <FREE> 27 KB
Memory mapping after compaction Now P5 of 15KB can be loaded here
33
compaction OS P1 12 KB P2 20 KB P4 3 KB P3 6 KB P5 12 KB
<FREE> 12 KB P5 of 15KB is loaded
34
relocation Static relocation: A process may be loaded into memory, each time possibly having a different starting address Necessary for variable partitioning Dynamic relocation: In addition to static relocation, the starting address of the process may change while it is already loaded in memory Necessary for compaction
35
Buddy System The allocator will only allocates blocks of certain sizes and has many free lists, one for each permitted size. The permitted sizes are usually either powers of 2, such that any block except the smallest can be divided into two smaller blocks of permitted sizes. Advantages: coalescence is cheap because buddy of any free block can be calculates from its address. See eg 6.2.2
36
Suballocators A suballocator obtains large blocks of memory from the system memory manager and allocates the memory to the application in smaller pieces. Function suballocator: To avoid general inefficiency in the system memory manager. To take advantage of special knowledge of the application’s memory requirements To provide memory management services that the system memory manager does not supply.
37
Memory Manager Strategies
1. Swapping To optimize system performance by removing a process from primary memory. RAM has limited capacity. Virtual memory as additional of RAM. The area hard disk used for virtual memory is called swap file. When more RAM space is needed, the OS swaps out from RAM and moved to virtual memory. The technique of swapping items between memory and storage called paging.
38
2. Virtual Memory Dynamic Relocation
Allow a process to use the CPU when only part of its address space is loaded in the primary memory. Dynamic Relocation Refers to address transformations being done during execution of a program.
39
Tutorial Define memory allocation
Quest of Nov2011 Define memory allocation Give three way to allocate memory in our system. Explain 3 functions that must be performed by memory manager in order to execute program and data. List three basic requirements of designing primary memory. List 2 strategies to manage memory Define what is best fit, worst fit and first fit. Quest of Nov2011 Quest of Nov2011 Quest of Nov2010
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.