Coupon Accepted Successfully!


Memory Management

Operating system uses the following memory allocation mechanism.




As processes are loaded and removed from memory, the free memory space is broken into little pieces. It happens after sometimes that processes can not be allocated to memory blocks considering their small size and memory blocks remains unused. This problem is known as Fragmentation.

Fragmentation is of two types

  1. External Total memory space is enough to satisfy a request or to reside fragmentation a process in it, but it is not contiguous so it can not be used.
  2. Internal Memory block assigned to process is bigger. Some portion of fragmentation memory is left unused as it can not be used by another process.


External fragmentation is avoided by using paging technique. Paging is a technique in which physical memory is broken into blocks of the same size called pages (size is power of 2, between 512 bytes and 8192 bytes).

Address generated by CPU is divided into

Page number (p) – page number is used as an index into a page table which contains base address of each page in physical memory.

Page offset (d) – page offset is combined with base address to define the physical memory address.


Segmentation is a technique to break memory into logical pieces where each piece represents a group of related information.

Address generated by CPU is divided into

Segment number (s) – segment number is used as an index into a segment table which contains base address of each segment in physical memory and a limit of segment.

Segment offset (o) – segment offset is first checked against limit and then is combined with base address to define the physical memory address.

Demand Paging

A demand paging system is quite similar to a paging system with swapping. When we want to execute a process, we swap it into memory. Rather than swapping the entire process into memory, however, we use a lazy swapper called pager.

When a process is to be swapped in, the pager guesses which pages will be used before the process is swapped out again. Instead of swapping in a whole process, the pager brings only those necessary pages into memory. Thus, it avoids reading into memory pages that will not be used in anyway, decreasing the swap time and the amount of physical memory needed.

Page fault can be handled as following

Step     Description

Step 1 : Check an internal table for this process, to determine whether the reference was a valid or it was an invalid memory access.

Step 2 : If the reference was invalid, terminate the process. If it was valid, but page have not yet brought in, page in the latter.

Step 3 : Find a free frame.

Step 4 : Schedule a disk operation to read the desired page into the newly allocated frame.

Step 5 : When the disk read is complete, modify the internal table kept with the process and the page table to indicate that the page is now in memory.

Step 6 : Restart the instruction that was interrupted by the illegal address trap. The process can now access the page as though it had always been in memory. Therefore, the operating system reads the desired page into memory and restarts the process as though the page had always been in memory.


Page Replacement Algorithm

Page replacement algorithms are the techniques using which Operating System decides which memory pages to swap out, write to disk when a page of memory needs to be allocated. Paging happens whenever a page fault occurs and a free page cannot be used for allocation purpose accounting to reason that pages are not available or the number of free pages is lower than required pages.

First In First Out (FIFO) algorithm

961.pngOldest page in main memory is the one which will be selected for replacement.

Optimal Page algorithm

966.pngAn optimal page-replacement algorithm has the lowest page-fault rate of all algorithms. An optimal page-replacement algorithm exists, and has been called OPT or MIN.

972.pngReplace the page that will not be used for the longest period of time . Use the time when a page is to be used.

Least Recently Used (LRU) algorithm

977.pngPage which has not been used for the longest time in main memory is the one which will be selected for replacement.

Page Buffering algorithm

982.pngTo get process start quickly, keep a pool of free frames.

987.pngOn page fault, select a page to be replaced.

992.pngWrite new page in the frame of free pool, mark the page table and restart the process.

997.pngNow write the dirty page out of disk and place the frame holding replaced page in free pool.

Least Frequently Used (LFU) algorithm

1002.pngPage with the smallest count is the one which will be selected for replacement.

1007.pngThis algorithm suffers from the situation in which a page is used heavily during the initial phase of a process, but then is never used again.

Most Frequently Used (MFU) algorithm

1012.pngThis algorithm is based on the argument that the page with the smallest count was probably just brought in and has yet to be used.

Test Your Skills Now!
Take a Quiz now
Reviewer Name