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

chore: run memory decommit after snapshot load/save #3828

Merged
merged 6 commits into from
Oct 6, 2024
Merged

chore: run memory decommit after snapshot load/save #3828

merged 6 commits into from
Oct 6, 2024

Conversation

kostasrim
Copy link
Contributor

@kostasrim kostasrim commented Sep 30, 2024

Sometimes for large values during snapshot loading/saving we allocate a lot of extra memory. For that, we might need to manually run memory decommit for mimalloc to release memory pages back to the OS. This PR addresses that by manually running memory decommit after each shard finishes loading or saving a snapshot.

@kostasrim kostasrim self-assigned this Sep 30, 2024
@kostasrim kostasrim changed the title [do not review] chore: run memory decommit after snapshot load/save chore: run memory decommit after snapshot load/save Sep 30, 2024
@kostasrim kostasrim marked this pull request as ready for review September 30, 2024 11:43
@kostasrim
Copy link
Contributor Author

@adiholden @chakaz

  1. I wanted to run decommit on both save and load flows. I think it would be good for both uses.
  2. We could manually run decommit after a save or load finishes (via proactor pool) but I think the current approach is simpler since all flows (both replication and command save/load) create an RdbSaver/Loader and delete it when the flow is done.

// Decommit local memory.
// We create an RdbSaver for each thread, so each one will Decommit for itself.
auto* tlocal = ServerState::tlocal();
if (tlocal) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

when is this null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tests 😄

For example LoadEmpty in rdb_test.cc, does not run RdbLoad::Load in a shard thread so it crashes.

I do not know if a similar unit test exist for rdb_save but I assumed this is the case and I added this here as well to avoid crashes like that

Copy link
Collaborator

Choose a reason for hiding this comment

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

that odd because rdb_save calls service init. please check this again why it is not set

Copy link
Contributor Author

@kostasrim kostasrim Oct 1, 2024

Choose a reason for hiding this comment

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

I don't see why this is odd. The service is created but we just don't run the rdb loader on a proactor thread

@kostasrim kostasrim requested a review from adiholden September 30, 2024 12:14
// full sync ends (since we explicitly reset the RdbLoader).
auto* tlocal = ServerState::tlocal();
if (tlocal) {
tlocal->DecommitMemory(ServerState::kDataHeap | ServerState::kBackingHeap |
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about creating a ServerState::kAllMemory to contain all bits?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

רעיון טוב

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this should mean good idea in Hebrew 🤣

@kostasrim kostasrim requested a review from chakaz September 30, 2024 14:20
chakaz
chakaz previously approved these changes Sep 30, 2024
kDataHeap = 1,
kBackingHeap = 2,
kGlibcmalloc = 4,
kAll = kDataHeap | kBackingHeap | kGlibcmalloc
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this is an anonymous enum, I'd use a more verbose name. Maybe kAllHeaps or kAllMemory?
Alternatively we can name this enum (preferably use enum class) so that it will not be confusing.
Anyway, this is a nit so feel free to ignore.

adiholden
adiholden previously approved these changes Oct 1, 2024
@kostasrim kostasrim enabled auto-merge (squash) October 1, 2024 09:11
chakaz
chakaz previously approved these changes Oct 1, 2024
@kostasrim kostasrim dismissed stale reviews from chakaz and adiholden via 1fa33b6 October 2, 2024 12:19
@kostasrim kostasrim requested review from chakaz and adiholden October 2, 2024 12:19
@kostasrim kostasrim merged commit 129ff0b into main Oct 6, 2024
12 checks passed
@kostasrim kostasrim deleted the kpr2 branch October 6, 2024 05:19
kostasrim added a commit that referenced this pull request Oct 7, 2024
Sometimes for large values during snapshot loading/saving we allocate a lot of extra memory. For that, we might need to manually run memory decommit for mimalloc to release memory pages back to the OS. This PR addresses that by manually running memory decommit after each shard finishes loading or saving a snapshot.

---------

Signed-off-by: kostas <[email protected]>
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