Comment #2 on issue 180 by petef4: HEAP_PROFILE_MMAP reports allocations
twice
http://code.google.com/p/google-perftools/issues/detail?id=180
Calls to mmap from the program under test is not an issue. The problem is
when a
regular new or malloc causes TCMalloc to acquire memory pages.
#include <memory>
#include <google/heap-profiler.h>
class Alloc20MiB {
char* buffer;
public:
Alloc20MiB() {
buffer = new char[20 * 1024 * 1024];
}
~Alloc20MiB() {
delete[] buffer;
}
};
int main(int argc, char* argv[]) {
const char* name = argc > 1 ? argv[1] : "default";
HeapProfilerStart(name);
std::auto_ptr<Alloc20MiB> m0(new Alloc20MiB());
HeapProfilerDump("about to make 2nd object");
std::auto_ptr<Alloc20MiB> m1(new Alloc20MiB());
HeapProfilerDump("about to exit");
}
The .0001 profile has the correct results.
Total: 20.0 MB
20.0 100.0% 100.0% 20.0 100.0% Alloc20MiB::Alloc20MiB
0.0 0.0% 100.0% 20.0 100.0% main
0.0 0.0% 100.0% 20.0 100.0% __libc_start_main
0.0 0.0% 100.0% 20.0 100.0% _start
When the program is run with HEAP_PROFILE_MMAP=true then extra memory usage
is
erroneously reported and .0001 now looks like this.
Total: 41.9 MB
20.0 47.7% 47.7% 40.1 95.5% Alloc20MiB::Alloc20MiB
20.0 47.7% 95.4% 20.0 47.7% SbrkSysAllocator::Alloc
1.9 4.6% 100.0% 1.9 4.6% DoAllocWithArena
0.0 0.0% 100.0% 41.9 100.0% main
0.0 0.0% 100.0% 20.0 47.7% ::cpp_alloc
0.0 0.0% 100.0% 0.1 0.1% AddressMap::FindCluster
0.0 0.0% 100.0% 0.1 0.1% AddressMap::Insert
0.0 0.0% 100.0% 0.1 0.1% AddressMap::New
0.0 0.0% 100.0% 0.7 1.6% HeapProfileTable::HeapProfileTable
0.0 0.0% 100.0% 0.1 0.1% HeapProfileTable::RecordAlloc
0.0 0.0% 100.0% 0.1 0.1%
HeapProfileTable::RecordAllocWithStack
0.0 0.0% 100.0% 1.9 4.5% HeapProfilerStart
0.0 0.0% 100.0% 1.9 4.6% LowLevelAlloc::AllocWithArena
0.0 0.0% 100.0% 0.1 0.1% LowLevelAlloc::NewArena
0.0 0.0% 100.0% 0.1 0.1% MallocHook::InvokeNewHook
0.0 0.0% 100.0% 0.1 0.1% MemoryRegionMap::DoInsertRegionLocked
0.0 0.0% 100.0% 0.1 0.1%
MemoryRegionMap::HandleSavedRegionsLocked
0.0 0.0% 100.0% 0.1 0.3% MemoryRegionMap::Init
0.0 0.0% 100.0% 0.1 0.1% MemoryRegionMap::InsertRegionLocked
0.0 0.0% 100.0% 0.1 0.1%
MemoryRegionMap::MyAllocator::Allocate
0.0 0.0% 100.0% 0.1 0.1% NewHook
0.0 0.0% 100.0% 1.8 4.3% ProfilerMalloc
0.0 0.0% 100.0% 0.1 0.1% RecordAlloc
0.0 0.0% 100.0% 0.1 0.1% STL_Allocator::allocate
0.0 0.0% 100.0% 41.9 100.0% __libc_start_main
0.0 0.0% 100.0% 41.9 100.0% _start
0.0 0.0% 100.0% 0.1 0.1% std::_Rb_tree::_M_create_node
0.0 0.0% 100.0% 0.1 0.1% std::_Rb_tree::_M_get_node
0.0 0.0% 100.0% 0.1 0.1% std::_Rb_tree::_M_insert
0.0 0.0% 100.0% 0.1 0.1% std::_Rb_tree::insert_unique
0.0 0.0% 100.0% 0.1 0.1% std::set::insert
The latter report can be partially cleaned up with
--ignore='DoAllocWithArena|
SbrkSysAllocator::Alloc'
Total: 41.9 MB
20.0 47.7% 47.7% 20.0 47.7% Alloc20MiB::Alloc20MiB
0.0 0.0% 47.7% 20.0 47.7% main
0.0 0.0% 47.7% 20.0 47.7% __libc_start_main
0.0 0.0% 47.7% 20.0 47.7% _start
I don't have the time to attempt a fix myself. I think that what needs to
be done
is for TCMalloc's allocators to call __sbrk rather than the sbrk version
with hooks.
In a similar manner do_mmap and co. should be called to avoid the mmap
hooks.
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings