Memory management is the functionality of an operating system which handles or manages primary memory and moves processes back and forth between main memory and disk during execution.
The essential requirement of memory management is to provide ways to dynamically allocate portions of memory to programs at their request, and free it for reuse when no longer needed.
Different Memory Management Techniques
The following are the three key memory management techniques used by an operating system:
Segmentation refers to the technique of dividing the physical memory space into multiple blocks.
Each block has specific length and is known as a segment.
Base address: Starting address of each segment.
Segment table: Contains details about each segment.
Paging is a technique in which the main memory of computer system is organized in the form of equal sized blocks called pages.
Page table: Where the address of occupied pages of physical memory are stored.
Paging enables the operating system to obtain data from the physical memory location without specifying lengthy memory address in the instruction. In this technique, the virtual address is used to map the physical address of the data. The length of virtual address is specified in the instruction and is smaller than physical address of the data. It consists of two different numbers, first number is the address of page called virtual page in the page table and the second number is the offset value of the actual data in the page.
Swapping involves two tasks called
- Swapping in
- Swapping out
1. Swapping in
The task of placing the pages or blocks of data from the hard disk to the main memory.
2. Swapping out
The task of removing pages or blocks of data from main memory to the hard disk.
Paging vs Swapping
|Paging allows the memory address space of a process to be noncontiguous.||Swapping allows multiple programs to run parallelly in the operating system.|
|Paging is more flexible as only pages of a process are moved.||Swapping is less flexible as it moves entire process back and forth between main memory and back store.|
|Paging allows more processes to reside in main memory||Compared to paging swapping allows less processes to reside in main memory.|
Paging vs Segmentation
|A page is of fixed block size.||A segment is of variable size.|
|Paging may lead to internal fragmentation.||Segmentation may lead to external fragmentation.|
|Paging involves a page table that contains base address of each page.||Segmentation involves the segment table that contains segment number and offset (segment length).|