Virtual Memory

Virtual Memory

Programs developed by the software engineers are stored in the auxiliary storage, however, when executed a copy or part of the program get transferred to main memory. The CPU always refers to the main memory to access instructions or the data. If the referenced item is not found then it is transferred from auxiliary storage to the main memory.

Virtual memory is a concept that permits programmers to to construct programs as though a very large memory space were available.  It provides a mechanism for translating program-generated address into the physical or main memory locations.

Address Space Vs Memory Space:

Address used by the programmers is called virtual address and the set of such addressed is called the address space. The addresses or the locations referenced by CPU to access a word is the physical or main memory addresses and set of such addresses are called the memory Space.

Pages and Blocks

The terms pages and blocks are used in the implementation of the address mapping of address space and memory space. So, the address space and the memory space is divided into the pages and blocks.

The auxiliary memory space is broken down into group of equal size called “pages”. The physical memory is broken down into equal size called “blocks”. The page size and the block size is of equal size.

For example a system using auxiliary memory of 8Kbyte and main memory of 4Kbyte . The auxiliary memory is divided into 8 pages each of 1K and the memory space is divided into 4 block of 1K each. The term “page frame” is sometimes used to denote a block.

Figure: Address Space Vs Memory space with valid bit

Figure shows the address space and the memory space for the above example. A valid bit  against the page of address space indicate that the copy of the page is in main memory. Whenever a data is not found in any block a new full page is transferred from address space to memory space.

Mapping Technique virtual address to memory address

We need a table that maps the virtual address space to the physical address space.  This table may be stored in a separate small but fast memory such as associate memory or may occupy a portion of the main memory itself. Figure below shows one of the way of mapping the address space to the physical space.

Figure: memory table for mapping virtual address

The CPU makes a request for the program or data by generating the 20-bit address of address space. This 20-bit address space is mapped to the physical memory address by mapping technique and the word is read from the main memory.

Organization of the mapping table:

Let us assume that the address space and the physical memory space available is 8Kbyte and 4K-byte respectively.  Virtual address of 13-bits and a memory address of 12 bits are required for addressing the two memories. If the page and the block size of 1Kbyte each is to be used then there are 8 pages and 4 blocks of equal sizes of 1Kbyte each. We need an address of 10 bits to address any word within a page or a block.

In the mapping process out of the 13-bit address, 10-bits address will be used to refer to the line within a page and the 3 MSB will used to refer to the pages.

Figure shows the complete mapping process.

Figure: Memory Table in a virtual memory page system


Leave a Reply

error: Content is protected !!