top of page

Memory Management in Operating System

Memory Management is the process of coordinating and controlling the memory in a computer, Blocks are assigning portions that are assigned to various running programs in order to optimize the overall performance of the system. This technique helps in keeping the track of each and every memory location, whether the memory location is allocated to some process or it is free.


This technique decides which process will get memory at what time. It also keeps the count of how much memory can be allocated to a process. As it keeps the tracks of everything so whenever some memory gets freed or unallocated it updates the status correspondingly.


Important roles of Memory Management in OS:

  • Memory manager is used to keep track of the status of memory locations, whether it is free or allocated. It addresses primary memory by providing abstractions so that software perceives a large memory is allocated to it.

  • Memory manager permits computers with a small amount of main memory to execute programs larger than the size or amount of available memory. It does this by moving information back and forth between primary memory and secondary memory by using the concept of swapping.

  • The memory manager is responsible for protecting the memory allocated to each process from being corrupted by another process. If this is not ensured, then the system may exhibit unpredictable behavior.

  • Memory managers should enable sharing of memory space between processes. Thus, two programs can reside at the same memory location although at different times.


How it Works:



Memory management Techniques:


The Memory management Techniques can be classified into following main categories:

  • Contiguous memory management schemes

  • Non-Contiguous memory management schemes



Contiguous memory management schemes:

In a Contiguous memory management scheme, each program occupies a single contiguous block of storage locations, i.e., a set of memory locations with consecutive addresses.


1. Single contiguous memory management schemes:

The Single contiguous memory management scheme is the simplest memory management scheme used in the earliest generation of computer systems. In this scheme, the main memory is divided into two contiguous areas or partitions. The operating systems reside permanently in one partition, generally at the lower memory, and the user process is loaded into the other partition.


Advantages of Single contiguous memory management schemes:

  • Simple to implement.

  • Easy to manage and design.

  • In a Single contiguous memory management scheme, once a process is loaded, it is given full processor's time, and no other processor will interrupt it.


Disadvantages of Single contiguous memory management schemes:

  • Wastage of memory space due to unused memory as the process is unlikely to use all the available memory space.

  • The CPU remains idle, waiting for the disk to load the binary image into the main memory.

  • It can not be executed if the program is too large to fit the entire available main memory space.

  • It does not support multiprogramming, i.e., it cannot handle multiple programs simultaneously.


2. Multiple Partitioning:

The single Contiguous memory management scheme is inefficient as it limits computers to execute only one program at a time resulting in wastage in memory space and CPU time. The problem of inefficient CPU use can be overcome using multiprogramming that allows more than one program to run concurrently. To switch between two processes, the operating systems need to load both processes into the main memory. The operating system needs to divide the available main memory into multiple parts to load multiple processes into the main memory. Thus multiple processes can reside in the main memory simultaneously.


The multiple partitioning schemes can be of two types:

  • Fixed Partitioning

  • Dynamic Partitioning


2.1 Fixed Partitioning

The main memory is divided into several fixed-sized partitions in a fixed partition memory management scheme or static partitioning. These partitions can be of the same size or different sizes. Each partition can hold a single process. The number of partitions determines the degree of multiprogramming, i.e., the maximum number of processes in memory. These partitions are made at the time of system generation and remain fixed after that.


Advantages of Fixed Partitioning memory management schemes:

  • Simple to implement.

  • Easy to manage and design.

Disadvantages of Fixed Partitioning memory management schemes:

  • This scheme suffers from internal fragmentation.

  • The number of partitions is specified at the time of system generation.


2.2 Dynamic Partitioning

The dynamic partitioning was designed to overcome the problems of a fixed partitioning scheme. In a dynamic partitioning scheme, each process occupies only as much memory as they require when loaded for processing. Requested processes are allocated memory until the entire physical memory is exhausted or the remaining space is insufficient to hold the requesting process. In this scheme the partitions used are of variable size, and the number of partitions is not defined at the system generation time.


Advantages of Dynamic Partitioning memory management schemes:

  • Simple to implement.

  • Easy to manage and design.


