</>EmbeddedInterview

Why is the page size usually 4 KB? What happens with smaller or larger pages?

MediumOperating System Concepts

Short answer: 4 KB is a compromise. Smaller pages waste less memory inside partly used pages (internal fragmentation) but need more page-table entries and more TLB entries for the same memory. Larger pages reduce page-table size and TLB misses and make disk I/O more efficient, but waste more memory and make copy-on-write and paging coarser. Modern systems keep a small base page and add huge pages where they help.

Smaller pages (e.g. 512 B) Larger pages (e.g. 64 KB, 2 MB)
Internal fragmentation low (average waste ½ page per region) high
Page-table size large (8× more entries than 4 KB) small
TLB reach / misses small reach, more misses large reach, fewer misses
Page-fault count more faults, each cheap fewer faults, each costs more (zeroing/copying more data)
Copy-on-write after fork fine-grained copies a lot for a small write
Disk I/O for swapping many small transfers (inefficient) fewer large transfers

What real systems do

  • x86-64: 4 KB base pages, with 2 MB and 1 GB huge pages.
  • ARM64: the kernel chooses a granule of 4 KB, 16 KB or 64 KB at build time. Apple silicon uses 16 KB pages; some server distributions use 64 KB pages to reduce TLB pressure. Software that assumes 4 KB (hard-coded 4096, alignment of mmap offsets) breaks on these systems, so use sysconf(_SC_PAGESIZE).
  • Linux Transparent Huge Pages (THP) automatically uses 2 MB pages for large anonymous memory; hugetlbfs reserves them explicitly. Recent kernels add "large folios" / mTHP (multi-size) to use 16–64 KB blocks with 4 KB page tables.

Numbers to show the trade-off: a process using 1 GB of memory needs 262,144 entries with 4 KB pages, but only 512 with 2 MB pages.

Follow-up: "When is virtual memory unnecessary?" Small single-application systems such as microcontrollers: there is only one program, all code is trusted and linked together, and real-time predictability matters more than isolation. An MPU gives enough protection there.