Memory Management in OS || Memory Management Techniques in OS

Memory Management

In a mono programming or uni programming system, the main memory is divided into two parts, one part for the operating system and another part for a job which is currently executing. Consider the following figure below.

memory management
memory management in operating system notes

Partition-1 is allowed for Operating system and partition-2 is allowed for the user process. But some part of partition 2 wasted, it is indicated by black color.

In a multiprogramming environment, the user space is divide into the number of the partition. Each partition is for one process.

The task of the subdivision is carried out dynamically by the operating system, this task is known as “Memory Management”.

Memory Management Unit (MMU):

It is a hardware component that handles all memory and caching operation associated with the processor. So MMU is responsible for all overactivity of memory management.

Logical Address Space and Physical Address Space:
An address generated by CPU is called logical address, whereas an address generated by MMU is called Physical address.

For example, J1 is a program, written by the user, the size of the program is 100KB. But program loaded in main memory from 2100 to 2200 KB. This actual loaded address in main memory is called physical address.

The set of all logical address is generated by a program is referred to as a “Logical address space”.

The set of the physical address corresponding these logical address referred to as a “Physical address space”.

Logical and Physical address space in OS

In our example from 0 to 100KB is the logical address space and from 2100 to 2200KB in the physical address space.

So, Physical address space = Logical address space + Contents of relocation register/ Base value
2200= 100 + 2100

The run-time mapping from logical to physical address is done by the memory management unit (MMU). The relocation register is also known as the base register. The value of the relocation register is added to every address generated by a user process at the time it is sent to the memory.

For example, the base is at 2100, then the attempt by the user to address location 0 is dynamically related to location 2100. An access location 100 is mapped to location 2200.


A process needs to be in memory for execution. But sometimes there is not enough main memory to hold all the currently active processes in a timesharing system. So, the excess process is kept on disk and brought in to run dynamically. Swapping is the process of bringing in each process in main memory, running it for a while and then putting it back to the disk.

Swap in- switch a process from disk to main memory.

Swap out- switch a process from main memory to disk.

Memory Allocation:

Memory allocation is a process by which computer programs are assigned memory or space. It is of three types:

1. First Fit
The first hole that is big enough is allocated to the program.

2. Best Fit
The smallest hole that is big enough is allocated to the program.

3. Worst Fit
The largest hole that is big enough is allocated to the program.

Memory Partitioning:

1. Fixed Partitioning: Main memory is divided into a no. of static partitions at system generation time. A process may be loaded into a partition of equal or greater size. Memory Manager will allocate a region to a process that best fits it unused memory within an allocated partition called internal fragmentation Advantages: Simple to implement Little OS overhead Disadvantages: Inefficient use of Memory due to internal fragmentation. Main memory utilization is extremely inefficient. Any program, no matter how small, occupies an entire partition. This phenomenon, in which there is wasted space internal to a partition due to the fact that the block of data loaded is smaller than the partition, is referred to as internal fragmentation.

Two possibilities of Partitioning:
a). Equal size partitioning 
b). Unequal size Partitioning

Unequal size partitioning is not suitable for systems in which process memory requirements not known ahead of time; i.e. timesharing systems.

Fixed Memory Partition

When the queue for a large partition is empty but the queue for a small partition is full, as is the case for partitions 1 and 3. Here small jobs have to wait to get into memory, even though plenty of memory is free An alternative organization is to maintain a single queue as in above Fig. (b).
Whenever a partition becomes free, the job closest to the front of the queue that fits in it could be loaded into the empty partition and run.

Post a Comment