Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

translate virtual address to physical address

Tags:

The following page table is for a system with 16-bit virtual and physical addresses and with 4,096-byte pages. The reference bit is set to 1 when the page has been referenced. Periodically, a thread zeroes out all values of the reference bit.All numbers are provided in decimal. enter image description here

I want to convert the following virtual addresses (in hexadecimal) to the equivalent physical addresses. Also I want to set the reference bit for the appropriate entry in the page table.

0xE12C

0x3A9D

0xA9D9

0x7001

0xACA1

I know the answers are but I want to know how can I achieve these answers:

0xE12C → 0x312C 0x3A9D → 0xAA9D 0xA9D9 → 0x59D9 0x7001 → 0xF001 0xACA1 → 0x5CA1 

I found and tried This but it did not help me much.

like image 688
Ruan Avatar asked Oct 27 '16 19:10

Ruan


People also ask

Why do we translate virtual address to physical address?

Whenever workloads access data in memory, the system needs to look up the physical memory address that matches the virtual address. This is what we refer to as memory translations or mappings. To map virtual memory addresses to physical memory addresses, page tables are used.


1 Answers

It is given that virtual address is 16 bit long.
Hence, there are 2^16 addresses in the virtual address space.
Page Size is given to be 4 KB ( there are 4K (4 * (2 ^ 10) )addresses in a page), so the number of pages will be ( 2^16 ) / ( 2 ^ 12 ) = 2 ^ 4.
To address each page 4 bits are required.
The most significant 4 bits in the virtual address will denote the page number being referred and the remaining 12 bits will be the page offset.

One thing to remember is page size (in the virtual address space ) is always same as the frame size in the main memory. Hence the last 12 bits will remain same in the physical address as that of the virtual address.

To get the frame address in the main memory just use the first 4 bits.
Example: Consider the virtual address 0xACA1
Here A in ACA1 denotes the page number ( 10 ) and corresponding frame no is 5 ( 0101) hence the resulting physical address will be → 0x5CA1.

like image 153
Akash Mahapatra Avatar answered Sep 20 '22 16:09

Akash Mahapatra