The Wayback Machine - https://web.archive.org/web/20241006001758/https://www.geeksforgeeks.org/partition-allocation-methods-in-memory-management/
Open In App

Partition Allocation Methods in Memory Management

Last Updated : 08 Mar, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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 into different blocks or partitions. Each process is allocated according to the requirement. 

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 into 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. 

When it is time to load a process into the main memory and if there is more than one free block of memory of sufficient size then the OS decides which free block to allocate.

There are different Placement Algorithm:

A. First Fit

B. Best Fit

C. Worst Fit

D. Next Fit

1. First Fit: In the first fit, the partition is allocated which is the first sufficient block from the top of Main Memory. It scans memory from the beginning and chooses the first available block that is large enough. Thus it allocates the first hole that is large enough. 

2. Best Fit Allocate the process to the partition which is the first smallest sufficient partition among the free available partition. It searches the entire list of holes to find the smallest hole whose size is greater than or equal to the size of the process. 

3. Worst Fit Allocate the process to the partition which is the largest sufficient among the freely available partitions available in the main memory. It is opposite to the best-fit algorithm. It searches the entire list of holes to find the largest hole and allocate it to process.  

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 the below exercise. 

Comparison of Partition Allocation Methods:

Sl.No.

Partition Allocation Method

Advantages

Disadvantages

1.

Fixed Partition

Simple, easy to use, no complex algorithms needed

Memory waste, inefficient use of memory resources

2.

Dynamic Partition

Flexible, more efficient, partitions allocated as required

Requires complex algorithms for memory allocation

3.

Best-fit Allocation

Minimizes memory waste, allocates smallest suitable partition

More computational overhead to find smallest split

4.

Worst-fit Allocation

Ensures larger processes have sufficient memory

May result in substantial memory waste

5.

First-fit Allocation

Quick, efficient, less computational work

Risk of memory fragmentation

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 the 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. 
Best Fit: 
300K is allocated from a 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. 

First Fit: 
300K request is allocated from 350K block, 50K is left out. 
25K is allocated from the 150K block, 125K is left out. 
Then 125K and 50K are allocated to the remaining left out partitions. 
So, the first fit can handle requests. 

So option B is the correct choice.
 


Previous Article
Next Article

Similar Reads

