16

I found this example.

Consider a system with a 32-bit logical address space. If the page size in such a system is 4 KB (2^12), then a page table may consist of up to 1 million entries (2^32/2^12). Assuming that each entry consists of 4 bytes, each process may need up to 4 MB of physical address space for the page table alone.

What is the meaning of each entry consists of 4 bytes and why each process may need up to 4 MB of physical address space for the page table?

Saurabh Shah
  • 576
  • 1
  • 5
  • 19
Pankaj Mahato
  • 1,051
  • 5
  • 14
  • 26
  • 2
    Possible duplicate of [Calculating Page Table Size](http://stackoverflow.com/questions/16323890/calculating-page-table-size) – ANjaNA Mar 31 '17 at 16:52

8 Answers8

14

A page table is a table of conversions from virtual to physical addresses that the OS uses to artificially increase the total amount of main memory available in a system.

Physical memory is the actual bits located at addresses in memory (DRAM), while virtual memory is where the OS "lies" to processes by telling them where it's at, in order to do things like allow for 2^64 bits of address space, despite the fact that 2^32 bits is the most RAM normally used. (2^32 bits is 4 gigabytes, so 2^64 is 16 gb.) Most default page table sizes are 4096 kb for each process, but the number of page table entries can increase if the process needs more process space. Page table sizes can also initially be allocated smaller or larger amounts or memory, it's just that 4 kb is usually the best size for most processes.

Note that a page table is a table of page entries. Both can have different sizes, but page table sizes are most commonly 4096 kb or 4 mb and page table size is increased by adding more entries.

chanzerre
  • 2,409
  • 5
  • 20
  • 28
Mdev
  • 2,440
  • 2
  • 17
  • 25
  • > _Most default page table sizes are 4096 kb for each process_, I think you mean `page size` instad of `page table size`, right? – Chen Li Jan 01 '19 at 07:57
  • @陳力 Possibly, this was so long ago I honestly don't remember, haha. I was taking a class on operating systems at the time and haven't really worked on them since. – Mdev Jan 11 '19 at 03:15
11

As for why a PTE(page table entry) is 4 bytes:

Several answers say it's because the address space is 32 bits and the PTE needs 32 bits to hold the address.

But a PTE doesn't contain the complete address of a byte, only the physical page number. The rest of the bits contain flags or are left unused. It need not be 4 bytes exactly.

blackbeard
  • 111
  • 1
  • 4
4

1) Because 4 bytes (32 bits) is exactly the right amount of space to hold any address in a 32-bit address space.

2) Because 1 million entries of 4 bytes each makes 4MB.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
4
  1. Your first doubt is in the line, "Each entry in the Page Table Entry, also called PTE, consists of 4 bytes". To understand this, first let's discuss what does page table contain?", Answer will be PTEs. So,this 4 bytes is the size of each PTE which consist of virtual address, offset,( And maybe 1-2 other fields if are required/desired)

  2. So, now you know what page table contains, you can easily calculate the memory space it will take, that is: Total no. of PTEs times the size of a PTE. Which will be: 1m * 4 bytes= 4MB Hope this clears your doubt. :)

user3204053
  • 79
  • 1
  • 7
3

The page table entry is the number number of bits required to get any frame number . for example if you have a physical memory with 2^32 frames , then you would need 32 bits to represent it. These 32 bits are stored in the page table in 4 bytes(32/8) .

Now, since the number of pages are 1 million i.e. so the total size of the page table = page table entry*number of pages =4b*1million =4mb.

hence, 4mb would be required to store store the table in the main memory(physical memory).

thekkb007
  • 31
  • 1
2

So, the entry refers to page table entry (PTE). The data stored in each entry is the physical memory address (PFN). The underlying assumption here is the physical memory also uses a 32-bit address space. Therefore, PTE will be at least 4 bytes (4 * 8 = 32 bits).

In a 32-bit system with memory page size of 4KB (2^2 * 2^10 B), the maximum number of pages a process could have will be 2^(32-12) = 1M. Each process thinks it has access to all physical memory. In order to translate all 1M virtual memory addresses to physical memory addresses, a process may need to store 1 M PTEs, that is 4MB.

belindanju
  • 1,394
  • 1
  • 9
  • 6
2

Honestly a bit new to this myself, but to keep things short it looks like 4MB comes from the fact that there are 1 million entries (each PTE stores a physical page number, assuming it exists); therefore, 1 million PTE's, which is 2^20 = 1MB. 1MB * 4 Bytes = 4MB, so each process will require that for their page tables.

DRoberts
  • 29
  • 4
0

size of a page table entry depends upon the number of frames in the physical memory, since this text is from "OPERATING SYSTEM CONCEPTS by GALVIN" it is assumed here that number of pages and frames are same, so assuming the same, we find the number of pages/frames which comes out to be 2^20, since page table only stores the frame number of the respective page, so each page table entry has to be of atleast 20 bits to map 2^20 frame numbers with pages, here 4 byte is taken i.e 32 bits, because they are using the upper limit, since page table not only stores the frame numbers, but it also stores additional bits for protection and security, for eg. valid and invalid bit is also stored in the page table, so to map pages with frames we need only 20 bits, the rest are extra bits to store protection and security information.