Memory management plays an important part in operating system. It deals with memory and the moving of processes from disk to primary memory for execution and back again. Some basic concepts related to memory management are as follows −
The address generated by the CPU is known as the virtual address and the address seen by the memory is known as the physical address. In compile time and load time address binding schemes, both the virtual and physical address are the same. They differ only in the execution time address binding scheme.
All the logical addresses generated by a program is known as virtual address space and all the physical addresses corresponding to these logical addresses constitute the physical address space.
Sometimes a process is swapped out of the main memory i.e removed from the main memory into the secondary storage. This may be done to make space for other processes so they can execute easily. Later the process that was swapped out can be swapped in for execution.
An image to illustrate the process of swapping is −
<p>The process P1 is swapped out i.e. moved from the main memory to secondary memory and process P2 is swapped in i.e. moved from the secondary memory to main memory for execution.
A simple way to allocate memory is to provide the empty memory spaces to incoming processes as required. This can be done using the following algorithms −
The process is allocated the first available memory space that is large enough for its purposes. Searching can start at the beginning or at the point where the last first fit search ended.
The process is allocated the smallest memory block that is large enough for its purposes. For the best fit algorithm, the entire block list needs to be searched, unless it is maintained in order.
The process is allocated the largest memory block that is available. For this algorithm also the entire block list needs to be searched, unless it is maintained in order.
In a computer system, virtual memory can be created that is more than the actual memory available i.e. physical memory. To implement this, the concept of paging is used.
In paging, the logical address space is divided into pages and the physical address space is divided into frames. The size of both the pages and frames is the same. The process is measured by the number of pages.
Now, these pages are brought from the logical address space to the physical address space by storing the pages into the frames. A page table is created to find out which page is stored in what frame.
This concept is explained more clearly using the following example −
The explanation of the above example is as follows −
This is a memory management technique that supports the user view of memory. The logical address space is divided into a group of segments. These segments have a name and memory length. So, the segment address is specifies using its name, base address and length.
The segments in logical address space appear as follows −