Skip to content

Commit

Permalink
memory-infra: Change discardable memory dump provider to use shared m…
Browse files Browse the repository at this point in the history
…emory edges

The discardable memory dump provider uses SharedMemory and should be
using the edges created by the new SharedMemoryTracker.

Bug: 661257
Change-Id: Ie20395d7696089c74ab5bdce0e6b09d66e564805
Reviewed-on: https://chromium-review.googlesource.com/607088
Reviewed-by: Hajime Hoshi <hajimehoshi@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Reviewed-by: David Reveman <reveman@chromium.org>
Commit-Queue: Siddhartha S <ssid@chromium.org>
Cr-Commit-Position: refs/heads/master@{#493566}
  • Loading branch information
ssiddhartha authored and Commit Bot committed Aug 10, 2017
1 parent 8432a8f commit 6dcb76a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 30 deletions.
7 changes: 7 additions & 0 deletions base/memory/discardable_shared_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ class BASE_EXPORT DiscardableSharedMemory {
// Returns a shared memory handle for this DiscardableSharedMemory object.
SharedMemoryHandle handle() const { return shared_memory_.handle(); }

// Returns an ID for the shared memory region. This is ID of the mapped region
// consistent across all processes and is valid as long as the region is not
// unmapped.
const UnguessableToken& mapped_id() const {
return shared_memory_.mapped_id();
}

// Locks a range of memory so that it will not be purged by the system.
// The range of memory must be unlocked. The result of trying to lock an
// already locked range is undefined. |offset| and |length| must both be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,22 +427,16 @@ void DiscardableSharedMemoryHeap::OnMemoryDump(
->GetTracingProcessId();
base::trace_event::MemoryAllocatorDumpGuid shared_segment_guid =
GetSegmentGUIDForTracing(tracing_process_id, segment_id);
// TODO(ssid): Make this weak once the GUID created is consistent
// crbug.com/661257.
pmd->CreateSharedGlobalAllocatorDump(shared_segment_guid);

// The size is added to the global dump so that it gets propagated to both the
// dumps associated.
pmd->GetSharedGlobalAllocatorDump(shared_segment_guid)
->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
base::trace_event::MemoryAllocatorDump::kUnitsBytes,
allocated_objects_size_in_bytes);

// By creating an edge with a higher |importance| (w.r.t. browser-side dumps)
// the tracing UI will account the effective size of the segment to the
// client.
const int kImportance = 2;
pmd->AddOwnershipEdge(segment_dump->guid(), shared_segment_guid, kImportance);
auto shared_memory_guid = shared_memory->mapped_id();
segment_dump->AddString("id", "hash", shared_memory_guid.ToString());
pmd->CreateWeakSharedMemoryOwnershipEdge(segment_dump->guid(),
shared_segment_guid,
shared_memory_guid, kImportance);
}

// static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ bool DiscardableSharedMemoryManager::OnMemoryDump(
if (!segment->memory()->mapped_size())
continue;

// The "size" will be inherited form the shared global dump.
// TODO(ssid): The "size" should be inherited from the shared memory dump,
// crbug.com/661257.
std::string dump_name = base::StringPrintf(
"discardable/process_%x/segment_%d", client_id, segment_id);
base::trace_event::MemoryAllocatorDump* dump =
Expand All @@ -327,24 +328,12 @@ bool DiscardableSharedMemoryManager::OnMemoryDump(
base::trace_event::MemoryAllocatorDumpGuid shared_segment_guid =
DiscardableSharedMemoryHeap::GetSegmentGUIDForTracing(
client_tracing_id, segment_id);
pmd->CreateSharedGlobalAllocatorDump(shared_segment_guid);
pmd->AddOwnershipEdge(dump->guid(), shared_segment_guid);

#if defined(COUNT_RESIDENT_BYTES_SUPPORTED)
if (args.level_of_detail ==
base::trace_event::MemoryDumpLevelOfDetail::DETAILED) {
size_t resident_size =
base::trace_event::ProcessMemoryDump::CountResidentBytes(
segment->memory()->memory(), segment->memory()->mapped_size());

// This is added to the global dump since it has to be attributed to
// both the allocator dumps involved.
pmd->GetSharedGlobalAllocatorDump(shared_segment_guid)
->AddScalar("resident_size",
base::trace_event::MemoryAllocatorDump::kUnitsBytes,
static_cast<uint64_t>(resident_size));
}
#endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED)

auto shared_memory_guid = segment->memory()->mapped_id();
dump->AddString("id", "hash", shared_memory_guid.ToString());
pmd->CreateSharedMemoryOwnershipEdge(dump->guid(), shared_segment_guid,
shared_memory_guid,
0 /* importance */);
}
}
return true;
Expand Down

0 comments on commit 6dcb76a

Please sign in to comment.