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

Account data direct mapping #28053

Merged
merged 44 commits into from
Apr 28, 2023
Merged

Conversation

alessandrod
Copy link
Contributor

@alessandrod alessandrod commented Sep 24, 2022

This PR introduces the bpf_account_data_direct_mapping feature. When enabled, account data is directly mapped into vm memory at vm setup time. This removes the need to have large copies during transaction execution, going in and out of the vm at each instruction/CPI boundary.

The only data copy left now is when an account is first mapped as writable during a transaction. That copy is unavoidable at the moment since accounts are cached in memory and written back only every N slots. I'm planning to try and remove that copy in a separate PR.

Feature gate issue: #29708

@alessandrod alessandrod added the work in progress This isn't quite right yet label Sep 24, 2022
@alessandrod alessandrod marked this pull request as draft September 24, 2022 22:45
@alessandrod alessandrod force-pushed the direct_mapping branch 7 times, most recently from b62527c to 7ad11d8 Compare September 30, 2022 07:14
@Lichtso Lichtso added this to To do in Account Data Direct Mapping via automation Sep 30, 2022
@Lichtso Lichtso moved this from To do to Prototyping (WIP) in Account Data Direct Mapping Sep 30, 2022
@alessandrod alessandrod force-pushed the direct_mapping branch 6 times, most recently from afd32c6 to 3eef8b8 Compare October 4, 2022 21:33
@alessandrod alessandrod changed the title WIP: direct mapping Account data direct mapping Oct 30, 2022
@alessandrod alessandrod marked this pull request as ready for review October 30, 2022 10:10
@alessandrod alessandrod removed the work in progress This isn't quite right yet label Oct 31, 2022
@alessandrod alessandrod force-pushed the direct_mapping branch 2 times, most recently from d6635f2 to 8c4d0f2 Compare November 12, 2022 01:22
@alessandrod alessandrod force-pushed the direct_mapping branch 3 times, most recently from eda8806 to da79024 Compare November 23, 2022 22:19
…ough

Introduce a better way to ensure that account capacity never goes below what
might be mapped in memory regions.
…::spare_data_capacity_mut()

Before we were using BorrowedAccount::get_data_mut() to get the base pointer to
the account data, then we were slicing the spare capacity from it. Calling
get_data_mut() doesn't work if an account has been closed tho, since the
current program doesn't own the account anymore and therefore get_data_mut()
errors out.
Add a test that after a realloc does a large write that spans the
original account length and the realloc area. This ensures that memory
mapping works correctly across the boundary.
…n and off

By default test banks test with all features on. This ensures we keep
testing the existing code until the new feature is enabled.
Split the actual memcmp code in a separate function. Remove check
indexing the slices since the slices are guaranteed to have the correct
length by construction.
Use slice::fill, which is effectively memset.
… memory

With direct mapping enabled, accounts can now span multiple memory
regions.
Simplify the logic to update a caller's memory region when a callee
causes an account data pointer to change (eg during CoW)
When starting at u64::MAX, the chunk iterator would always return the
empty sequence (None on the first next()) call, instead of returning a
memory access violation.

Use checked instead of saturating arithmetic to detect the condition and
error out.

This commit also adds more tests around boundary conditions.
With direct mapping on, invalid writes are caught early meaning the
tuner would fail on the first store and not consume the whole budget
like the benchmark expects.
Copy link
Contributor

@Lichtso Lichtso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need some more refactorings, but can be merged first.

@alessandrod alessandrod merged commit 117a194 into solana-labs:master Apr 28, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature-gate Pull Request adds or modifies a runtime feature gate runtime Issues related to runtime, BPF, and LLVM
Development

Successfully merging this pull request may close these issues.

None yet

5 participants