Tuesday, 4 September 2012

Memory Management in Operating System (OS)

In this article I am going to discuss the basics of  Memory Management in Operating System which is an important topic in exams  . One question is always there in GATE exam from Memory Management in Operating System

1)Uniprogramming
:  In this technique the RAM is partitioned into two parts .One Portion is for the Operating system to reside and the second part is for the user.  Here a fence register is used which contains the last word address of the OS part. Operating system will compare the user data address with the fence register and if it is different that means user is not entering in the OS area. Fence register is also called boundary register and is used to prevent user from entering in the OS Area.


Here CPU utilization is very poor and hence multiprogramming is used.
2) Multiprogramming: Multiple users can share the memory simultaneously.
a)Contiguous memory Allocation:
1)MFT or fixed partitioning Scheme:
In fixed scheme at the time of installation OS will be partitioned into fixed sized blocks for e.g.  let us consider that each block is of size 4KB  and there are total 4 partitions. so the  processes whose memory requirement is equals to or less than 4KB, can only get the memory.
Advantages: At the time of compilation only the address of each word can be given. Or we can bind address at the compile time
Disadvantages: Degree of multiprogramming is rigid ,its is not flexible because we cannot  change the no. of blocks. memory wastage is caused due to fragmentation.
Fragmentation:
1)Internal: Partial or Incomplete usage of a block of memory
2)External: Entire block of available memory cannot be used.
2)MVT OR variable partitioning Scheme:
In variable partitioning  scheme at the beginning there are no partitions. There is only the OS area and the rest of the available RAM. The memory is given to the processes as they arrive.

Advantages: In this scheme there is no internal fragmentation. This method is more flexible as variable size process can be given memory. there is no size limitation.
Disadvantages: It also suffers from external fragmentation. In this scheme compile time address binding is not possible.
b)Non Contiguous Allocation(Virtual Memory): To provide ease to the user and at the same time increase the CPU utilization we use the concept of virtual memory. In this system Operating system is giving illusion to the user such that
1)user can write a very big program
2)user thinks that its entire program is present in the RAM
3)All the space allocated to the user is contiguous
4)User address starts from all 0’s.
In reality only a small portion of the user program is in RAM which may or may not be contiguous while the remaining program is in secondary storage.
Advantages:
1)provides ease to the user as the user thinks that he has plenty of memory which is contiguous.
2)provides benefits to the system as the degree of multiprogramming is maintained. No fragmentation.
Paging:
We have seen previously that fixed and variable partitioning each had their disadvantages. Moreover, complete program has to be placed in the memory,which ultimately reduces the degree of multiprogramming. To overcome these problems the paging technique is used. The process is divided in small sections called pages. Main memory is also divided in to sections of the same size called frames. When a process needs to be run, it is loaded into memory ( see figure a below ). In figure b,c and d, three more processes are loaded. If process B is swapped to disk, the freed memory can be used by another process (figure e). Say that this new process D is larger than B. The first three pages will be loaded into the space freed by B, the two remaining pages will be read into frames 11 and 12 ( figure f).


Simple relative addressing scheme, cannot be used here. Address translation from virtual to physical address is to be done , and for this, the system needs to keep a page table for every process. For every page of a process currently residing in main memory, this table contains its corresponding frame.Every row in this table is called a Page Table Entry (PTE). The system also keeps a list with all the frames, which are not used at moment.
To keep things simple, the size of main memory, the size of pages and the size of frames is a power of 2.

Segmentation.
Another way of subdividing processes is segmentation. Processes are split up in variable size segments. The difference with dynamic partitioning is that processes can consists of several segments and these segments to not have to be loaded contiguously.

No comments:

Post a Comment