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

src: be less conservative in NearHeapLimitCallback #50718

Closed
wants to merge 1 commit into from

Conversation

joyeecheung
Copy link
Member

@joyeecheung joyeecheung commented Nov 13, 2023

Previously the callback only considered potential overhead coming from promotion. As it turns out the cache for calculated line ends could also increase heap memory usage during heap snapshot generation. This patch makes the raised limit less conservative using a formula of (young_gen_size + old_gen_size / 2) for the extra leeway given to the heap limit.

Drive-by: use uv_get_available_memory() to calculate the memory available to the process directly and print the memory in MB in the debugging logs.

Refs: #50711

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Nov 13, 2023
src/env.cc Outdated
// can only be restored when the heap usage falls down below the
// new limit, so in a heap with unbounded growth the isolate
// may eventually crash with this new limit - effectively raising
// the heap limit to the new one.
size_t new_limit = current_heap_limit + max_young_gen_size;
size_t estimated_overhead = young_gen_size + (old_gen_size / 2);
size_t new_limit = current_heap_limit + estimated_overhead;
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure about this formula - maybe we should use inital_heap_limit here as the base instead of avoid unbound growth of the new limit

Previously the callback only considered potential overhead coming
from promotion. As it turns out the cache for calculated line ends
could also increase heap memory usage during heap snapshot
generation. This patch makes the raised limit less conservative
using a formula of (young_gen_size + old_gen_size / 2) for the
extra leeway given to the heap limit.

Drive-by: use uv_get_available_memory() to calculate the memory
available to the process directly and print the memory in MB
in the debugging logs.
@joyeecheung joyeecheung force-pushed the near-heap-limit-limit branch from e9e6170 to a6616b1 Compare November 14, 2023 00:47
@joyeecheung
Copy link
Member Author

joyeecheung commented Jun 5, 2024

I believe this is no longer necessary after the changes in v8 https://issues.chromium.org/issues/42204564 that ensures the heap snapshot generation/serialization only use off-heap memory for the heap snapshot itself (need to wait until v8 12.5 update to roll it in though).

@joyeecheung joyeecheung closed this Jun 5, 2024
@joyeecheung
Copy link
Member Author

Actually on macOS, #50711 is still skipped, because of libuv/libuv#3897

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants