Virtual Memory Addressing Explained

December 15, 2011

Virtual memory is part of the memory management component in the operating system. It is used for making the memory of a computer system transparent (every memory such as disk and RAM are thought of as one memory). The virtual memory does usually consist of the RAM itself, extended by disk space, it also behaves so. As long as processes require more memory than the size of the RAM itself, we need virtual memory and paging to extend it. More on paging later on.If you’d like a more thorough introduction to the concept of memory management take a look at the 3rd edition of Tanenbaums “Modern Operating Systems”1The background of this short article is from one of my bachelor’s courses (operating systems). Credits to a great lecturer: Vegar Johansen. Now, what is the connection between virtual and physical memory? To explain that, we need to take quick look at paging. In order to combine the disk memory and the physical memory we need to split the data into bulks and store the currently unused bulks at the disk, such a bulk is named a page. The area of the disk dedicated to virtual memory is called swap space. The unused pages of a process are swapped to the swap area. The addressing are as followed in figure 1.

Mapping of virtual to physical memory

Assuming a paging memory system with the following 16 bits logical addressing: 0101 1011 0000 00002`

The address is assembled of a page-part (p-part), being 4 bits, and a displacement-part (d-part) of 12 bits. The physical address corresponding to the logical address is: 0111 1011 0000 00002`

The rest of this article will explain how the addressing system is organized, and how to calculate the addresses, by using the values above.

Virtual memory

Most central is the p-part, since that is the part used for finding the frame number in the page-entry table. The extraction og the frame number is done by first looking up a cache named the Translation Lookaside Buffer (TLB). If nothing is found in the cache, we do a lookup in the page table (named a TLB miss). The page table contains all page entries. Finally we extract the frame number from the page entry.

Now that we have the frame number, this is combined with the d-part: This results in the physical address, further used in the physical memory.

Security In a Paged System

Paging access levels

In each page there are two bits representing the access level required for the page. E.g. at kernel access level we have access to all pages.