Memory Pages

From COMP15212 Wiki
Depends on Virtual MemoryMemory Sizes

A page is a division of a virtual memory system. The whole address space is sliced into pages which – for implementation purposes – will each contain 2N locations.

What ‘N’ is may be debated; for the moment let us assume a value of 12, as this is typically representative of the sort of sizes used practically.

This gives a page size of 4 KiB (“4 KB”) if we assume each byte has a separate address. (Again this is normal in almost every modern system.)

The page is an indivisible block. The operating system will assign memory to a process in pages: thus a program which has (say) 14 KiB of code will have four pages in which that code will be stored.

  • 3 pages x 4 KiB = 12 KiB: Insufficient.
  • 4 pages x 4 KiB = 16 KiB: Minimum feasible for 14 KiB requirement.

The choice of page size is such that there is not too much memory ‘wasted’ when this occurs (so pages should be small) but there are not too many separate pages to manage (so pages should be large). It’s all a compromise.

If we use this memory with a 32-bit address, the least significant 12 bits of the address will act as an offset (like an array index) into the page. These bits are used because programs must (and data tends to) be at contiguous addresses. There are illustrations of this process in the memory mapping articles.

Because pages are the same size, in a virtual memory system they can be mapped arbitrarily and interchangeably. This is called “paging” – or, sometimes “swapping”; there is an interactive illustration under that article.

With the system described here there are still 20 address bits which select the page, thus 220 (~ “a million”) pages to manage in the virtual space.


Bonus bit: (don’t worry too much about this).

Different page sizes

If you delve into specific implementations you may discover that a few discrete sizes of pages may be possible. However these will always be 2N bytes long and so will ‘fit together’.

If you want a commercial example, the ARM Architecture Reference Manual (Section B) is on line. (You’ll need to register for the official download.)

This allows a mixture of 1 MiB ‘sections’ with 64 KiB, 4 KiB and (formerly) 1 KiB pages … and maybe some newer variants. That’s probably as much as (or more than) you want to know.


Also refer to: Operating System Concepts, 10th Edition: Chapter 9.3, pages 360-371