converting virtual address to physical address - caching

Wanted to know how should i be processing the information of converting the virtual address
(0x10002400)
which contains the value floor(n/2^10)
to physical address
Details given are 32 bit address bus
512 KB physical memory and
page size of 32 KB

Contents of a memory location does not impact the virtual to physical address translation.
Your virtual address got 8 hex values, which indicates this is a 32 bit virtual address.
Your physical memory size is 512KB, which means there are 2^19 bytes (512 * 1024 Bytes).
In this case, virtual to physical mapping involves mapping a 32 bit address to a 19 bit address.
In your example, the page size is 32KB, which means there are 16 physical pages (512/32). We need 4 bits to index 16 physical pages.
From the 32 bit virtual address, we use the last 4 bits to index into a physical page. We can use the remainder 28 bits to do the comparison.
There is an structure called "page table" which holds this information.
This is basically a mapping of leading 28 bits (32-4) of the virtual address to the leading 15 bits (19-4) physical address.
In the given example, the virtual address is 0x10002400.
Last 4 bits are represented by hex 0. Therefore the index is 0. So we take the 0th entry from the page table. Then we check if the virtual tag in the page table matches with our virtual tag which is 1000240 (Note: The last hex value is dropped). If the virtual tag in the entry matches 1000240, then we use the physical tag from the 0th entry and construct our physical address by appending the same index, which is zero.

Related

Am I reading the virtual addresses correctly?

I have been given a page table for a system with 12-bit virtual ad physical addresses and 256-byte pages.
Say I am given an virtual address (in hexadecimal) that reads 0x3E5.
Am I reading this correctly by saying the first hexadecimal, in this case 3, is the page number and the other 2 hexadecimals are the offset?
This because the page sizes, 256-bytes, which is 2^8, meaning 8 bits are for the page size.
Yes, but only if it is a system with byte addressing. Otherwise, you would divide the page size (256 bytes) by the word size to determine the number of addresses within a page, log2 of which would give you the number of page offset bits.

Can a Page Number of a given virtual address be equals to 0 in memory mapping?

Say you were given a Page Size of 6 KB (6144 bytes) and a Virtual Address value of 2309 using the formula: Page = Virtual Address / Page size, which is 0,376 or just 0 is this possible in a real-world situation, thanks in advance?
Pages are integer entities, so there are consecutive page addresses from 0 to maximum number of pages, identical to virtual addresses that exists from 0 to maximum memory size (ignoring canonicality) - Virtual address 2309 is the byte number 2309 in page number 0.
Having said that, virtual page doesn't have to be present and doesn't have to be mapped to physical address, so it is not necessary possible to access any random address in the virtual address range.

Operating System Logical and Physical Address Mapping

Question is here:
Consider a logical-address space of 32 pages with page size 512 words,
mapped onto a physical memory of 128 frames.
I want to know if my attempting calculation below is correct:
so far I have come the:
**
32 pages = 2^5 bits
512 words = 2^9 bits
128 frames = 2^7 bits
**
How to calculate the logical address and physical address if i do not know the word size?
Word size depends on the computer architecture. Generally for a 32 bit CPU the word size is 32 bits(4 bytes) and for 64 bit CPU, it is 64 bits(8 bytes).
* Logical address will be generated by the CPU for a particular proceess, you don't need to calculate anything. As the CPU generates the logical address it will be mapped to physical address by Page Map Table or a fast Cache in Memory management unit(MMU).
* With respect to the details given above, your CPU generates the logical address of 14 bits, so it can address (2^14 words in memory). Assuming your processor is 32 bit, then it can access 2^16 bytes.
* Given the logical address of 14 bits, it looks in the page map table by using the first 9 bits for page. Then it finds the address where the page is actually located in the physical memory and it adds the offset to the physical address to find memory location in the Main memory.

Convert logical (virtual) address to physical address

I have the following page table of process1 :
Assuming that the paging system works with 16bit addresses and page size is 4k
And I want to convert the logical address 16000 to a physical address .
I'm a little bit new in this topic so go easy on me :
Partial solution : The address 16000 fits cell number 3 in the page table , so I guess
that I need to work with that cell and its stored frame - 2 .
How can I find the offset and the physical address now ?
Thanks
In your case process 1 currently can access upto 4 * 4k bytes of virtual memory.
Generally a process can access upto 4gb of virtual memory(depending on the implementation).
Now the table you have given maps virtual memory to the actual physical address(on RAM).With each entry of page table mapping 4k of memory from virtual to physical space.
So the physical address where the address 16000 corresponds to the 3rd entry of page table which is mapped to the physical address starting from 8192(3*4096) till 12288 (8192+4096).
16000 mod 4096 = 3712(offset).
At an offset of 3172 bytes in the virtual page 2 i.e at an offset of 3172 in physical page 3 ( at address 8192) you find the data corresponding to address 16000.
All these mappings are done by the MMU(memory management unit) for every address access a process makes.
Good link to understand this concept is here.
Cheers :)

Why 16-bit address with 12-bit offset results in 4KB page size?

I'm reading the "Modern Operating System" book. And I'm confused about the "Page Size".
In the book, the author says,
The incoming 16-bit virtual address is
split into a 4-bit page number and
12-bit offset. With 4 bits for the
page number, we can have 16 pages, and
with 12 bits for the offset, we can
address all 4096 bytes within a
page.
Why 4096 bytes? With 12 bits, we can address 4096 entries within a page, correct. But, one entry is an address (in this case, address size = 16 bits). So I think we can address 4096(entry) * 16(bit) = 4096(entry) * 2(byte) = 8KB, but why the book says that we can address 4096 (bytes) ?
Thanks in advance! :)
This is assuming byte-addressed memory (which almost every machine made in the past 30 years uses), so each address refers to a byte, not an entry or address or any other larger value. To hold a 16-bit value, you'll need two consecutive addresses (two bytes).
More than 30 years ago, there used to be machines which were word addressed, which worked like you surmise. But such machines had a tough time dealing with byte-oriented data (such as ASCII characters), and so have fallen out of favor. Nowadays, things like byte addressability, 8-bit bytes and twos-complement integers are pretty much just assumed.
The 12 bits are an offset within a page. The offset is in bytes, not addresses. 2^12 is 4096.
Because with 12 bit, we can address 2^12=4096 slots. Each slot represents an address which size is 1 byte in byte-addressable memory. Hence the total size is 4096*1=4096 bytes = 4KB.
What you are calculating is the page size, i.e. the size of a page in the page table in the memory. As we use 12 bits for the offset, each frame in the physical memory is 2^12=4096K. However, each page in the page table occupies 2^12 entries x 2 bytes = 8K in the memory.
okay so you have 16 bit virtual address let see what does it mean .It means you have 2**16 =65536 bytes.
4 bit page number that means there are 16 pages as 2^4=16
Now You Name The Pages As page1,page2...page16.
Now We are left with 12bits let us see how many address can 12 bits represent 2**12=4096 bytes
65536 bytes could also be achieved by dividing it into 16 pages containing 4096 bytes each as 4096*16=65536

Resources