by jaen · 1w ago · 0 comments
Usually emulators use a direct-mapped cache (basically a software TLB).
In this case though, since you control the kernel, it could use something like the MIPS software-managed TLB of the olden days, with bespoke paging data structures and fast-path page fault handlers, perhaps also using PowerPC Inverted Page Tables as inspiration. (and eg. changing page allocation strategies to constrain pages in the lower address space region to simplify cache look up, and something to prevent cache set conflicts).
Given that the working set is small tho in this use case, eg. just a kernel-managed direct-mapped `page_number[MAX_PAGES] → base_address` table is sufficient and fast. (with some trick for page faults; also who needs granular RWX access permissions...)
wasm32-jit on a ryzen 9 3900, lower ms = faster
workload baseline flat-mmu winner
------------------------ -------- -------- ------
conflict (tlb thrashing) 491 ms 39 ms flat-mmu 12.7×
chase (pointer chasing) 448 ms 116 ms flat-mmu 3.9×
stream (sequential rmw) 78 ms 80 ms baseline 1.03×
sieve (primes) 81 ms 84 ms baseline 1.04×
high-conflict (>64 mib) 484 ms 506 ms baseline 1.05×
fib (cpu) 35 ms 37 ms baseline 1.05×
mem (memory ops) 69 ms 75 ms baseline 1.08×
sha (hashing) 97 ms 106 ms baseline 1.09×
boundary (64 mib edge) 73 ms 82 ms baseline 1.13×
high (hot pages >64 mib) 27 ms 32 ms baseline 1.21×
control (hot pages) 27 ms 32 ms baseline 1.21×Did you check the final compiled assembly for the memory access path?
Also measuring only the whole system in a comparison benchmark is not statistically appropriate/legible, what's desired is something like causal profiling (to isolate the slowness of the rest of the system vs. the part that's being optimized):
https://github.com/plasma-umass/coz https://rocm.docs.amd.com/projects/rocprofiler-systems/en/la...
microbenchmark flat map 8x TLB
conflict 13.7x 14.5x
chase 3.6x 3.5x
high-conflict 0.81x 16.2x
high 0.76x 1.00x
mem/sha/sieve 0.90-1.03 ~1.00
real world:
cold boot 278 -> 276 ms
nix eval 670 -> 726 ms
sqlite 10k 676 -> 724 ms