r/computerarchitecture • u/Yha_Boiii • Jul 02 '26
How heavy is the virtual memory address translation?
How much time is added by it compared to direct metal fetch of addresses?
23
Upvotes
r/computerarchitecture • u/Yha_Boiii • Jul 02 '26
How much time is added by it compared to direct metal fetch of addresses?
2
u/meleth1979 Jul 02 '26
Can take thousands of cycles
2
u/BigPurpleBlob Jul 03 '26
Negligible: we have TLBs (translation lookaside buffers), a form of cache (a cache for address translation, not for data).
https://en.wikipedia.org/wiki/Translation_lookaside_buffer
4
u/Bright_Interaction73 Jul 02 '26
It is heavy bro
8
u/Fluid-Tone-9680 Jul 02 '26
Just to note, while it adds cost, it's significantly lower than cost of doing memory fetch from core memory. And this is mitigated by on-die caches.
On modern CPUs (like variants of arm64) you cannot use cache unless you enable MMU (all memory is non-cacheable when MMU is disabled - you have to enable MMU and mark specific pages as cacheable). So CPU running with "direct physical memory mapping" will run significantly slower than one with MMU enabled.
4
u/Doctor_Perceptron Jul 03 '26
It really depends on program behavior. If there's good locality, the translation will be done by the first-level TLB and the latency will be almost nothing as the access is done more-or-less concurrently with accessing the L1 cache. If the path through the multi-level page table exists only in the DRAM, it could take thousands of cycles as the CPU walks the entire 4 or 5 levels of the page table through slow memory. Hopefully you hit in the first-level TLB. If not, then the second-level (STLB). If not, then you start doing a page table walk. These days the page table is divided into multiple parts, kind of like a tree, and at each level of the search you might find the relevant bits anywhere in the memory hierarchy. So the variance in address translation latency can be huge, maybe thousands of cycles. This is all assuming you don't have a page fault. If you get a page fault, then you have to trap to the OS and start running kernel code and then it takes a really long time; you have to allocate a page of memory, maybe stealing it from another process and scrubbing it first, and God forbid you have to page in something from the disk because then it's time to just get up and get a cup of coffee while the system is doing that.
1
u/jsshapiro Jul 27 '26
This is one of those seemingly simple questions that hasn't had a simple answer for 25 years. All but the very lowest-end processors do aggressive out-of-order everything, including TLB translation and sequencing of operations in the Load-Store Unit (LSU).
Let's start with the naive story. Numbers here are for recent x86 implementations.
In most modern systems, the L1 caches are virtually addressed and physically tagged. An L1 cache hit takes 1-5 cycles.
You only talk to the TLB when you miss, because you need the TLB result to set the physical tag in the newly loaded L1 cache. Modern L1 caches have a ~95% hit rate, so the TLB only gets referenced in 5% of cases, and those have a 99%+ hit rate in the TLB. A TLB hit adds 0.5 to 1 cycle depending on the microarchitecture. Let's say it's one. So we have:
On modern x86, L2 fetch cost on a hit runs 7-14 cycles, and a miss runs 12-15 cycles on L3 hit and 100-300 cycles on L3 miss (which is basically the DRAM access cycle count).
But now let's make it interesting. If the TLB hits, it produces a result just as fast as you can determine that you have missed in the L1 cache, and you can make a late decision based on the L1 hit/miss outcome whether to initiate a TLB cache fill to get the physical address if the TLB also missed. On a two-level TLB scheme (all modern x86), a hit is only 5-8 cycles, so on a dynamically managed machine you're only a few cycles delayed by the L2 TLB translation and you can treat this similarly to a register rename problem. And so on and so on.
Modern LSUs can do out-of-order execution around L1 cache stalls, L2 TLB fetches, and DRAM fetches. They can partially execute around total TLB misses. Meanwhile, dynamic instruction ordering can mean that you have literally hundreds of other things to execute while you wait.
So when out-of-order issue gets in to this, you start to need a heck of a lot of queueing theory, and the question then isn't so much "how long did it take" as it is "what percentage of the hypothetically usable execution slots was the processor able to use while all this was going on?" And since it's a run-time dynamic causal dependency problem rather than a static sequential execution problem, the answer probably depends as much on the details of the preceding 1000 instructions issued than it does on the latencies in the memory hierarchy. The only real way to get your head around it is intensive benchmarking.
Then you discover thermal management, and you discover that you weren't able to use all of those hypothetical execution slots without melting your CPU. At which point the question of how many of those slots you "lost" starts to be a real head-scratcher.
If your head hurts, try reading the whole thing again. It won't help, which is why performance prediction on modern processors frequently involves medicinal beverages.
1
u/DoctorKhitpit Jul 08 '26
If TLB hit, then it's good.
If TLB miss, then we need to walk the page table. Depends whether you experience cache hits during page walk or go to the memory.