Virtual Memory and Demand Paging
page 2 of 8
by Joydip Kanjilal
Feedback
Average Rating: 
Views (Total / Last 10 Days): 98556/ 85

Virtual Memory

Let us understand in simple terms the memory access that is required for execution of an instruction from the main memory.  The data and the instructions are read from the main memory and then after the execution of the instruction is over they are written back onto the memory.  But what happens when the program in consideration is larger than the size of the available memory?  Virtual Memory is a concept that addresses this issue by allowing a program than is even larger than the size of the available free memory to be loaded and executed and eliminate the chances of external fragmentation.  Let us understand how this is accomplished.

The data and instructions of any process (a program in execution) or thread of execution within a process must be available to the CPU by residing in physical memory at the time of execution.  Virtual Memory refers to the concept in which a process of a larger size than available memory can be loaded and executed by loading the process in parts.  The Operating System maps the programmer's virtual addresses to real hardware storage addresses.  Mapping implies the correspondence between the virtual addresses and the physical addresses using virtual translation mechanisms as decided by the Operating System.  The program memory is divided into pages and the available physical memory into frames.  The page size is always equal to the frame size.  The page size is generally in a power of 2 to avoid the calculation involved to get the page number and the offset from the CPU generated address.

In the virtual memory systems, the addresses that the application programs deal with are known as virtual addresses.  These virtual addresses used by the application program are mapped to physical addresses by translation of these virtual addresses.  This is taken care of by the virtual memory system's address translation mechanism by mapping these virtual addresses to frame addresses using the Page Map Tables.  This is what we call the physical address in the main memory that can be used to refer to the contents from the memory.  The process address space implies the number of unique addresses needed to hold both the process and its data.   The virtual address space refers to the memory space of the virtual addresses.

The virtual address contains a page number and an offset.  This is mapped to the physical address by a technique of address resolution after searching the Page Map Table.  In order to maintain the accounting information of which pages are loaded into which frames, the Operating System maintains a Page Map Table.  This table contains the following:

·         The Page Number

·         The Offset

·         The Frame Number

·         The Reference Bit

·         The Presence Bit

·         The Dirty/Modified Bit

The Page Number refers to the number of the page in the virtual addressing mechanism for the page.  The offset indicates the relative address of a particular instruction in the page from the base of that page.  The frame number indicates the number of the physical frame in the memory that is divided into equal sized frames.  Note that the page size and the frame size are always equal so that a page can be easily mapped onto a frame in the main memory.  The reference bit indicates whether the page is being referenced.  The presence bit indicates whether the page is in memory.  The modified bit is set if the page has been modified after being loaded in memory.  The Page table is process specific and each process is allocated its own Page Table.  There is another table called the Page Table Register that contains the references to the Page Tables in memory.  Therefore, there is one Page Table Register for the entire system, but there can be multiple Page Map Tables, each belonging to a particular process.

In Virtual Memory systems, the Virtual Page Address Translation mechanism translates a virtual Page No to a Physical Frame No.  This translation is taken care of by a specific hardware called the Memory Management Unit (MMU) that is contained in the CPU.  The MMU is a hardware device responsible for handling memory accesses requests that come from the CPU.  Note that the addressing model in this case is defined by the CPU.  In order to facilitate faster page table lookups, the Operating System makes use of "Translation Look aside Buffers" (TLB) and ensures that the Page Tables are updated with each Page Fault.  A TLB is a buffer (or cache) in a CPU that contains parts of the page table of a particular process that translates the virtual address to a physical address.  Page Fault is discussed later in this article.


View Entire Article

User Comments

Title: virtual memory and paging concepts   
Name: Suganthi Velusamy
Date: 2006-12-28 1:10:43 AM
Comment:
This is very very useful for me to know about the virtual memory concets and paging concepts clearly. Thanks a lot for you to make me to get a clear idea of what is virtul memory and all of its corresponding operations. Can u please guide me by an article for threading concepts in detailed manner?
Title: Mapping virtual address to physical   
Name: Swetha
Date: 2006-10-15 3:07:27 PM
Comment:
Hello Sir,

The article is very good for beginners like me.But ca you tell me whether can I write a code to map virtual address to physical addres.

Warm Regards
swetha
Title: Suggestion   
Name: Sandeep Acharya
Date: 2006-08-30 12:30:59 PM
Comment:
The article is really good. We all know that covering the paging concept in a small article is very tough. But I guess it could be better if you can throw some more light on the "Pure demand Paging" and how it could "Thrash" an application. I guess a pictorial/graphical explanation could be better. ANyway its a suggestion only. And I am really appriciating the article. Hoping to have some good articles like this in future.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-25 5:18:58 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search