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 MEMORYThe primary memory access time must be as small as possible. This need influences both software and hardware designThe 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 isThe 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 isto allocate primary memory space to processesto map the process address space into the allocated portion of the primary memoryto minimize access times using a cost- effective amount of primary memory
4 Memory allocationIn 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 Fitii. Buddy SystemIii. 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 FitBest FitWorst FitWhen 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 fitFirst 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
8 first fit OS P1 12 KB <FREE> 10 KB P2 20 KB <FREE> 16 KB P4 of 3KBarrives
9 first fit OS P1 12 KB P4 3 KB <FREE> 7 KB P2 20 KB P4 of 3KBloaded here byFIRST FIT
10 first fit OS P1 12 KB P4 3 KB <FREE> 7 KB P2 20 KB P5 of 15KBarrives
11 first fit OS P1 12 KB P4 3 KB <FREE> 7 KB P2 20 KB P5 15 KB P5 of 15 KBloaded here byFIRST FIT
12 Best fitBest 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.
14 best fit OS P1 12 KB <FREE> 10 KB P2 20 KB <FREE> 16 KB P4 of 3KBarrives
15 best fit OS P1 12 KB <FREE> 10 KB P2 20 KB <FREE> 16 KB P4 of 3KBloaded here byBEST FIT
16 best fit OS P1 12 KB <FREE> 10 KB P2 20 KB <FREE> 16 KB P5 of 15KBarrives
17 best fit OS P1 12 KB <FREE> 10 KB P2 20 KB P5 15 KB P5 of 15 KBloaded here byBEST FIT
18 worst fitWorst 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.
20 worst fit OS P1 12 KB <FREE> 10 KB P2 20 KB <FREE> 16 KB P4 of 3KBarrives
21 worst fit OS P1 12 KB <FREE> 10 KB P2 20 KB P4 3 KB P4 of 3KBLoaded here byWORST 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 15KCompaction is needed !!
24 compactionCompaction 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
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 compactionNow 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 KBP5 of 15KB is loaded
34 relocationStatic relocation: A process may be loaded into memory, each time possibly having a different starting addressNecessary for variable partitioningDynamic relocation: In addition to static relocation, the starting address of the process may change while it is already loaded in memoryNecessary for compaction
35 Buddy SystemThe 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 SuballocatorsA 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 requirementsTo provide memory management services that the system memory manager does not supply.
37 Memory Manager Strategies 1. SwappingTo 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 RelocationRefers to address transformations being done during execution of a program.
39 Tutorial Define memory allocation Quest of Nov2011Define memory allocationGive 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 memoryDefine what is best fit, worst fit and first fit.Quest of Nov2011Quest of Nov2011Quest of Nov2010