Commit 7679db6e authored by Hajime Hoshi's avatar Hajime Hoshi Committed by Commit Bot

Use resident bytes for tracking SharedMemory usage

This CL fixes SharedMemoryTracker::OnMemoryDump to use resident bytes
instead of virtual mmap-ed size so that memory-infra allocator dumps
will show accurate memory usages of shared memory.

SharedMemoryTarcker::OnMemoryDump will use CountResidentBytesInSharedMemory,
that uses syscalls (e.g. mincore on Linux). Calling those adds 1-2 [ms] in total to
create allocation dumps with one renderer, one browser and one gpu process.
See the document regarding the experiments of performance:
https://docs.google.com/document/d/1pNwUJVarTCZYaBbiZ4LUuRyTGAocCHKicnats20mLSM/edit#

Bug: 713768
Change-Id: Ied163094f9adcf4eba1c109f8ac39a1dae6bb6d3
Reviewed-on: https://chromium-review.googlesource.com/582065
Commit-Queue: Hajime Hoshi <hajimehoshi@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Reviewed-by: default avatarPrimiano Tucci <primiano@chromium.org>
Reviewed-by: default avatarSiddhartha S <ssid@chromium.org>
Cr-Commit-Position: refs/heads/master@{#490732}
parent dc7b9066
...@@ -58,27 +58,42 @@ void SharedMemoryTracker::DecrementMemoryUsage( ...@@ -58,27 +58,42 @@ void SharedMemoryTracker::DecrementMemoryUsage(
bool SharedMemoryTracker::OnMemoryDump(const trace_event::MemoryDumpArgs& args, bool SharedMemoryTracker::OnMemoryDump(const trace_event::MemoryDumpArgs& args,
trace_event::ProcessMemoryDump* pmd) { trace_event::ProcessMemoryDump* pmd) {
std::vector<std::tuple<UnguessableToken, size_t>> usages; // The fields are shared memory's ID, its resident size and its virtual size
// respectively. If a resident size is not available, a virtual size is used
// as fallback.
std::vector<std::tuple<UnguessableToken, size_t, size_t>> usages;
{ {
AutoLock hold(usages_lock_); AutoLock hold(usages_lock_);
usages.reserve(usages_.size()); usages.reserve(usages_.size());
for (const auto& usage : usages_) { for (const auto& usage : usages_) {
usages.emplace_back(usage.first->mapped_id(), usage.second); const SharedMemory* shared_memory = usage.first;
size_t virtual_size = usage.second;
size_t size = virtual_size;
#if defined(COUNT_RESIDENT_BYTES_SUPPORTED)
base::Optional<size_t> resident_size =
trace_event::ProcessMemoryDump::CountResidentBytesInSharedMemory(
*shared_memory);
if (resident_size.has_value())
size = resident_size.value();
#endif
usages.emplace_back(shared_memory->mapped_id(), size, virtual_size);
} }
} }
for (const auto& usage : usages) { for (const auto& usage : usages) {
const UnguessableToken& memory_guid = std::get<0>(usage); const UnguessableToken& memory_guid = std::get<0>(usage);
size_t size = std::get<1>(usage); size_t size = std::get<1>(usage);
size_t virtual_size = std::get<2>(usage);
std::string dump_name = GetDumpNameForTracing(memory_guid); std::string dump_name = GetDumpNameForTracing(memory_guid);
// Discard duplicates that might be seen in single-process mode. // Discard duplicates that might be seen in single-process mode.
if (pmd->GetAllocatorDump(dump_name)) if (pmd->GetAllocatorDump(dump_name))
continue; continue;
trace_event::MemoryAllocatorDump* local_dump = trace_event::MemoryAllocatorDump* local_dump =
pmd->CreateAllocatorDump(dump_name); pmd->CreateAllocatorDump(dump_name);
// TODO(hajimehoshi): The size is not resident size but virtual size so far.
// Fix this to record resident size.
local_dump->AddScalar(trace_event::MemoryAllocatorDump::kNameSize, local_dump->AddScalar(trace_event::MemoryAllocatorDump::kNameSize,
trace_event::MemoryAllocatorDump::kUnitsBytes, size); trace_event::MemoryAllocatorDump::kUnitsBytes, size);
local_dump->AddScalar("virtual_size",
trace_event::MemoryAllocatorDump::kUnitsBytes,
virtual_size);
auto global_dump_guid = GetGlobalDumpIdForTracing(memory_guid); auto global_dump_guid = GetGlobalDumpIdForTracing(memory_guid);
trace_event::MemoryAllocatorDump* global_dump = trace_event::MemoryAllocatorDump* global_dump =
pmd->CreateSharedGlobalAllocatorDump(global_dump_guid); pmd->CreateSharedGlobalAllocatorDump(global_dump_guid);
......
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