google / google/tcmalloc

Does ReleaseMemoryToSystem(0) release memory?

Open
#89 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

In the `tcmalloc/testing/releasing_test.cc` unit test, one finds this comment.
```
119 // Try to release memory TCMalloc thinks it does not need.
120 tcmalloc::MallocExtension::ReleaseMemoryToSystem(0);
```
However, when I read the code it seems like a size of 0 here is a no-op. Am I missing something? The documentation for ReleaseMemoryToSystem doesn't say but `MallocExtension_Internal_ReleaseMemoryToSystem` says:

```
1086 // We released too much on a prior call, so don't release any
1087 // more this time.
1088 extra_bytes_released = extra_bytes_released - num_bytes;
1089 num_bytes = 0;
1101 num_pages = Length(0);
```
The `ReleaseAtLeastNPages` implementation in page_heap.cc is a no-op when there are 0 pages requested to release but the huge pages implementation looks like it will opportunistically release. Would it make sense to document 0 bytes to have a consistent meaning that all backends interpret consistently?

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.