Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aligned_memory: use calloc to get zeroed memory #360

Merged
merged 2 commits into from
Jul 22, 2022

Conversation

alessandrod
Copy link

@alessandrod alessandrod commented Jul 22, 2022

Use calloc() instead of using malloc() + memset(). The former gets zeroed memory straight from the OS, avoids writing the memory twice (once to clear old content, once to zero it) and avoids actually paging in the whole new allocation due to memset. See rust-lang/rust#54628.

In practical terms, this halves memset usage while executing transactions, eliminating a frequent largeish memset in CallFrames::new.

Before:
Screen Shot 2022-07-22 at 9 53 09 am

After:
Screen Shot 2022-07-22 at 9 53 22 am

You can see that memset_avx2_erms is cut in half, and CallFrames::new() no longer shows up in profiles. (As for the other memsets, we'll probably be able to remove them when we implement unaligned memory mapping)

@codecov-commenter
Copy link

codecov-commenter commented Jul 22, 2022

Codecov Report

Merging #360 (8e19183) into main (e8243ec) will increase coverage by 0.15%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #360      +/-   ##
==========================================
+ Coverage   90.21%   90.37%   +0.15%     
==========================================
  Files          21       21              
  Lines        8312     8322      +10     
==========================================
+ Hits         7499     7521      +22     
+ Misses        813      801      -12     
Impacted Files Coverage Δ
src/aligned_memory.rs 86.99% <100.00%> (+11.99%) ⬆️
src/call_frames.rs 97.80% <100.00%> (-0.02%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us.

Use calloc() instead of using malloc() + memset(). The former gets
zeroed memory straight from the OS, avoids writing the memory twice
(once to clear old content, once to zero it) and avoids actually paging
in the whole new allocation due to memset.
@alessandrod alessandrod merged commit 1c1556e into solana-labs:main Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants