Memory Management

Introduction

Memory management in the operating system is a kind of method or kind of functionality to manage the various kinds of memories. This means in the system there are a lot of different types of memory available like RAM, hard disk, CD, registers, etc., how to manage all the memory resources in a more efficient method. Memory management primarily manages the “primary memory”. Primary memory is the priority of memory management, which means memory management manages the primary memory as the top priority and a very large amount.

The main function of memory management is to allocate the physical memory to the requesting processes which have a finite capacity. Each process requires a certain amount of memory for activation. It handles the allocation and deallocation of the memory. When the processor requires the memory, the OS allocates the memory for processing and deallocates the memory when it is not in the use through memory management.

There are many memory management schemes that reflect various approaches and the effectiveness of each algorithm depends on the situation. For a system, the selection of a memory management scheme depends on various factors, especially on the hardware design of the system. Own hardware support is required by each algorithm.

Single Process Monitor

This is the simplest approach to memory management. In this kind of memory management, the memory is divided into two partitions, out of which the first partition is for the contiguous parts for operating system programs (also called monitor), and the other partition is for the user program.

Here, the operating system only keeps track of the first and last location available for allocation of the user programs. The operating system is loaded at one end, either the bottom or the top for providing a contiguous area of free storage for the user program.

Multiprogramming with Fixed Partitions

In multiprogramming, several programs reside in primary memory at a time and the CPU passes its control rapidly between these programs. The way for supporting the multiprogramming is to divide the main memory into several partitions, each of them allocated a particular process. Depending upon how and when partitions are created, there are two types of memory:

  1. Static Memory
  2. Dynamic Memory

In static partition, the division of memory into the number of partitions and its size is created in the beginning (during the process of system generation) and remains fixed after that. While in the dynamic partitions, the number of sections and their size are decided during the run time by the operating system.

There are 6 partitions in the above figure.

The first region is reversed for the operating system and the other five partitions are for user programs. Out of which three sections are occupied by programs P1, P2, and P3. Only two sections are free and available for memory allocation. When the partitions are defined, then the operating system keeps track of the status (whether allocated or free) of the memory partition. This task is fulfilled by the partition description table.

Techniques of Memory Management

 The techniques of memory management are as follows:

Contiguous memory allocation

  • Fixed-size Partition Scheme
  • Variable–size Partition Scheme

Non – Contiguous memory allocation

  • Paging
  • Segmentation

Contiguous Memory Allocation

Contiguous memory allocation is a technique of memory management that contains each process in a single contiguous section of memory. In this technique of memory allocation, all free memory sections/partitions are not spread here and there across the whole memory space because they all remain together in one place. When a user process requires the memory then, the contiguous memory allocation gives a single block of memory to the user according to their requirements.

Contiguous memory allocation can be achieved by dividing it into two parts i.e.,

  1. Fixed-size Partition Scheme
  2. Variable–size Partition Scheme

Fixed-size Partition Scheme

The system divides the whole memory into fixed-size partitions in this scheme. This means the system divides the whole memory into some partition of fixed size. The size of each partition may be different or maybe the same. Each partition size is fixed according to the size of the whole memory and the size cannot be changed, once it was fixed. Each partition must contain at least one process. In this scheme, there are some limitations to multiprogramming, as the number of processes is divided according to the number of partitions. When a partition finishes the currently executing process and terminates it, then it will become available for another process. The other name of this technique is Static partitioning.

Example: Let us consider the memory of 20 bits and divide it according to the fixed size partition:

Variable–size Partition Scheme

For overcoming the limitations of the fixed-size partition scheme a new scheme is formed i.e., a variable–size partition scheme. In this scheme, the allocation is done dynamically. In the fixed-size technique, the size of partitions is declared initially, then execute in the process, but variable – size partition scheme does not declare the size of the partition initially. Whenever a process arrives then, a partition is created according to the size of the process and allocated to the process. So, the size of each partition is equal to the size of the process. The size of the partition varies according to the size of the process. This technique is also known as dynamic partitioning.

