Skip to content

API enhancements for ReleaseMemoryToSystem #186

Open

Description

@mbautin

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;
  }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions