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

API enhancements for ReleaseMemoryToSystem #186

Open
mbautin opened this issue Jun 2, 2023 · 0 comments
Open

API enhancements for ReleaseMemoryToSystem #186

mbautin opened this issue Jun 2, 2023 · 0 comments

Comments

@mbautin
Copy link

mbautin commented Jun 2, 2023

tcmalloc::MallocExtension::ReleaseMemoryToSystem should ideally be improved as follows:

  • It should return the number of bytes actually released to the system. Currently it just ignores the return value of MallocExtension_Internal_ReleaseMemoryToSystem:
void MallocExtension::ReleaseMemoryToSystem(size_t num_bytes) {
#if ABSL_INTERNAL_HAVE_WEAK_MALLOCEXTENSION_STUBS
  if (&MallocExtension_Internal_ReleaseMemoryToSystem != nullptr) {
    MallocExtension_Internal_ReleaseMemoryToSystem(num_bytes);
  }
#endif
}
  • There should be a parameter to avoid invoking the logic based on extra_bytes_released, and simply release the requested number of bytes.
  // ReleaseMemoryToSystem() might release more than the requested bytes because
  // the page heap releases at the span granularity, and spans are of wildly
  // different sizes.  This keeps track of the extra bytes bytes released so
  // that the app can periodically call ReleaseMemoryToSystem() to release
  // memory at a constant rate.
  ABSL_CONST_INIT static size_t extra_bytes_released;

  absl::base_internal::SpinLockHolder rh(&release_lock);

  absl::base_internal::SpinLockHolder h(&pageheap_lock);
  if (num_bytes <= extra_bytes_released) {
    // We released too much on a prior call, so don't release any
    // more this time.
    extra_bytes_released = extra_bytes_released - num_bytes;
    num_bytes = 0;
  } else {
    num_bytes = num_bytes - extra_bytes_released;
  }
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

No branches or pull requests

1 participant