Skip to content

Conversation

@spredolac
Copy link

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_flush is removed and is now just assumed to be 3/4 of max_bytes

In 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_bytes may go away in the future and be controlled by HPA as well, as anything that is in SEC is logically part of dirty memory 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_ns per sec in malloc stats for the sum of hpa_shard, hpa_shard_grow and hpa_sec locks for equivalent configurations (for example, have fewer shards with more max_bytes per bin). we have also observed

New stats added will look like this:

Bytes in small extent cache: 1200128
Total hits in small extent cache: 519634579
Total misses in small extent cache: 86725256
Dalloc calls without flush in small extent cache: 572836049
Dalloc calls with flush in small extent cache: 33195578

@meta-cla meta-cla bot added the cla signed label Nov 25, 2025
@spredolac spredolac added enhancement New feature or request cleanup PRs cleaning/refactoring the codebase labels Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed cleanup PRs cleaning/refactoring the codebase enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant