torvalds / test-tlb

Stupid memory latency and TLB tester
GNU General Public License v2.0
717 stars 207 forks source link

Quick memory latency and TLB test program.

NOTE! This is a quick hack, and the code itself has some hardcoded constants in it that you should look at and possibly change to match your machine.

  #define PAGE_SIZE 4096

  #define FREQ 3.9

.. and then later down..

  // Hugepage size
  #define HUGEPAGE (2*1024*1024)

if you don't change the FREQ define (it's in gigahertz) the tests still work, and the absolute time values in nanoseconds are correct, but the CPU cycle estimation will obviously be completely off.

In addition to the tweakables in the code itself, there are other hardcoded values in the Makefile, where the "make run" script will be testing memory sizes ranging from 4kB to 256MB, and it uses a hardcoded stride of 64 bytes.

To give meaningful numbers, the stride should generally be at least the size of your cacheline, although particularly in cases with multiple different cacheline sizes, you might just use different strides and see how it affects the scores.

Note that the "stride" is still used when doing the random list case, but since the end result will be chasing a random chain it won't be a "stride" in memory as much as just the granularity of the chain entries. You can use odd stride values to see how unaligned loads change the picture, for example.

Also note that the actual memory sizes used for testing will depend on how much cache you have, but also on how much memory you have. To actually get a largepage (when using the "-H" flag), not only does your architecture need to support it, you also have to have enough free memory that the OS will give you hugepage allocations in the first place.

So if you are running on some s390 with a 384MB L4 cache, you should increase the largest memory area size to at least 1G, but you should also increase the stride to 256 to match the cache line size.

Also not that the use of MADV_HUGEPAGE is obviously Linux-specific, but the use of madvise() means that it is advisory rather than some hard requirement, and depending on your situation, you may not actually see the hugepage case at all.

For example MADV_HUGEPAGE obviously depends on your kernel being built to support it, and not all architectures support large pages at all. You can still do the non-hugepage tests, of course, but then you'll not have the baseline that a bigger page size will get you.

Finally, there are a couple of gotchas you need to be aware of:

Finally, I've made the license be GPLv2 (which is basically my default license), but this is a quick hack and if you have some reason to want to use this where another license would be preferable, email me and we can discuss the issue. I will probably accommodate other alternatives in the very unlikely case that somebody actually cares.

             Linus