Sei sulla pagina 1di 2

Virtual Memory Management

Virtual memory is a technique that allows the execution of processes that are not currently in memory.
Advantages
~ Programs can be larger than physical memory.
~ Allows process to share files easily.

Virtual address space of a process refers to the logical view of how a process is stored in memory.
Physical memory may be organised in page frames .
The heap is allowed to grow up in memory as it is used for dynamic memory allocation. 
The large block of space (hole) between the heap and stack is part of the virtual address space.
These address spaces which include holes are called sparse address space.

Demand paging
An executable program might be loaded from disk into memory.
Loading of pages as and when needed is known as demand paging.
A process resides in secondary memory. When we want to execute a process we swap it into memory. Instead of swapping
the entire process, we use a lazy Swapper which swaps in a page into memory only when needed.

Hardware support is required to distinguish between the pages that are in memory and which are on the disc.
A bit is used. 
If the bit is set to invalid, the page is either not valid or is currently on the disc. 
While the process executes and access  pages that are memory resident, execution proceeds normally
Access to a  page marked invalid causes a page fault.
The paging hardware will notice that the invalid bit is set, causing a trap to the operating system. This trap is the result of the
operating system’s failure to bring in the desired page into memory

Method to handle page fault

> Check internal table for this process to check if it has a valid or invalid memory access.
> If reference was invalid, terminate the process.
> Find a free frame.
> Schedule a disk operation to read the desired page into the newly allocated frame.
> 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.
> Pure demand paging : Never bring a page into memory unless it is required.
> As we save the state of the interrupted process when a page fault occurs, the process must be able to be start exactly at
the same place and state.

If instruction modifies several different locations :

Solution 1 : Microcode computes and attempts to access both ends of both blocks. Hence all the relevant pages are in
memory.

Solution 2 : Use of temporary register to hold the value of overwritten locations. If there is a page fault, all the old values are
written back into memory before the trap occurs. This action restore memory to its state before the instruction was started. 

Demand paging is a faster file system because swap space is allocated in much larger blocks and the file lookup methods are
not used. 
Another option is to demand pages  from the filesystem initially but to write the pages to swap space as they are replaced.
This approach will ensure that only needed pages are read from the file system. 
Call on write

> The fork system call may initially bypass the need for demand paging. 
> This provides rapid process creation and minimizes number of new pages.
> Fork system call creates child process that is a duplicate of its parent by creating a copy of the parent's address space for
the child.
> Instead we can use copy on write technique which allows the parent and child processes initially to share the same pages.
> The child process will then modify its copied page and not the page belonging to the parent process.
> When it is determined that a page is going to be duplicated, we have to know the location from which the free page will be
allocated.
> These pages are located by a technique known as Zero fill on demand. The pages have been zeroed out before being
allocated, thus erasing the previous contents. 

Potrebbero piacerti anche