finds.dev

torvalds/test-tlb

Stupid memory latency and TLB tester

View on GitHub

★ 1,018CGPL-2.0updated Aug 2024

// the take

A single-file C program from Linus Torvalds for measuring memory latency and TLB behavior across different buffer sizes and page configurations. It tests sequential stride access versus random pointer-chasing to expose cache hierarchy and TLB characteristics. Aimed at kernel developers and hardware people who need to profile memory subsystems, not general application developers.

The random pointer-chasing approach (vs. stride loops) is the right way to measure true memory latency rather than prefetcher-inflated bandwidth numbers. The hugepage flag (-H via MADV_HUGEPAGE) lets you isolate TLB miss cost from cache associativity effects — the README actually explains why these conflate, which is more educational than most benchmarks bother to be. Makefile drives a sweep from 4kB to 256MB automatically, giving you a full latency curve in one run. GPLv2 with an explicit note that Linus will relicense on request is a pragmatic touch for a tool this niche.

The CPU frequency is hardcoded as a #define you must edit before the cycle counts mean anything — on modern CPUs with frequency scaling, those numbers will be wrong anyway without pinning frequency first. No noise reduction: one second per test, no iteration averaging, results vary noticeably between runs depending on virtual-to-physical mapping. The hardcoded constants (page size, hugepage size, stride, max buffer) in both the C file and the Makefile mean every new machine requires manual editing rather than runtime detection. Linux-only due to MADV_HUGEPAGE and the madvise() calls, with no portability shim or compile guard.

We read the README, the directory tree and a key source file in June 2026. Nobody pays to be listed. How we judge →

// at a glance

Stars
1,018
Forks
218
Language
C
License
GPL-2.0
Last commit
19 Aug 2024

// nearby

If test-tlb isn't quite it.

All repos →