Virtual Memory Computer Architecture

Virtual Memory:

In Computer Architecture, Virtual memory is a technique used in computing to optimize memory management by transferring data between different storage systems, such as RAM and Disk Storage. It is used to store application data and instructions that are currently not needed to be processed by the CPU. Virtual memory enables a system to run applications larger than the main memory.

The disk seen by the CPU as virtual memory, if the CPU has 16 address lines, then the size of virtual memory will be 216 B. Application residing in the disk called process. When a user runs a program, the operating system moves the pages of the process into the main memory. Virtual memory divided into pages as shown below figure. Process A occupied pages P0 through P4, and process B occupied pages P5–P9.

Virtual Memory Computer Architecture

The CPU generates a virtual address (to access an address in the disk) of V-bits. These bits divided into two identifiers: a virtual page number of M bits and a page offset of N bits as shown above figure. The total number of pages in the system is equal to 2M, and the number of bytes (in a byte-addressable system) in a page is equal to 2N. The total number of addresses in a system is equal to 2(N+M) or 2V.

Example: The capacity of a virtual disk is 2 MB, and each page is 2 kB in a byte-addressable system.

i. What are the values of N and M?

ii. How many pages are on the disk?

Ans Since each page is 2 KB, 2N 2048 B, meaning N equals 11.
The capacity of the disk is 2 MB. 2V 2 M equals 221 so V 21 bits.
The number of pages, then, is equal to 2(21–11). The disk contains 210 or 1024 pages and the size of each page is 2 KB.

Virtual Memory Computer Architecture

Page Table:

With main memory divided into blocks, the size of each block is equal to the page size. When the CPU transfers a page into the main memory, it records the page number and corresponding block in the page table. The address line of the page table is the page number. Each line contains the frame or block number of the matching location in the main memory and a valid bit that indicates whether the line is valid or not. The above figure shows a page table wherein pages P0, P1, P3, and P4 are transferred to blocks 2, 3, 0, and 1, respectively.