Issue
I'm a bit confused on why page size 2KB is too small for x86-64 architecture. I know an ideal page size is 4KB. I do not know how to explain this why 2KB is not ideal. Thanks in advance
i said it will lead to larger tables.
Solution
The ideal page size is a compromise between advantages and disadvantages. "Pages too small" creates too much overhead (in the form of more levels of tables, more memory consumed by page tables and higher TLB miss costs; for the same virtual address size) when converting virtual addresses into physical addresses. "Pages too big" creates too much memory wastage (e.g. if you need 123 bytes you have to round up to the page size so larger pages mean more wasted RAM).
For 80x86 this decision was made in the 1980s (for 80386), and 4 KiB pages was probably optimal at that time. Since then the benefits of keeping the page size the same (to avoid breaking existing software) has outweighed the benefits of changing the page size. If there was no software (and if there wasn't larger page sizes) and the decision could be made again today, a page size closer to 16 KiB would probably be optimal.
However; due to the way "hierarchy of tables" works it's easy to introduce much larger page sizes. 80x86 has been doing this since the 1990s. For (modern) 80x86 these page sizes are 2 MiB and 1 GiB (and conceptually 512 GiB but it's not supported yet).
In addition; it's possible for a CPU to coalesce adjacent page table entries that happen to be compatible; to get the benefits of a larger page size for TLB efficiency (but without getting the benefits of lower memory consumption for page tables). AMD Zen started doing this a few years ago to create a "16 KiB coalesced page size". This also opens up the opportunity for an operating system to emulate a larger page size (e.g. tell user-space software that the page size is 16 KiB even though the real page size is 4 KiB) and get some of the benefits. This coalescing idea could also be applied to larger page sizes in future (e.g. if 4 adjacent 2 MiB pages happen to be compatible coalesce to get an "8 MiB coalesced page size").
Of course the existence of multiple larger (real and coalesced) page sizes diminishes the benefits of increasing the size of the smallest page size (software that could benefit the most from a switch from 4 KiB pages to 16 KiB pages is probably already using 2 MiB pages anyway).
Answered By - Brendan Answer Checked By - David Marino (WPSolving Volunteer)