In operating system, following are four common memory management techniques.
Single contiguous allocation: Simplest allocation method used by MS-DOS. All memory (except some reserved for OS) is available to a process. Partitioned allocation: Memory is divided in different blocks Paged memory management: Memory is divided in fixed sized units called page frames, used in virtual memory environment. Segmented memory management: Memory is divided in different segments (a segment is logical grouping of process' data or code) In this management, allocated memory does'nt have to be contiguous.
Most of the operating systems (for example Windows and Linux) use Segmentation with Paging. A process is divided in segments and individual segments have pages.
In Partition Allocation, when there are more than one partition freely available to accommodate a process’s request, a partition must be selected. To choose a particular partition, a partition allocation method is needed. A partition allocation method is considered better if it avoids internal fragmentation.
Below are the various partition allocation schemes :
1. First Fit: In the first fit, partition is allocated which is first sufficient from the top of Main Memory. 2. Best Fit Allocate the process to the partition which is first smallest sufficient partition among the free available partition. 3. Worst Fit Allocate the process to the partition which is largest sufficient among the freely available partitions available in the main memory. 4. Next Fit Next fit is similar to the first fit but it will search for the first sufficient partition from the last allocation point.
Is Best-Fit really best?
Although, best fit minimizes the wastage space, it consumes a lot of processor time for searching the block which is close to required size. Also, Best-fit may perform poorer than other algorithms in some cases. For example, see below exercise.
Exercise: Consider the requests from processes in given order 300K, 25K, 125K and 50K. Let there be two blocks of memory available of size 150K followed by a block size 350K.
Which of the following partition allocation schemes can satisfy above requests?
A) Best fit but not first fit.
B) First fit but not best fit.
C) Both First fit & Best fit.
D) neither first fit nor best fit.
Solution: Let us try all options.
300K is allocated from block of size 350K. 50 is left in the block.
25K is allocated from the remaining 50K block. 25K is left in the block.
125K is allocated from 150 K block. 25K is left in this block also.
50K can’t be allocated even if there is 25K + 25K space available.
300K request is allocated from 350K block, 50K is left out.
25K is be allocated from 150K block, 125K is left out.
Then 125K and 50K are allocated to remaining left out partitions.
So, first fit can handle requests.
So option B is the correct choice.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Virtual Memory | Operating System
- Operating System | Paging
- Operating System | Thread
- Virtual Memory | Questions
- Operating System | Page Replacement Algorithms
- Operating Systems | Need and Functions
- Operating System | Free space management
- Nokia Interview Experience | Set 5
- Tasks in Real Time systems
- Communication between two process using signals in C