Memory management plays an important part in the operating system. It deals with memory and the moving of processes from disk to primary memory for execution and back again.
Some activities of an operating system with regards to memory management are −
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 first available memory space that is large enough for the process purposes is allocated. Searching can start at the beginning or at the point where the last first-fit search ended.
The smallest memory block that is large enough for the process purposes is allocated For the best-fit algorithm, the entire block list needs to be searched unless it is maintained in order.
The largest memory block that is available is allocated to the process. For this algorithm also the entire block list needs to be searched unless it is maintained in order.
Sometimes a process is removed from the main memory and into the secondary storage. This is known as swapping. Later the process that was swapped out can be swapped in for execution. One of the reasons for swapping is to make space for other processes so they can execute easily.
An image to illustrate the process of swapping is −
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.
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 −