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

Update chainbase to tip (reduce memory usage) #1575

Merged
merged 5 commits into from
Aug 30, 2023
Merged

Conversation

greg7mdp
Copy link
Contributor

@greg7mdp greg7mdp commented Aug 29, 2023

This updates the chainbase submodule to include the memory reduction optimization. Description copied below.

Reduce offset_node_base memory usage inside the RBtree of chainbase

This PR will reduce the chainbase memory usage

old implementation:

  • _parent, _left, _right, _color consume 32 bytes together (8 bytes each).

new implementation

  • _parent, _left, _right, _color consume 16 bytes (42 + 42 + 42 + 2 bits) together.
  • use -2 (instead of 2) as erased_flag since _color is a 2 bit signed int.

limitations:

  • offset pointers _parent, _left & _right only have signed 42-bit each (so 41-bit absolute value), shifted by two bits thanks to alignment, implying a maximum of chainbase size of 2^43 = 8TB.
  • offset_node_base objects must always be allocated within the same segment due to the 42-bit offset limit. Using a stack variable of offset_node_base is no longer valid (as stack address starts from 0x7fffxxxxxxxx which is too far away from heap addresses).
  • possible minor performance impact due to misalignment and extra bit operation required. Or performance could possibly be better thanks to higher memory locality.

tested results:

using mainnet snapshot snapshot-308122667.bin.tar.gz:

  • old chainbase memory usage: 28799134736
  • memory usage in this PR: 23136280976 (around 20% reduction)

[greg 8/21/2023] retested with the current PR version and confirmed the memory savings as reported by curl -X POST http://127.0.0.1:8888/v1/db_size/get after loading snapshot.

@spoonincode
Copy link
Member

Should we consider adding a validation on chain-state-db-size-mb that it's set less than 33554432 (I believe)?

@greg7mdp greg7mdp requested a review from dimas1185 August 29, 2023 19:05
Copy link
Member

@heifner heifner left a comment

Choose a reason for hiding this comment

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

I think @spoonincode idea of a limit would be good. Otherwise, LGTM.

@greg7mdp
Copy link
Contributor Author

Should we consider adding a validation on chain-state-db-size-mb that it's set less than 33554432 (I believe)?

The new limit for chainbase addressable memory is 8TB, so that would be 8388608mb I believe.

@spoonincode
Copy link
Member

ah wow didn't realize we reduced the max to 8TB

chain_config->state_size = options.at( "chain-state-db-size-mb" ).as<uint64_t>() * 1024 * 1024;
EOS_ASSERT( chain_config->state_size <= 8ull * 1024 * 1024 * 1024 * 1024, plugin_config_exception,
"The maximum supported size for the chain state db is 8TiB" );
Copy link
Member

Choose a reason for hiding this comment

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

imo it would be nice for this error message to expressly refer to chain-state-db-size-mb somehow, so the user knows exactly what knob is set too far. But, users can probably figure it out in this case anyways

@greg7mdp greg7mdp merged commit 82fc678 into main Aug 30, 2023
@greg7mdp greg7mdp deleted the update_chainbase_tip branch August 30, 2023 00:17
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