Disadvantages of Dynamic Partitioning memory management schemes:

  • This scheme also suffers from internal fragmentation.

  • The number of partitions is specified at the time of system segmentation.


Non-Contiguous memory management schemes:

In a Non-Contiguous memory management scheme, the program is divided into different blocks and loaded at different portions of the memory that need not necessarily be adjacent to one another. This scheme can be classified depending upon the size of blocks and whether the blocks reside in the main memory or not.


Paging:

Paging is a storage mechanism that allows OS to retrieve processes from the secondary storage into the main memory in the form of pages. In the Paging method, the main memory is divided into small fixed-size blocks of physical memory, which is called frames. The size of a frame should be kept the same as that of a page to have maximum utilization of the main memory and to avoid external fragmentation. Paging is used for faster access to data, and it is a logical concept.


Advantages of paging:

  • Pages reduce external fragmentation.

  • Simple to implement.

  • Memory efficient.

  • Due to the equal size of frames, swapping becomes very easy.

  • It is used for faster access of data.


Segmentation:

Segmentation method works almost similarly to paging. The only difference between the two is that segments are of variable-length, whereas, in the paging method, pages are always of fixed size. A program segment includes the program’s main function, data structures, utility functions, etc. The OS maintains a segment map table for all the processes. It also includes a list of free memory blocks along with its size, segment numbers, and its memory locations in the main memory or virtual memory.



Memory Management Methods



Paging:

Paging is a storage mechanism that allows OS to retrieve processes from the secondary storage into the main memory in the form of pages. In the Paging method, the main memory is divided into small fixed-size blocks of physical memory, which is called frames. The size of a frame should be kept the same as that of a page to have maximum utilization of the main memory and to avoid external fragmentation. Paging is used for faster access to data, and it is a logical concept.


Segmentation:

Segmentation method works almost similarly to paging. The only difference between the two is that segments are of variable-length, whereas, in the paging method, pages are always of fixed size. A program segment includes the program’s main function, data structures, utility functions, etc. The OS maintains a segment map table for all the processes. It also includes a list of free memory blocks along with its size, segment numbers, and its memory locations in the main memory or virtual memory.


Swapping:

Swapping is a method in which the process should be swapped temporarily from the main memory to the backing store. It will be later brought back into the memory for continue execution.

Backing store is a hard disk or some other secondary storage device that should be big enough in order to accommodate copies of all memory images for all users. It is also capable of offering direct access to these memory images.


Fragmentation:

Processes are stored and removed from memory, which creates free memory space, which are too small to use by other processes.

After sometimes, that processes not able to allocate to memory blocks because its small size and memory blocks always remain unused is called fragmentation. This type of problem happens during a dynamic memory allocation system when free blocks are quite small, so it is not able to fulfill any request.

Two types of Fragmentation methods are:

  1. External fragmentation

  2. Internal fragmentation

  • External fragmentation can be reduced by rearranging memory contents to place all free memory together in a single block.

  • The internal fragmentation can be reduced by assigning the smallest partition, which is still good enough to carry the entire process.


Partition Allocation:

It divides primary memory into various memory partitions, which is mostly contiguous areas of memory. Every partition stores all the information for a specific task or job. This method consists of allotting a partition to a job when it starts & unallocated when it ends.




Advantages of Memory Management:

  1. Allocating memory is easy and cheap

  2. Any free page is ok, OS can take first one out of list it keeps

  3. Eliminates external fragmentation

  4. Data (page frames) can be scattered all over PM

  5. Pages are mapped appropriately anyway

  6. Allows demand paging and pre-paging

  7. More efficient swapping

  8. No need for considerations about fragmentation

  9. Just swap out page least likely to be used



Disadvantages Memory Management:

  1. Longer memory access times (page table lookup)

  2. Can be improved using TLB

  3. Guarded page tables

  4. Inverted page tables

  5. Memory requirements (one entry per VM page)

  6. Improve using Multilevel page tables and variable page sizes (super-pages)

  7. Guarded page tables

  8. Page Table Length Register (PTLR) to limit virtual memory size

  9. Internal fragmentation



Read More:




The Tech Platform

bottom of page