Explain Memory Management in operating system?

Main Memory is a repository of rapidly available information shared by the CPU and I/O devices. Main memory is associated with the processor, so moving instructions and information into and out of the processor is extremely fast. A power interruption occurs and the RAM loses its data.

Let’s understand the concept of logical address space and Physical address space:

Logical and Physical Address Space

An address seen by the memory unit (i.e the one loaded into the memory address register of the memory) is commonly known as a “Physical Address”.

Logical address space can be defined as the size of the process. The set of all physical addresses corresponding to these logical addresses is known as Physical address space.

Static and Dynamic Loading

To load a process into the main memory is done by a loader. There are two different types of loading :

  • Static loading:- loading the entire program into a fixed address. It requires more memory space.
  • Dynamic loading:- The size of a process is limited to the size of physical memory. To gain proper memory utilization, dynamic loading is used. In dynamic loading, a routine is not loaded until it is called. This loading is useful when a large amount of code is needed to handle efficiently.

Static and Dynamic linking

To perform a linking task a linker is used. A linker is a program that takes one or more object files generated by a compiler and combines them into a single executable file.

  • Static linking: In static linking, the linker combines all necessary program modules into a single executable program. So there is no runtime dependency. Some operating systems support only static linking, in which system language libraries are treated like any other object module.
  • Dynamic linking: The basic concept of dynamic linking is similar to dynamic loading. In dynamic linking, “Stub” is included for each appropriate library routine reference. A stub is a small piece of code. When the stub is executed, it checks whether the needed routine is already in memory or not. If not available then the program loads the routine into memory.

Swapping

  1. A process must have been in memory before it was executed. Swapping is the process of temporarily moving a process from the main memory into secondary memory, which is quicker than secondary memory.
  2. More processes can run and fit into memory at once thanks to swapping. Transferring time makes up the majority of swapping, and the amount of memory swapped directly relates to the total time.
  3. Swapping is also referred to as “roll-out, roll-in” because the memory manager can swap out the lower priority process and then load and run the higher priority process if one with a higher priority arrives and requests assistance.
  4. The lower priority process switched back into memory after completing the higher priority work and continued.

Contiguous Memory Allocation

The main memory is used by both the operating system and the different client processes. We normally need several user processes to reside in memory simultaneously. In adjacent memory allotment, each process is contained in a single contiguous segment of memory. This means that we need to consider how to allocate available memory.

Paging

It is a memory management scheme that eliminates the need for contiguous allocation of physical memory. This scheme permits the physical address space of a process to be non-contiguous.