Difference between the Fixed-size partition method and variable – size partition method

Advantages of contiguous memory allocation

  1. This technique is very simple as it allocates the contiguous memory to the process.
  2. In this technique the addressing is very simple as it is within the process.

Disadvantages of contiguous memory allocation

  1. There is no method of sharing the data and instructions among the processes which are loaded in the different portions of the memory.
  2. Multiprogramming is depending on the availability of the partition that can accommodate the whole process.

Non – Contiguous Memory Allocation

Non – contiguous memory allocation, allocates a single block of memory to the process. Non – contiguous memory allocation performs address translation and reduces memory waste. As a result of address translation, the overheads are increased. The memory execution time is slow because address translation consumes time.

There are two parts of non – contiguous memory allocation i.e.,

  1. Paging
  2. Segmentation

Paging

This method divides the physical memory into fixed – sizes blocks called frames and logical memory into fixed-size blocks called pages. Frames and pages are of the same size. The main function of this technique is to place the pages of a process into the available frames of memory when the process is to be executed. When the data is transferred from one location to another then, the content of the memory address is transferred. Address of memory location is generated by using indexing, base register, segment registers, and some other ways. These generated addresses are known as virtual addresses and form the virtual address space.

Advantages of Paging

  1. Having a higher degree of multiprogramming as compared to contiguous memory allocation.
  2. No possibility of external fragmentation.
  3. Paging helps to share a single code among the processes i.e., through paging a single code can share among all the processes.
  4. Swapping is easier in paging because of an equal number of frames and pages.

Disadvantages of Paging

  1. Page table consumes a large amount of memory.
  2. Paging causes internal fragmentation.
  3. Lookup time is longer for memory.

Segmentation

Segmentation is another technique of non – contiguous memory allocation. Segmentation is the technique that provides a view of memory to the programmer. Programmers always considered their program as a collection of logically related entities, such as subroutines or procedures, functions, global or local data area, stack, etc., rather than a linear array of words. During the program translation time, the segments are formed by grouping the logically related entities. The formations of these segments are varying from compiler to compiler.

Advantages of Segmentation

  1. The sharing of code of data in paging is possible even with the segmentation technique. The entries in two different segment tables can be done by pointing to a common physical location.
  2. The size of the segment table is less in segmentation than that of the page table in paging.
  3. There is no internal fragmentation in segmentation memory allocation.
  4. Locating segments is easier as compared to locating the entire address space.
  5. The average size of segments is larger than that of the actual page size.

Disadvantages of Segmentation

  1. The speed of the computer system is slow because paging requires two memory references per logical address.
  2. External fragmentation arises in segmentation when the size of blocks of memory that accommodate the segments is small.
  3. The algorithm used in this memory management is costly.
  4. Difficult to allocate segmentation in variable-sized partition contiguous memory management.
  5. As the number of segments increased, the size of the segment table also increased.

Difference between Paging and Segmentation

Difference between Contiguous Memory Allocation and Non – Contiguous Allocation

Summary

In this article, we studied memory management. Memory management in the operating system is a kind of method or kind of functionality to manage the various kinds of memories. The two kinds of memory management techniques are contiguous memory allocation and non – contiguous memory allocation. Contiguous memory allocation is a technique of memory management that contains each process in a single contiguous section of memory, and non –contiguous memory allocation technique allocates a single block of memory to the process. Fixed–sized partition and variable-sized partition are the two schemes of contiguous memory allocation and paging and segmentation are the schemes of non – contiguous memory allocation. In a fixed-sized partition, the system divides the whole memory into some partition of fixed size, whereas in a variable-sized partition, the allocation of memory is done dynamically. Paging divides the physical memory into fixed – sizes blocks called frames and logical memory into fixed-size blocks called pages. Segmentation is the technique that provides a view of memory to the programmer.


Similar Articles