How to calculate number of virtual pages

virtual adress size: 32 bits

page size = 4K =2^12 bytes

what is the number of pages? i know the answer is (2^32)/(2^12) = 2^20 but why?

i think it should be (2^32)/(2^15) because of the byte bit conversion (2^12)*(8)=2^15

Upvotes: 3

Views: 15739

Answers (1)

inquisitive
inquisitive

Reputation: 3639

Every byte in memory has a numeric address starting from 0. The CPU has one or more registers which hold the address of that one byte which is being worked upon. A register is a physical device and has limits to how large a number it can store.

virtual address size: 32 bits

This means the address register can store one address (number) which could be anything between 0 and 2^32 -1.

As the largest address that the address register can store is 2^32 -1 there is no point in having more memory bytes. Because the CPU will never be able to work with them. So in general we assume the total memory to be 2^32 bytes.

page size = 4K =2^12 bytes

The total memory of millions of bytes is actually organized in chunks called pages. Here total memory of 2^32 bytes is chunked into pages of 2^12 bytes.

what is the number of pages?

the answer is (2^32)/(2^12) = 2^20. Good job!

but why? i think it should be (2^32)/(2^15) because of the byte bit conversion (2^12)*(8)=2^15

Here 2^32 is the total number of bytes in memory. 2^12 is total number of bytes in a page. Both numerator and denominator should be in same units - bytes. So you need not convert the denominator to bits.


Note:

I have used over simplification of terms like memory, address, register etc. Many of the statements made above are not valid for a real laptop - but useful for initial learning.

Upvotes: 5

Related Questions