Search code examples
operating-systemcpu-architecturevirtual-memoryinstruction-setpage-tables

Why is Page Size specified as part of Instruction Set Architecture?


I am trying to understand why is Page Size specified as part of an ISA.

More specifically, I am looking for details where any of the hardware modules (MMU, TLB) (apart from the Operating System) use the Page Size information to provide a certain functionality.

Please let me know the reasons Page Size has to be part of the ISA instead of just being decided by the OS.

Thanks.


Solution

  • The TLB hardware has to know the page size to figure out whether a translation applies to an address or not. e.g. given a translation, does an address 2500 bytes above it use that translation or not?

    Or to put it another way, the TLB has to know which address bits are part of the page offset (within a page), and which bits need translating from virtual to physical.

    Also, on architectures with HW page walk, the whole page table format is part of the ISA, and the typical design uses the virtual page number as an index to find the right entry (e.g. x86-64's 4-level page tables). Not a linear or binary search through the page table to find an entry that contains the virtual address being searched for. Normally this same design is used for page tables walked by software, AFAIK.


    It is possible to build a TLB where each entry has a mask to control how many address bits it matches. i.e. where a single TLB can have entries for pages of multiples sizes. This only works if pages have power-of-2 sizes and are naturally aligned (i.e. the start address of a page is always some multiple of its size, so zeroing the low bits of an address inside a page gives you the page-start address).

    You could potentially use this with an extent-based page-table format, where you have one entry for each contiguous mapping instead of one entry for each page.

    Page-walks would probably be more costly, having to check more entries for more mappings, but the same number of TLB entries could cover more address space.

    In many cases OSes want to be able to easily unmap or even page out unused pages, and this conflicts with using huge pages that cover a mix of hot and cold data or especially code. (But normal fixed-size hugepages have this problem, too, so x86-64's 2M and 1G hugepages aren't always a win vs. standard 4k pages.)