Skip to main content

Linux Virtual Memory - Paging pt.1

A memory address is a single number whose value is between 0 and a maximum determined by your hardware architecture, and a memory space is the entire range of valid addresses within a given scope. The x86-64 architecture has 64 bit memory values, meaning that the address space is between 0 and \(2^{64} - 1\) or \(1.84*10^{19}\), which is enough to address 16 exabytes of memory. For reference a mainstream desktop PC's physical RAM in 2019 tops out around 128 GB, or \(2^{37}\) or \(1.37*10^{11}\). Virtual memory space has room for 100,000,000 times more memory than this amount of physical RAM.

Linux virtual memory does not work at this fine level of detail however, and instead manages chunks of memory called pages. When a process accesses a location in memory, the OS (with help from the hardware MMU, or memory management unit,) determines which page that address belongs to, and translates the virtual page into a physical page frame in RAM.

OBJECTIVE

Define the following terms: Page, Page Frame, Page Boundary .

Summarize concepts.

Page

A Page is a contiguous unit of memory and the data it holds, which the kernel manages as a single inseparable block. The standard or default page is the smallest unit of allocation that the kernel can map to a process on a given architecture. On x86-64 this is \(2^{12}\), 4KB, or 4096 bytes. If for some reason you are not familiar with these memory terms, see Memory sizes.

Page Frame

A Page Frame is a contiguous block of physical RAM the size of a page. When the kernel assigns a virtual page to physical ram, it locates an available page frame to place the data.

Page Boundary

A Page Boundary or Page Frame Boundary is the address where one page or page frame ends and the next begins.

4K is a convenient page boundary for reading in hexidecimal, because the 4rd digit is \(16^3\) or \(2^{12}\), or 4K. Because pages and frames are always aligned on the boundary, you can easily identify them; 0x1000 is a page boundary, and 0x2000 is one page boundary above that.

Summary

I will show some concrete examples later on, but for now understand that each process will have a discrete virtual memory space, inside of which will be blocks of memory called pages, that when accessed the kernel translates to a page frame that exists in physical RAM between page frame boundaries.

Note that the address of pages in virtual address space have no relation to the address in physical RAM. If a process has 64K of contiguous virtual memory, it can exist in up to 16 different locations in RAM. Since logical data structures can cross page boundaries, your string of text can be spread out over different areas of physical memory. This is of great benefitb since there is no requirement for a process's resident memory to be contiguous or ordered in main memory, easing the difficulty for the kernel to find unused page frames to allocate.

The next lesson will go over the mechanics of paging.

Next in series : Paging pt.2
Previous in series : Introduction