Memory management in an operating system is a crucial aspect responsible for the efficient utilization and allocation of computer memory. In this article, we learn some essential concepts and methods related to memory management.

Memory management in Operating System
Memory management in Operating System

What is Memory?

In Computer Science, Memory is a collection of data in a specific format that is used to store the instructions and processed data. The memory consists of a large group of words or bytes each of them with its own location. The main target of the computer system is to execute programs. These executed programs along with the information that they access must be in the main memory at the time of execution.

As per the value of the program counter, the CPU gets the instructions from the memory. For memory utilization, a degree of multiprogramming, and memory management is crucial.

What is Main Memory

For a modern computer, the main memory is the central to its operation. The Main Memory is a group of large words or bytes which ranges in sizes from hundreds of thousands to millions. The information which is shared by CPU and input/output devices are collectedly available in main memory.

Computer-Science-Memory
Computer-Science-Memory

Main memory is a place where programs and information are kept available when the processor are kept utilizing them. Since this memory is associated with the processor, the movement of information and instruction from input to output is rapidly fast.

The main memory is also known as RAM (Random Access Memory). Ram seems to be a volatile memory. The data is lost when the power turns off.

Image of Memory Hierarchy
Image of Memory Hierarchy

How Memory Management is Done

Memory management is a process in the operating system to manage the operations between the main memory and the disk at the time of execution of the process. Utilizing the memory efficiently is the main goal of the memory management.

The operating systems in a multi programming computers would resides in a part of memory and the remaining will be used by multiple processes. The memory management is termed as subdividing memory among different processes.

Why Memory Management is Critical

Why do you think a memory management is required in the operating system? Let’s analyze the information given below –

  • In order to allocate and de-allocate the memory before and after the execution of the process, memory management is needed.
  • Used memory spaces by processes has to be tracked.
  • To reduce the issues in data scattering.
  • Utilization of main memory correctly.
  • Maintaining the undivided data while executing of process.

Methods Involved in Memory Management

There are different methods involved in the process of memory management in the operating system. Below is the block diagram that shows the basic methods.

Memory-Management-Methods
Memory-Management-Methods

1. Loading – Static Loading and Dynamic Loading

A loader is used to load a process into the main memory. Below, we see there are two types of loading and their descriptions –

Static Loading:

Static loading needs more memory space as it loads the complete program into a fixed address.

Dynamic Loading:

In dynamic loading, the routine is not loaded until is called. All routines are residing in the disk in a relocatable load format. Hence, the unused routine is never loaded. This loading is useful when a large amount of code is needed to handle it efficiently.

2. Linking – Static linking and Dynamic linking

A linker is used to perform a linking task. A linker is a program that will take one or more files object files which is generated by the compiler and merges them into a single executable file.

There are two types of linking that are explained below in details-

Static linking

Here in static linking, the linker will combine all the required program modules into one single executable program. Hence, there is no dependency of runtime.

Dynamic Linking

Dynamic linking is as similar to dynamic loading. In the dynamic linking, a small program routine is added for each appropriate routine reference. A stub is noting but a small piece of code. However, when this stub is executed, it clearly checks if the required routine is present in the memory or not and if it is not available, then the program loads the routine into the memory.

Importance of Memory Management

The memory management in an operating system plays a vital role in a computer system. Below are some of their importance.

  • The allocations of memory status can be tracked from memory manager. Memory management addresses the primary memory by giving them the abstractions so that the software perceives a large memory is distributed to it.
  • Memory manager allows computer with a small amount of main memory to carry out programs which is larger than the size or for the amount of memory that is available. Using the method of swapping, the memory manager moves information back and forth between the primary memory and the secondary memory.
  • In order to protect the memory allocated to each process from being corrupted to a different process, the memory manager is held responsible.
  • The sharing of memory space between the processes should be done by memory managers. Hence, two programs can be placed at the same memory location at their different times.

Memory Management Techniques

The techniques of memory management in the operating system can be classified into two types –

  • Contiguous memory management schemes
  • Non-Contiguous memory management schemes
Memory Management Techniques
Memory Management Techniques

Contiguous Memory Management Schemes 

Every program occupies a single contiguous block of storage location which means a set of memory locations with consecutive addresses.

Single Contiguous Memory Management Schemes

It is the simplest form of scheme which were used in early generation of computer systems.  The main memory in this scheme is divided into two partitions. In one of the portions, the operating system is placed permanently, mostly at the lower memory and the user process is loaded into the other partition.

Advantages of Single Contiguous Memory Management Schemes

  • They are very easy to implement.
  • Easy to design them and manage.
  • In this scheme, once the process is loaded, it given its own time to process and hence no other processor will interrupt them.

Disadvantages of Single Contiguous Memory Management Schemes

  • Process will not use all the available memory space and hence there will be memory space because of unused memory.
  • CPU waits for the disk to load the binary image to the main memory.
  • In case the program is too large to fit the overall available main memory space, the program cannot be executed.
  • This scheme cannot handle multiple programs parallelly i.e, it will not support multi programming.

Non Contiguous Memory Management Schemes

Under this scheme, the programs are divided into different blocks and then loaded at different portions of the memory which may not be necessarily adjacent to each other. This non-contiguous scheme can be classified depending upon the size of the blocks and if the blocks can reside in the main memory or not.

Swapping in Operating system

Swapping is the process of bringing in each process in the main memory, which will run for a while and then it will be put back to the disk. In order to execute, a process needs to be in the memory. However, there are few times that there will not be enough main memory to hold all the currently active process in a time-sharing system and hence the excess process is kept on disk and brought into dynamic run.

Fragmentation in Operating system

When most of the free blocks are too small and are unable to satisfy any request, they are termed as inability to use the available memory. This is when the fragmentation appears in a dynamic memory allocation system.

In this scenario, processes are loaded and removed from the memory and as a result, the free holes exist in order to satisfy the request however, are non-contiguous.

Paging in Operating system

Paging is a solution for fragmentation problem. Here in paging, the physical memory is divided into equal size of blocks which is known as pages. These pages belonging to a particular process are loaded into available memory space.

Segmentation in Operating system

Segmentation is another part of memory management scheme that helps the user-view of memory. The segmentation breaks the virtual address space of a single process into multiple segments that can be placed in non-contiguous area of physical memory.

Conclusion

With the above information, it is clearly evident that the memory management plays an crucial role in the operating system. The operating system divides the memory into primary and secondary memory and makes sure that the policies are in place in order to manage and control the types of memory efficiently. However, primary memory can hold the data and programs required to process to execute in the CPU, while the secondary memory gives long term data and program storage.

Read Also:
What is Operating System (OS) – Function, Types, Resource Management
Batch Operating System Overview
Time Sharing Operating System Overview