Presentation on theme: " 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."— Presentation transcript:
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. 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.
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
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
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 5
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 6
OS P1 12 KB 10 KB P2 20 KB 16 KB P3 6 KB 4 KB 8 P4 of 3KB arrives P4 of 3KB arrives
OS P1 12 KB P4 3 KB 7 KB P2 20 KB 16 KB P3 6 KB 4 KB 9 P4 of 3KB loaded here by FIRST FIT P4 of 3KB loaded here by FIRST FIT
OS P1 12 KB P4 3 KB 7 KB P2 20 KB 16 KB P3 6 KB 4 KB 10 P5 of 15KB arrives P5 of 15KB arrives
OS P1 12 KB P4 3 KB 7 KB P2 20 KB P5 15 KB 1 KB P3 6 KB 4 KB 11 P5 of 15 KB loaded here by FIRST FIT P5 of 15 KB loaded here by FIRST 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. 12
OS P1 12 KB 10 KB P2 20 KB 16 KB P3 6 KB 4 KB 14 P4 of 3KB arrives P4 of 3KB arrives
OS P1 12 KB 10 KB P2 20 KB 16 KB P3 6 KB P4 3 KB 1 KB 15 P4 of 3KB loaded here by BEST FIT P4 of 3KB loaded here by BEST FIT
OS P1 12 KB 10 KB P2 20 KB 16 KB P3 6 KB P4 3 KB 1 KB 16 P5 of 15KB arrives P5 of 15KB arrives
OS P1 12 KB 10 KB P2 20 KB P5 15 KB 1 KB P3 6 KB P4 3 KB 1 KB 17 P5 of 15 KB loaded here by BEST FIT P5 of 15 KB loaded here by BEST 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. 18
OS P1 12 KB 10 KB P2 20 KB 16 KB P3 6 KB 4 KB 20 P4 of 3KB arrives P4 of 3KB arrives
OS P1 12 KB 10 KB P2 20 KB P4 3 KB 13 KB P3 6 KB 4 KB 21 P4 of 3KB Loaded here by WORST FIT P4 of 3KB Loaded here by WORST FIT
OS P1 12 KB 10 KB P2 20 KB P4 3 KB 13 KB P3 6 KB 4 KB 22 No place to load P5 of 15K
OS P1 12 KB 10 KB P2 20 KB P4 3 KB 13 KB P3 6 KB 4 KB 23 No place to load P5 of 15K Compaction is needed !!
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.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 24
OS P1 12 KB P2 20 KB P4 3 KB P3 6 KB 26 Swap out P2 Secondary storage
OS P1 12 KB P2 20 KB P4 3 KB P3 6 KB 27 Swap in P2 Secondary storage
OS P1 12 KB P2 20 KB P4 3 KB P3 6 KB 28 Swap out P4 Secondary storage
OS P1 12 KB P2 20 KB P4 3 KB P3 6 KB 29 Swap in P4 with a different starting address Secondary storage
OS P1 12 KB P2 20 KB P4 3 KB P3 6 KB 30 Swap out P3 Secondar y storage
OS P1 12 KB P2 20 KB P4 3 KB P3 6 KB 31 Swap in P3 Secondar y storage
OS P1 12 KB P2 20 KB P4 3 KB P3 6 KB 27 KB 32 Memory mapping after compaction Now P5 of 15KB can be loaded here
OS P1 12 KB P2 20 KB P4 3 KB P3 6 KB P5 12 KB 12 KB 33 P5 of 15KB is loaded
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 34
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
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.
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.
Allow a process to use the CPU when only part of its address space is loaded in the primary memory. Refers to address transformations being done during execution of a program.
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 Nov2010 Quest of Nov2011