This repository was archived by the owner on Jul 15, 2023. It is now read-only.
fix pointer-chasing to touch full working set#17
Open
mhillenbrand wants to merge 2 commits intomicrosoft:masterfrom
Open
fix pointer-chasing to touch full working set#17mhillenbrand wants to merge 2 commits intomicrosoft:masterfrom
mhillenbrand wants to merge 2 commits intomicrosoft:masterfrom
Conversation
xmem::build_random_pointer_permutation weaves a random path through a pointer array, thereby generating a linked list feasible for latency-sensitive pointer-chasing in memory micro-benchmarks. The resulting permutation should touch the whole pointer array to maximize the working set of the benchmark thread. In CS terms, the pointers should form a hamiltonian cycle in the graph formed by the pointer array. However, the build_random_pointer_permutation often fails to construct a hamiltonian cycle. As a result, a benchmark thread's working set might become much smaller than desired, thereby distorting cache miss rates and observed average latencies. Change xmem::build_random_pointer_permutation to always produce hamiltonian cycles in a cheap way: * Represent the traversal order of pointers in an int array of indices * Shuffle the indices in a way that maintains a hamiltonian cycle starting and ending at 0. * Impose the traversal order on the pointer array (specific per chunk size). The changes slow build_random_pointer_permutation down by only ~4% (measured with 64-bit chunks in 32 MiB array on an i7-3530M @ 4 MiB LLC) but ensure the full array as working set all the time.
Contributor
|
Hi Marius, Thank you for this pull request and detailed description of the problem. And I apologize for my delayed response! I will definitely take a look. I am actually already aware of this problem and had yet to fix it. In an early version of X-Mem, I believe I actually did have a Hamiltonian Cycle version of this function. If I recall correctly, I had a compile-time option to allow users to select between Hamiltonian and the shuffle algorithms. I don't recall why I removed this ability. It was probably due to long runtimes on large working sets. Let me re-investigate my notes and figure out the original reason. Otherwise, I agree, we should change this back to Hamiltonian Cycle to be more correct. Mark |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We (@jkehne and @mhillenbrand) found an issue in how X-Mem generates its pointer array for pointer-chasing micro-benchmarks. Most of the time, the traversed linked list does not cover the complete pointer array (only ~45% on average). Thus, the actual working set for random access patterns may be less than specified using -w. With the proposed fix, we ensure that the pointer chain walks across the full array (i.e., the pointers form a hamiltonian cycle) at minimum overhead (~4% slowdown in generating the permutation).
A test harness illustrates that the cycles generated by xmem::build_random_pointer_permutation most often miss significant parts of the pointer array. The code measures the actual length of the pointer cycle in the generated pointer array, comparing the original version of xmem::build_random_pointer_permutation and our proposed alternative.
This pull request replaces the existing implementation with our proposed alternative generator.
Please see the commit message below for more details.