Repository navigation
Huge Memory Pages
In Mess, our goal is to measure the load-to-use latency of memory accesses while eliminating TLB (Translation Lookaside Buffer) miss overhead.
This is critical because we aim to capture the intrinsic hardware latency of memory accesses and exclude other sources of interference as much as possible. To this end, we strive to minimize TLB misses.
- Dataset Sizing: We ensure that the pointer-chasing data set is optimized to test main memory without unnecessary overheads.
- Huge Pages: We use huge pages for pointer chasing whenever possible. The use of huge pages significantly reduces the number of TLB misses observed during pointer chasing.
-
Latency Compensation: Mess always mathematically discounts the TLB miss penalty from the measured latency.
- With Huge Pages: This penalty is near-zero, meaning the raw measurement is naturally accurate.
- Without Huge Pages: The compensation assumes a critical role in removing the page walk overhead to estimate the true memory latency.
Modern processors use a memory management technique called paging, where virtual memory is divided into fixed-size blocks called "pages". The hardware uses the TLB to cache the translation from virtual addresses (used by software) to physical addresses (used by RAM).
- Standard Pages: Typically 4KB in size.
- Huge Pages: Typically 2MB or 1GB in size.
With standard 4KB pages, mapping a large memory region (e.g., 16GB of RAM) requires millions of page table entries. This floods the TLB, causing frequent TLB Misses.
When a TLB miss occurs, the CPU must pause execution to "walk" the page table in memory to find the physical address. This "page walk" adds significant latency (often 20-100+ cycles) to the memory access, polluting the measurement of the pure memory latency.
By using Huge Pages (e.g., 1GB), the same 16GB region requires only 16 entries in the TLB. This almost entirely eliminates TLB misses during sequential access within that region, allowing Mess to measure the raw speed of the memory controller and DRAM, rather than the speed of the CPU's memory management unit.
To enable huge pages on Linux (temporarily, until reboot):
# Allocate 1024 huge pages (assuming default size for huge pages of 2MB)
echo 1024 | sudo tee /proc/sys/vm/nr_hugepagesTo verify allocation:
cat /proc/meminfo | grep HugeIf Mess detects that huge pages are available, it will automatically prefer them for its memory allocations.