LAT_MEM_RD(8)
π lat_mem_rd β memory read latency benchmark π
okay bestie, welcome to section 8 of the LMBENCH manual, this is lat_mem_rd(8) and it is literally the girl who measures how long your memory takes to hand over a single lil pointer. she's thorough. she's iconic. let's go β¨
β¨ SYNOPSIS β¨
lat_mem_rd [ -P <parallelism> ] [ -W <warmups> ] [ -N <repetitions> ]
size_in_megabytes stride [ stride stride... ]
π DESCRIPTION π
so lat_mem_rd measures memory read latency across different memory sizes and different strides. the results come out in nanoseconds per load, and ngl they've been verified accurate to within a few nanoseconds on an SGI Indy. slay π
it measures the entire memory hierarchy, no crumbs left:
- onboard cache latency and size
- external cache latency and size
- main memory latency
- TLB miss latency
only data accesses get measured, bestie. the instruction cache is not measured. don't @ me.
the benchmark runs as two nested loops, and it's giving very much "outer loop / inner loop" energy:
- the outer loop is the stride size
- the inner loop is the array size
for each array size, the benchmark creates a ring of pointers that point backward one stride. then traversing the array is done by
p = (char **)*p;
inside a for loop β and before you come for the loop overhead, it's not significant, okay? the loop is an unrolled loop 100 loads long. periodt.
the size of the array varies from 512 bytes to (typically) eight megabytes. for the small sizes, the cache will have an effect, and the loads will be much faster. this becomes much more apparent when the data is plotted. like, the plot is the main character here fr fr π
now, since this benchmark uses fixed-stride offsets in the pointer chain, it may be vulnerable to smart, stride-sensitive cache prefetching policies. the lore: older machines were typically able to prefetch for sequential access patterns, and some were able to prefetch for strided forward access patterns, but only a few could prefetch for backward strided patterns. these capabilities are becoming more widespread in newer processors. so likeβ¦ vibe check your CPU, ig π¦
π OUTPUT π
the output format is intended as input to xgraph or some similar program (we use a perl script that produces pic input, iykyk). there is a set of data produced for each stride.
- the data set title is the stride size
- the data points are the array size in megabytes (floating point value) and the load latency over all points in that array
π INTERPRETING THE OUTPUT π
the output is best examined in a graph, where you typically get a graph that has four plateaus. iconic. the graph should be plotted in log base 2 of the array size on the X axis and the latency on the Y axis. each stride is then plotted as a curve. π
the plateaus that appear correspond to:
- the onboard cache (if present)
- the external cache (if present)
- main memory latency
- TLB miss latency
as a rough guide, you may be able to extract the latencies of the various parts as follows β but you should really look at the graphs, since these rules of thumb do not always work (some systems do not have onboard cache, for example, and we don't judge them):
- onboard cache β try stride of
128and array size of.00098. - external cache β try stride of
128and array size of.125. - main memory β try stride of
128and array size of8. - TLB miss β try the largest stride and the largest array.
π BUGS π
this program is dependent on the correct operation of mhz(8). so if you are getting numbers that seem off, check that mhz(8) is giving you a clock rate that you believe. if the vibes are rancid, it's probably mhz(8), not you π
π«Ά ACKNOWLEDGEMENT π«Ά
funding for the development of this tool was provided by Sun Microsystems Computer Corporation. ty besties π«Ά
π SEE ALSO π
lmbench(8), tlb(8), cache(8), line(8).
π AUTHOR π
Carl Staelin and Larry McVoy
comments, suggestions, and bug reports are always welcome. seriously, slide into our inboxes, we love hearing from you π₯°
cute lil sign-off: this whole thing is (c)1994 Larry McVoy</s> and the date stamp is$Date$β the page itself isLAT_MEM_RD(8), and yes she ate. bye bestie, go measure some latency πβ¨ππ¦
π¦ where this page comes from
- debian bookworm: lmbench 3.0-a9+debian.1-6
- debian trixie: lmbench 3.0-a9+debian.1-9
- ubuntu jammy: lmbench 3.0-a9+debian.1-6
- ubuntu noble: lmbench 3.0-a9+debian.1-6build3
- ubuntu questing: lmbench 3.0-a9+debian.1-9
- ubuntu resolute: lmbench 3.0-a9+debian.1-10
- ubuntu stonking: lmbench 3.0-a9+debian.1-10
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms