Skip to content

Commit

Permalink
[PA-E] Don't double-count fragmentation in memory-infra
Browse files Browse the repository at this point in the history
This is expected to improve reported memory footprint according to the
various malloc metrics for perf bots, and *.Malloc.* for UMA. This does
not correspond to any real memory footprint change, and as a consequence
Private Memory Footprint (PMF) should not move.

Note that this metric regressed on some platforms when switching to
PartitionAlloc, because of this double-counting. However, since it was
known that this footprint was not directly comparable across different
allocators, it was not used as an evaluation criterion.

Change-Id: If7640e86499f3d497e9ea5904003e3dc0f9433ea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3383815
Reviewed-by: Thiabaud Engelbrecht <thiabaud@google.com>
Reviewed-by: Siddhartha S <ssid@chromium.org>
Commit-Queue: Benoit Lize <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#959122}
  • Loading branch information
Benoit Lize authored and Chromium LUCI CQ committed Jan 14, 2022
1 parent 47651ec commit 2c36908
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions base/trace_event/malloc_dump_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,18 @@ bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
size_t allocated_objects_count = 0;
#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
uint64_t syscall_count = 0;
uint64_t pa_only_resident_size;
uint64_t pa_only_allocated_objects_size;
#endif

#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
ReportPartitionAllocStats(pmd, args.level_of_detail, &total_virtual_size,
&resident_size, &allocated_objects_size,
&syscall_count);

pa_only_resident_size = resident_size;
pa_only_allocated_objects_size = allocated_objects_size;

// Even when PartitionAlloc is used, WinHeap is still used as well, report
// its statistics.
#if OS_WIN
Expand Down Expand Up @@ -251,14 +256,28 @@ bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
allocated_objects_count);
}

if (resident_size > allocated_objects_size) {
int64_t waste = static_cast<int64_t>(resident_size) - allocated_objects_size;

// With PartitionAlloc, reported size under malloc/partitions is the resident
// size, so it already includes fragmentation. Meaning that "malloc/"'s size
// would double-count fragmentation if we report it under
// "malloc/metadata_fragmentation_caches" as well.
//
// Still report waste, as on some platforms, PartitionAlloc doesn't capture
// all of malloc()'s memory footprint.
#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
int64_t pa_waste = static_cast<int64_t>(pa_only_resident_size) -
pa_only_allocated_objects_size;
waste -= pa_waste;
#endif

if (waste > 0) {
// Explicitly specify why is extra memory resident. In mac and ios it
// accounts for the fragmentation and metadata.
MemoryAllocatorDump* other_dump =
pmd->CreateAllocatorDump("malloc/metadata_fragmentation_caches");
other_dump->AddScalar(MemoryAllocatorDump::kNameSize,
MemoryAllocatorDump::kUnitsBytes,
resident_size - allocated_objects_size);
MemoryAllocatorDump::kUnitsBytes, waste);
}

#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
Expand Down

0 comments on commit 2c36908

Please sign in to comment.