Buddy Memory Allocation Program | Set 1 (Allocation)
Prerequisite - Buddy System Question: Write a program to implement the buddy system of memory allocation in Operating Systems.Explanation - The buddy system is implemented as follows- A list of free nodes, of all the different possible powers of 2, is maintained at all times (So if total memory size is 1 MB, we'd have 20 free lists to track-one for
13 min read
Memory Allocation Techniques | Mapping Virtual Addresses to Physical Addresses
Prerequisite : Requirements of Memory Management System, Logical and Physical Address Memory Allocation Techniques:To store the data and to manage the processes, we need a large-sized memory and, at the same time, we need to access the data as fast as possible. But if we increase the size of memory, the access time will also increase and, as we kno
5 min read
If memory allocation using new is failed in C++ then how it should be handled?
In this article, if memory allocation using new is failed in C++ then how it should be handled? When an object of a class is created dynamically using new operator, the object occupies memory in the heap. Below are the major thing that must be keep in mind: What if sufficient memory is not available in the heap memory, and how it should be handled?
3 min read
Buddy Memory Allocation Program | Set 2 (Deallocation)
Prerequisite - Buddy Allocation | Set 1 Question: Write a program to implement the buddy system of memory allocation and deallocation in Operating Systems.Explanation - As we already know from Set 1, the allocation is done via the usage of free lists. Now, for deallocation, we will maintain an extra data structure-a Map (unordered_set in C++, HashM
15+ min read
Difference between Static and Dynamic Memory Allocation in C
Memory Allocation: Memory allocation is a process by which computer programs and services are assigned with physical or virtual memory space. The memory allocation is done either before or at the time of program execution. There are two types of memory allocations: Compile-time or Static Memory AllocationRun-time or Dynamic Memory AllocationStatic
3 min read
Difference Between Contiguous and Non-Contiguous Memory Allocation
Memory management is one of the fundamentals of operating systems that has implications for its performances and use of resources. These are discussed below: Contiguous and non-contiguous allocation of memory Allocation of memory may take either of the following forms: This article enables you to know the difference between the two, how memory is a
5 min read
Buddy System - Memory Allocation Technique
Static partition techniques are limited by having a fixed number of active processes, and space use may not be optimal. The buddy system is a memory allocation and management technique that uses power-of-two increments. Assume the memory size is 2U and a size of S is required. In this article, we are going to discuss the Buddy System in detail alon
9 min read
Why Linked List is implemented on Heap memory rather than Stack memory?
Pre-requisite: Linked List Data StructureStack vsHeap Memory Allocation The Linked List is a linear data structure, in which the elements are not stored at contiguous memory locations. The elements in a linked list are linked using pointers. It is implemented on the heap memory rather than the stack memory. This article discusses the reason behind
14 min read
Difference between Volatile Memory and Non-Volatile Memory
Memory is one of the most fundamental components in computing systems. Broadly, computer memory can be divided into two types namely volatile memory and non volatile memory. Even though both are crucial in the total functioning of the electronics, they are not interchangeable, each playing specific roles. Volatile memory deploys power in order to s
6 min read
Random Access Memory (RAM) and Read Only Memory (ROM)
Memory is a fundamental component of computing systems, essential for performing various tasks efficiently. It plays a crucial role in how computers operate, influencing speed, performance, and data management. In the realm of computer memory, two primary types stand out: Random Access Memory (RAM) and Read-Only Memory (ROM). Understanding the diff
9 min read
Difference between Virtual memory and Cache memory
Virtual Memory and Cache Memory are important substructures of contemporary computing systems that perform an important function in terms of enhancing capabilities. But they are dissimilar in terms of functionality and function differently. Virtual memory works as extra physical memory of the system and Cache memory provides quick access to frequen
5 min read
Operating Systems | Memory Management | Question 1
Which of the following page replacement algorithms suffers from Belady’s anomaly? (A) FIFO (B) LRU (C) Optimal Page Replacement (D) Both LRU and FIFO Answer: (A) Explanation: Belady’s anomaly proves that it is possible to have more page faults when increasing the number of page frames while using the First in First Out (FIFO) page replacement algor
1 min read
Operating Systems | Memory Management | Question 2
What is the swap space in the disk used for? (A) Saving temporary html pages (B) Saving process data (C) Storing the super-block (D) Storing device drivers Answer: (B) Explanation: Swap space is typically used to store process data. See this for more details.
1 min read
Operating Systems | Memory Management | Question 10
Increasing the RAM of a computer typically improves performance because: (A) Virtual memory increases (B) Larger RAMs are faster (C) Fewer page faults occur (D) Fewer segmentation faults occur Answer: (C) Explanation: When there is more RAM, there would be more mapped virtual pages in physical memory, hence fewer page faults. A page fault causes pe
1 min read
Operating Systems | Memory Management | Question 4
A computer system supports 32-bit virtual addresses as well as 32-bit physical addresses. Since the virtual address space is of the same size as the physical address space, the operating system designers decide to get rid of the virtual memory entirely. Which one of the following is true? (A) Efficient implementation of multi-user support is no lon
1 min read
Operating Systems | Memory Management | Question 5
A CPU generates 32-bit virtual addresses. The page size is 4 KB. The processor has a translation look-aside buffer (TLB) which can hold a total of 128 page table entries and is 4-way set associative. The minimum size of the TLB tag is: (A) 11 bits (B) 13 bits (C) 15 bits (D) 20 bits Answer: (C) Explanation: Size of a page = 4KB = 2^12 Total number
1 min read
Operating Systems | Memory Management | Question 6
Virtual memory is (A) Large secondary memory (B) Large main memory (C) Illusion of large main memory (D) None of the above Answer: (C) Explanation: Virtual memory is illusion of large main memory.
1 min read
Operating Systems | Memory Management | Question 10
Page fault occurs when (A) When a requested page is in memory (B) When a requested page is not in memory (C) When a page is corrupted (D) When an exception is thrown Answer: (B)Explanation: Page fault occurs when a requested page is mapped in virtual address space but not present in memory. Quiz of this QuestionPlease comment below if you find anyt
1 min read
Operating Systems | Memory Management | Question 8
Thrashing occurs when (A) When a page fault occurs (B) Processes on system frequently access pages not memory (C) Processes on system are in running state (D) Processes on system are in waiting state Answer: (B) Explanation: Thrashing occurs processes on system require more memory than it has. If processes do not have “enough” pages, the pagefault
1 min read
Operating Systems | Memory Management | Question 9
A computer uses 46–bit virtual address, 32–bit physical address, and a three–level paged page table organization. The page table base register stores the base address of the first–level table (T1), which occupies exactly one page. Each entry of T1 stores the base address of a page of the second–level table (T2). Each entry of T2 stores the base add
2 min read
Operating Systems | Memory Management | Question 10
Consider data given in the above question. What is the minimum number of page colours needed to guarantee that no two synonyms map to different sets in the processor cache of this computer? (GATE CS 2013) (A) 2 (B) 4 (C) 8 (D) 16 Answer: (C) Explanation: 1 MB 16-way set associative virtually indexed physically tagged cache(VIPT). The cache block si
1 min read
Requirements of Memory Management System
Memory management keeps track of the status of each memory location, whether it is allocated or free. It allocates the memory dynamically to the programs at their request and frees it for reuse when it is no longer needed. Memory management meant to satisfy some requirements that we should keep in mind. These Requirements of memory management are:
5 min read
Implementing Non-contiguous Memory Management Techniques
Memory Management Techniques are basic techniques that are used in managing the memory in operating system. Memory Management Techniques are basically classified into two categories: (i) Contiguous (ii) Non-contiguous We have already discussed the implementation of contiguous in the article Implementation of Contiguous Memory Management Techniques.
3 min read
First Fit algorithm in Memory Management using Linked List
First Fit Algorithm for Memory Management: The first memory partition which is sufficient to accommodate the process is allocated.We have already discussed first fit algorithm using arrays in this article. However, here we are going to look into another approach using a linked list where the deletion of allocated nodes is also possible.Examples: In
15+ min read
Program for Best Fit algorithm in Memory Management using Linked List
Best fit algorithm for memory management: The memory partition in which there is a minimum loss on the allocation of the process is the best-fit memory partition that is allocated to the process.We have already discussed one best-fit algorithm using arrays in this article. However, here we are going to look into another approach using a linked list
15+ min read
Best Ways for Operating System Memory Management
Prerequisite - Partition Allocation Methods Contiguous Memory Allocation :Probably the least difficult technique for the memory portion is to isolate memory into a few fixed partitions. Each partition contains precisely one process. The level of multi-programming relies upon the number of partitions. In the different partition technique, when a par
7 min read
Memory Management in Operating System
The term memory can be defined as a collection of data in a specific format. It is used to store instructions and process data. The memory comprises a large array or group of words or bytes, each with its own location. The primary purpose of a computer system is to execute programs. These programs, along with the information they access, should be
14 min read
Windows Memory Management
The memory management in the operating system is to control or maintain the main memory and transfer processes from the primary memory to disk during execution. Memory management keeps track of all memory locations, whether the process uses them or not. Determines how much memory should be allocated to each process. Specifies how much memory each p
5 min read
Demystifying Memory Management in Modern Java Versions
Memory management is the backbone of Java programming, determining how efficiently your applications use system resources. In this comprehensive guide, we will explore the intricacies of memory management in modern Java versions, including Java 8, 11, and beyond. By the end of this article, you'll have a profound understanding of how memory works i
6 min read
Program for First Fit algorithm in Memory Management
Prerequisite : Partition Allocation MethodsIn the first fit, the partition is allocated which is first sufficient from the top of Main Memory.Example : Input : blockSize[] = {100, 500, 200, 300, 600}; processSize[] = {212, 417, 112, 426}; Output: Process No. Process Size Block no. 1 212 2 2 417 5 3 112 2 4 426 Not AllocatedIts advantage is that it
8 min read