google / google/tcmalloc

API enhancements for ReleaseMemoryToSystem

Open
#186 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5.3k
Forks
570
Avg merge
23h 43m
Merged PRs (30d)
172

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.