My current work needs to generate a specified number of TLB misses on CPU of Intel Core series, while it's not going on well. I've tried many methods but all of them have a very high rate of TLB hit. Does anyone know some useful information about how x86 TLB works, or some method to generate large number of TLB misses within a user process?
The TLB is a cache used by the CPU to remember the physical address associated with a virtual address. The virtual address space is split into pages, usually 4KB each. The TLB has a space for each possible virtual page which contains the address of the physical page associated with it. A TLB miss occurs when you try to access a page whose physical address has not been loaded yet. Therefore, to maximize misses, you need to maximize the number of different pages accessed.
Unfortunately, it is not that simple. A simple TLB miss would read entries from the page table hierarchy to find the proper physical address. But this only occurs if you access a page which has a physical address. The OS will determine what virtual addresses have what physical addresses, and if you try to read from any others, you will cause a page fault. The page fault handler will either terminate your program for illegally accessing that page or move data around to put a physical page in that virtual address.
The best way to cause as many TLB misses as possible is to:
The number of misses will go up as available RAM gets low, because the OS will have to move more physical pages around to satisfy your program's needs, so it is good to have other, memory hungry processes running at the same time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With