In the operating system, the 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 or partitions.Each process is allocated accroding to the requirment.
Paged memory management: Memory is divided into fixed sized units called page frames, used in a virtual memory environment.
Segmented memory management: Memory is divided in different segments (a segment is a logical grouping of the process’ data or code).In this management, allocated memory doesn’t have to be contiguous.
Most of the operating systems (for example Windows and Linux) use Segmentation with Paging. A process is divided into segments and individual segments have pages.
In Partition Allocation, when there is 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, the partition is allocated which is first sufficient block from the top of Main Memory.
2. Best Fit Allocate the process to the partition which is the first smallest sufficient partition among the free available partition.
3. Worst Fit Allocate the process to the partition which is the 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 the 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
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Implementation of all Partition Allocation Methods in Memory Management
- Buddy Memory Allocation Program | Set 1 (Allocation)
- File Allocation Methods
- Implementation of file allocation methods using vectors
- Difference between Contiguous and Noncontiguous Memory Allocation
- Buddy System - Memory allocation technique
- Buddy Memory Allocation Program | Set 2 (Deallocation)
- Overlays in Memory Management
- Program for First Fit algorithm in Memory Management
- Program for Best Fit algorithm in Memory Management
- Program for Next Fit algorithm in Memory Management
- Requirements of Memory Management System
- Operating Systems | Memory Management | Question 6
- Operating Systems | Memory Management | Question 10
- Operating Systems | Memory Management | Question 5
Improved By : VaibhavRai3