Determining page numbers and offsets for given addresses

两盒软妹~` 提交于 2020-06-22 11:41:05

问题


Consider a computer system with a 32-bit logical address and 4KB page size. The system supports up to 512MB of physical memory.

How many entries are there in a conventional single-level page table?

Conventional single-level page table: 2^32 / 2^12 (4000)  = 2^20 = 1,048,576

Why did I have to divide 2^32 / 2^12 to get the answer?

How many entries are there in an inverted page table?

An inverted page table needs as many entries as there are page frames in memory.

Inverted page table: 2^29 (512mb)/ 2^12 (4000) = 2^17 = 131,072

Why did I have to divide 512mb / page size to get the inverted page table entries?

What are the page numbers and offsets for the following address references: a) 30000, b) 256, c) 0xbcf034

a) 30000 in hex: x7530 Page #: x7 = 7 offset: x530 = 1328

b) 256 in hex x100 Page #: x0 = 0 offset: x100 = 256

c) 0xbcf034 Page #: xbcf = 3023 offset: x034 = 22

How do I figure out these page numbers and offsets based on the hex addresses?

I know the answers and but I want to understand WHY and HOW. Can someone please explain in detail :)


回答1:


Why did I have to divide 2^32 / 2^12 to get the answer?

2^32 ==> Total virtual memory size

4KB=2^12 ==> Size of a single page

2^32 / 2^12 =2^20 ==> Total number of pages of virtual memory

So page table will be having 2^20 = 1M entries

How many entries are there in an inverted page table?

2^29=512MB ==> Total physical memory

2^12 = page size = frame size

2^29 / 2^12 =2^17 ==> Total number of frames in physical memory

So inverted page table will be having 2^17 = 128K entries

This fig. may clear your remaining doubts:




回答2:


Given page size and address references :
best way to Calculate page number and offset,
Suppose, page size of is 1KB and address reference is 256.


Page number = (address reference / page size) = 256/1024 = 0

Offset = (address reference % page size) = (256 % 2014) = 256 


Apply the same procedure for the rest of the address references.


回答3:


2^12 => 4096 2^32/2^12 => 2^32/4096 => how many 4K pages are there => how many page table entries we need.

Similar calculation for the physical page table i.e. how many page table entries do we need for the inverted page table.

With the above hint, give the question a shot and let us know what you come up with. Once you learn a bit more in your OS course, you will find out that there are pros and cons in each page table design.




回答4:


because page size = frame size = 2^12 number of entries in inverted page table = no of frames so we are calculating no of frames



来源:https://stackoverflow.com/questions/17646754/determining-page-numbers-and-offsets-for-given-addresses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!