Make SEC owned by hpa_shard, add stats, lock per bin, improve contention #61
+1,255
−1,269
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.
Motivation
SEC sits in front of HPA and it does not allow for benefits of being allocator aware (for example, one can fill in cache in flexible manner when convenient based on availability of regions, not at some hard-coded constraints). Having HPA own the SEC will simplify allocator interface and allow HPA to drive decisions (instead of the other way around). There were no stats about hits and misses and they are now added. Locking per bin is finer grain and aligns with size-class based design in upper levels. Option
bytes_after_flushis removed and is now just assumed to be 3/4 ofmax_bytesIn the future we plan to remove batch_fill_extra and let HPA fill what is the most beneficial from Allocator point of view. Also,
max_bytesmay go away in the future and be controlled by HPA as well, as anything that is in SEC is logically part ofdirtymemory of that HPA shard. Those changes were out of scope of this PR.What
SEC is now owned by HPA_SHARD instead of arena. It is not an instance of allocator anymore, but rather simple cache. Most of the interesting changes are in the
sec.[hc]files itself and usage of SEC in hpa. Everything else is just plumbing. Some stats about SEC are introduced.Testing
Old unit test for sec which was leaking memory is replaced with the new one that does not. Unit tests for integration between HPA and SEC is added. Code ran on internal services with various configuration changes to keep something (number of shards, or max_bytes over shard, batch fills). Although primary motivation is to refactor the code and enable some future improvements, we have observed on average 20% improvements in
total_wait_nsper sec in malloc stats for the sum ofhpa_shard,hpa_shard_growandhpa_seclocks for equivalent configurations (for example, have fewer shards with moremax_bytesper bin). we have also observedNew stats added will look like this: