Commit 0752ec9c authored by ssid's avatar ssid Committed by Commit bot

Add generic.total_physical_bytes property to MallocExtension

The actual physical memory usage of tcmalloc cannot be obtained by
GetNumericProperty. This accounts for the current_allocated_bytes,
fragmentation and malloc metadata, and excludes the unmapped memory
regions. This helps the user to understand how much memory is actually
being used for the allocations that were made.

This change is done only in chromium tree since the
metadata_unmapped_bytes is added only in the chromium's tcmalloc in CL:
www.crrev.com/10499004.

This is to be used by malloc dump provider for tracing.

BUG=546491

Review URL: https://codereview.chromium.org/1410353005

Cr-Commit-Position: refs/heads/master@{#357155}
parent 71929f7a
......@@ -40,23 +40,13 @@ bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
if (get_property_function) {
// If the function is not null then tcmalloc is used. See
// MallocExtension::getNumericProperty.
size_t pageheap_unmapped_bytes = 0;
bool res = get_property_function("generic.heap_size", &total_virtual_size);
DCHECK(res);
res = get_property_function("tcmalloc.pageheap_unmapped_bytes",
&pageheap_unmapped_bytes);
res = get_property_function("generic.total_physical_bytes", &resident_size);
DCHECK(res);
res = get_property_function("generic.current_allocated_bytes",
&allocated_objects_size);
DCHECK(res);
// Please see TCMallocImplementation::GetStats implementation for
// explanation
// about this math.
// TODO(ssid): Usage of metadata is not included in page heap bytes
// (crbug.com/546491). MallocExtension::GetNumericProperty will be extended
// to get this value.
resident_size = total_virtual_size - pageheap_unmapped_bytes;
} else {
struct mallinfo info = mallinfo();
DCHECK_GE(info.arena + info.hblkhd, info.uordblks);
......
......@@ -99,3 +99,4 @@ Modifications:
- Changed DEFINE_string to define const char*s instead of strings
- Disabled HEAPPROFILE envvar unless ENABLE_PROFILING is defined
- Add "ARMv8-a" to the supporting list of ARM architecture
- Add generic.total_physical_bytes property to MallocExtension
......@@ -159,6 +159,14 @@ class PERFTOOLS_DLL_DECL MallocExtension {
// freed memory regions
// This property is not writable.
//
// "generic.total_physical_bytes"
// Estimate of total bytes of the physical memory usage by the
// allocator ==
// current_allocated_bytes +
// fragmentation +
// metadata
// This property is not writable.
//
// tcmalloc
// --------
// "tcmalloc.max_total_thread_cache_bytes"
......
......@@ -678,6 +678,14 @@ class TCMallocImplementation : public MallocExtension {
return true;
}
if (strcmp(name, "generic.total_physical_bytes") == 0) {
TCMallocStats stats;
ExtractStats(&stats, NULL, NULL, NULL);
*value = stats.pageheap.system_bytes + stats.metadata_bytes -
stats.pageheap.unmapped_bytes - stats.metadata_unmapped_bytes;
return true;
}
if (strcmp(name, "tcmalloc.slack_bytes") == 0) {
// Kept for backwards compatibility. Now defined externally as:
// pageheap_free_bytes + pageheap_unmapped_bytes.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment