umahp: Record residency status as tags in heap profiles [chromium/src : main]

1 view
Skip to first unread message

Joe Mason (Gerrit)

unread,
Jul 10, 2026, 12:02:06 PMJul 10
to Sean Maher, Etienne Bergeron, Chromium LUCI CQ, chromium...@chromium.org, Thiabaud Engelbrecht, asvitki...@chromium.org, chromiumme...@microsoft.com, spang...@chromium.org, tracing...@chromium.org, wfh+...@chromium.org
Attention needed from Sean Maher

Joe Mason added 1 comment

Patchset-level comments
File-level comment, Patchset 8:
Sean Maher . resolved

hey joe, what do you think of the architecture here?

Joe Mason

Interesting approach. Architecture LGTM, I haven't had time to review the impl in depth though. Sorry for the delay.

Open in Gerrit

Related details

Attention is currently required from:
  • Sean Maher
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I59b98bb2e1466c325145a96df40efaa1dbc2bc88
Gerrit-Change-Number: 8062015
Gerrit-PatchSet: 10
Gerrit-Owner: Sean Maher <sp...@chromium.org>
Gerrit-Reviewer: Joe Mason <joenot...@google.com>
Gerrit-Reviewer: Sean Maher <sp...@chromium.org>
Gerrit-CC: Etienne Bergeron <etie...@chromium.org>
Gerrit-CC: Thiabaud Engelbrecht <thia...@google.com>
Gerrit-Attention: Sean Maher <sp...@chromium.org>
Gerrit-Comment-Date: Fri, 10 Jul 2026 16:01:53 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Sean Maher <sp...@chromium.org>
satisfied_requirement
unsatisfied_requirement
open
diffy

Joe Mason (Gerrit)

unread,
Jul 13, 2026, 6:00:53 PMJul 13
to Sean Maher, Etienne Bergeron, Chromium LUCI CQ, chromium...@chromium.org, Thiabaud Engelbrecht, asvitki...@chromium.org, chromiumme...@microsoft.com, spang...@chromium.org, tracing...@chromium.org, wfh+...@chromium.org
Attention needed from Sean Maher

Joe Mason added 9 comments

File base/sampling_heap_profiler/sampling_heap_profiler.cc
Line 301, Patchset 10 (Latest): std::vector<trace_event::ProcessMemoryDump::MemoryRange> ranges;
Joe Mason . unresolved

Nit: `reserve(active_samples.size())` before the for loop?

Line 307, Patchset 10 (Latest): size_t aligned_size =
Joe Mason . unresolved

Nit: Took me a while to figure out this calculation. Please add comments explaining it. (It's the distance from aligned_addr to the end of the allocation, rounded up to multiples of page_size, right?)

Line 317, Patchset 10 (Latest): resident_ranges;
Joe Mason . unresolved

Nit: could move this declaration up with `ranges` and just check the feature once.

Line 330, Patchset 10 (Latest): sample.is_resident = true;
Joe Mason . unresolved

Since a 0-byte allocation can't be real, it seems like this should be false?

Line 332, Patchset 10 (Latest): sample.is_resident = !resident_ranges.has_value() ||
Joe Mason . unresolved

Likewise, if we can't find a resident range, shouldn't is_resident be false? Or just left as nullopt?

File base/trace_event/process_memory_dump.h
Line 72, Patchset 10 (Latest): raw_ptr<void> start_address;
Joe Mason . unresolved

Because this isn't actually holding allocated memory, raw_ptr is extra overhead. I'd use uintptr_t for this, or RAW_PTR_EXCLUSION if there would be too much casting. (See https://chromium.googlesource.com/chromium/src/+/main/base/memory/raw_ptr.md#pointers-in-locations-other-than-fields, "Pointers whose addresses are used only as identifiers".)

File base/trace_event/process_memory_dump.cc
Line 95, Patchset 10 (Latest):ProcessMemoryDump::CountResidentBytes(base::span<MemoryRange> ranges) {
Joe Mason . unresolved

I think the semantics of this function would make more sense if MemoryRange had `optional<size_t> resident_bytes`, with nullopt for unknown. Then the function would just return void, and each range in `ranges` could succeed or fail separately:

```
for (auto& range : ranges) {
...
bool failure = false;
while (offset < range.size) {
...
if (failure) {
PLOG(ERROR) << "CountResidentBytes"; // Or just remove the log.
break;
}
range.resident_bytes = total_resident_pages;
offset += kMaxChunkSize;
}
}
```

Then sampling_heap_profiler.cc would set `is_resident = ranges[range_idx++].value_or(0) > 0`, or something like that.

Line 127, Patchset 10 (Latest): while (offset < range.size) {
Joe Mason . unresolved

Seems like this is doing extra work for the heap profiler case - it could stop as soon as any resident bytes are found in the range, without having to iterate through the whole thing. Maybe give MemoryRange an `optional<bool>` instead of `optional<size_t>`, and add a flag param to say whether to only fill in the bools or also calculate `total_resident_pages`?

File components/services/heap_profiling/public/cpp/merge_samples.cc
Line 26, Patchset 10 (Latest): return lhs.is_resident < rhs.is_resident;
Joe Mason . unresolved

Nit: the standard way to do this is `std::tie(lhs.stack, lhs.is_resident) < std::tie(rhs.stack, rhs.is_resident)`. I *think* your code is equivalent, but I'm too tired to be certain right now, and using std::tie would be easier for other people reading this later.

Open in Gerrit

Related details

Attention is currently required from:
  • Sean Maher
Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: I59b98bb2e1466c325145a96df40efaa1dbc2bc88
    Gerrit-Change-Number: 8062015
    Gerrit-PatchSet: 10
    Gerrit-Owner: Sean Maher <sp...@chromium.org>
    Gerrit-Reviewer: Joe Mason <joenot...@google.com>
    Gerrit-Reviewer: Sean Maher <sp...@chromium.org>
    Gerrit-CC: Etienne Bergeron <etie...@chromium.org>
    Gerrit-CC: Thiabaud Engelbrecht <thia...@google.com>
    Gerrit-Attention: Sean Maher <sp...@chromium.org>
    Gerrit-Comment-Date: Mon, 13 Jul 2026 22:00:41 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Sean Maher (Gerrit)

    unread,
    Jul 16, 2026, 12:33:31 PMJul 16
    to Etienne Bergeron, Chromium LUCI CQ, chromium...@chromium.org, Thiabaud Engelbrecht, asvitki...@chromium.org, chromiumme...@microsoft.com, spang...@chromium.org, tracing...@chromium.org, wfh+...@chromium.org
    Attention needed from Joe Mason

    Sean Maher added 9 comments

    File base/sampling_heap_profiler/sampling_heap_profiler.cc
    Line 301, Patchset 10: std::vector<trace_event::ProcessMemoryDump::MemoryRange> ranges;
    Joe Mason . resolved

    Nit: `reserve(active_samples.size())` before the for loop?

    Sean Maher

    Done

    Line 307, Patchset 10: size_t aligned_size =
    Joe Mason . resolved

    Nit: Took me a while to figure out this calculation. Please add comments explaining it. (It's the distance from aligned_addr to the end of the allocation, rounded up to multiples of page_size, right?)

    Sean Maher

    yep. hopefully made it more clear

    Line 317, Patchset 10: resident_ranges;
    Joe Mason . resolved

    Nit: could move this declaration up with `ranges` and just check the feature once.

    Sean Maher

    Done

    Line 330, Patchset 10: sample.is_resident = true;
    Joe Mason . resolved

    Since a 0-byte allocation can't be real, it seems like this should be false?

    Sean Maher

    i actually disagree, but i left it as nullopt.

    Line 332, Patchset 10: sample.is_resident = !resident_ranges.has_value() ||
    Joe Mason . resolved

    Likewise, if we can't find a resident range, shouldn't is_resident be false? Or just left as nullopt?

    Sean Maher

    ok, left it as nullopt.

    File base/trace_event/process_memory_dump.h
    Line 72, Patchset 10: raw_ptr<void> start_address;
    Joe Mason . resolved

    Because this isn't actually holding allocated memory, raw_ptr is extra overhead. I'd use uintptr_t for this, or RAW_PTR_EXCLUSION if there would be too much casting. (See https://chromium.googlesource.com/chromium/src/+/main/base/memory/raw_ptr.md#pointers-in-locations-other-than-fields, "Pointers whose addresses are used only as identifiers".)

    Sean Maher

    Done

    File base/trace_event/process_memory_dump.cc
    Line 95, Patchset 10:ProcessMemoryDump::CountResidentBytes(base::span<MemoryRange> ranges) {
    Joe Mason . resolved

    I think the semantics of this function would make more sense if MemoryRange had `optional<size_t> resident_bytes`, with nullopt for unknown. Then the function would just return void, and each range in `ranges` could succeed or fail separately:

    ```
    for (auto& range : ranges) {
    ...
    bool failure = false;
    while (offset < range.size) {
    ...
    if (failure) {
    PLOG(ERROR) << "CountResidentBytes"; // Or just remove the log.
    break;
    }
    range.resident_bytes = total_resident_pages;
    offset += kMaxChunkSize;
    }
    }
    ```

    Then sampling_heap_profiler.cc would set `is_resident = ranges[range_idx++].value_or(0) > 0`, or something like that.

    Sean Maher

    mostly done, but with std::nullopt propagation instead.

    Line 127, Patchset 10: while (offset < range.size) {
    Joe Mason . resolved

    Seems like this is doing extra work for the heap profiler case - it could stop as soon as any resident bytes are found in the range, without having to iterate through the whole thing. Maybe give MemoryRange an `optional<bool>` instead of `optional<size_t>`, and add a flag param to say whether to only fill in the bools or also calculate `total_resident_pages`?

    Sean Maher

    I am redoing this to use all the information.

    File components/services/heap_profiling/public/cpp/merge_samples.cc
    Line 26, Patchset 10: return lhs.is_resident < rhs.is_resident;
    Joe Mason . resolved

    Nit: the standard way to do this is `std::tie(lhs.stack, lhs.is_resident) < std::tie(rhs.stack, rhs.is_resident)`. I *think* your code is equivalent, but I'm too tired to be certain right now, and using std::tie would be easier for other people reading this later.

    Sean Maher

    Acknowledged, reverted anyways.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Joe Mason
    Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement is not satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I59b98bb2e1466c325145a96df40efaa1dbc2bc88
      Gerrit-Change-Number: 8062015
      Gerrit-PatchSet: 18
      Gerrit-Owner: Sean Maher <sp...@chromium.org>
      Gerrit-Reviewer: Joe Mason <joenot...@google.com>
      Gerrit-Reviewer: Sean Maher <sp...@chromium.org>
      Gerrit-CC: Etienne Bergeron <etie...@chromium.org>
      Gerrit-CC: Thiabaud Engelbrecht <thia...@google.com>
      Gerrit-Attention: Joe Mason <joenot...@google.com>
      Gerrit-Comment-Date: Thu, 16 Jul 2026 16:33:21 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Joe Mason <joenot...@google.com>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Joe Mason (Gerrit)

      unread,
      Jul 24, 2026, 1:40:29 PM (13 days ago) Jul 24
      to Sean Maher, Chromium Metrics Reviews, android-bu...@system.gserviceaccount.com, Etienne Bergeron, Chromium LUCI CQ, chromium...@chromium.org, Thiabaud Engelbrecht, asvitkine...@chromium.org, storage...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com, spang...@chromium.org, tracing...@chromium.org, wfh+...@chromium.org
      Attention needed from Sean Maher

      Joe Mason added 3 comments

      File base/sampling_heap_profiler/sampling_heap_profiler.cc
      Line 323, Patchset 39 (Latest): if (ranges[range_idx].resident_bytes.has_value() && sample.size > 0) {
      Joe Mason . unresolved

      Nit: >0 check is redundant, since size is unsigned.

      Line 330, Patchset 39 (Latest): sample.resident_total = static_cast<size_t>(
      Joe Mason . unresolved

      Nit: use `base::checked_cast` here? It looks like the llround should never overflow `size_t` since all the inputs are size_t, but that would verify it. (Or `base::saturated_cast` if it's possible for the result to be large, and we just want that to set resident_total to the max.)

      Line 332, Patchset 39 (Latest): (*ranges[range_idx].resident_bytes) / sample.size));
      Joe Mason . unresolved

      Nit: putting `resident_bytes` in a temporary would make this more clear. I miscounted the parens when I first read this and thought there was an order-of-operations bug.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Sean Maher
      Submit Requirements:
        • requirement satisfiedCode-Coverage
        • requirement is not satisfiedCode-Owners
        • requirement is not satisfiedCode-Review
        • requirement is not satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: chromium/src
        Gerrit-Branch: main
        Gerrit-Change-Id: I59b98bb2e1466c325145a96df40efaa1dbc2bc88
        Gerrit-Change-Number: 8062015
        Gerrit-PatchSet: 39
        Gerrit-Owner: Sean Maher <sp...@chromium.org>
        Gerrit-Reviewer: Joe Mason <joenot...@google.com>
        Gerrit-Reviewer: Sean Maher <sp...@chromium.org>
        Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
        Gerrit-CC: Etienne Bergeron <etie...@chromium.org>
        Gerrit-CC: Thiabaud Engelbrecht <thia...@google.com>
        Gerrit-Attention: Sean Maher <sp...@chromium.org>
        Gerrit-Comment-Date: Fri, 24 Jul 2026 17:40:03 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Joe Mason (Gerrit)

        unread,
        Jul 24, 2026, 3:02:27 PM (13 days ago) Jul 24
        to Sean Maher, Chromium Metrics Reviews, android-bu...@system.gserviceaccount.com, Etienne Bergeron, Chromium LUCI CQ, chromium...@chromium.org, Thiabaud Engelbrecht, asvitkine...@chromium.org, storage...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com, spang...@chromium.org, tracing...@chromium.org, wfh+...@chromium.org
        Attention needed from Sean Maher

        Joe Mason added 11 comments

        File base/sampling_heap_profiler/sampling_heap_profiler_unittest.cc
        Line 403, Patchset 39 (Latest): profiler->SetSamplingInterval(1024);
        Joe Mason . unresolved

        Nit: should also create a `PoissonAllocationSampler::ScopedSuppressRandomnessForTesting` object. That will make it sample at EXACTLY 1024 bytes, to avoid test flakes if it happens to sample more rarely than expected.

        Line 420, Patchset 39 (Latest): if (sample.resident_total.has_value()) {
        Joe Mason . unresolved

        Optional nit: When I first read this I thought the `if` meant the `resident_total` might not actually be set during the test, which confused me. It'd be more clear to use `ASSERT_TRUE(has_value())` which returns early if it's false, or gmock's EXPECT_THAT and Optional:

        `EXPECT_THAT(sample.resident_total, ::testing::Optional(::testing::Gt(0u)))`

        File base/trace_event/process_memory_dump.cc
        Line 105, Patchset 39 (Latest): max_mapped_size = std::max(max_mapped_size, range.size);
        Joe Mason . unresolved

        I don't think this is always the right max: for each entry in the range the `mapped_size` below is `aligned_end - aligned_start` and here it's just `end - start`. That could mean that an allocation that happens to be near the end of a page would span 2 pages, but this would only return 1 page. Which in turn could mean that `page_count` calculated below could be higher than the size of `vec`.

        (Also since this doesn't correspond exactly to `mapped_size` it should have a different name.)

        How about just dropping this calculation and always allocating a vector for kMaxChunkSize? It would be less efficient when querying a small amount of already-aligned memory, but that's probably not significant compared to the cost of actually calling mincore / QueryWorkingSetEx.

        Or you could repeat the calculation to find the fully aligned `mapped_size` in this loop.

        A trivial example of this: `ranges` has one entry, with a valid `start_pointer` and size `0`. `max_vec_size` will be 0, but `aligned_end` - `aligned_start` gives 1 page.

        Line 119, Patchset 39 (Latest): for (auto& range : ranges) {
        Joe Mason . unresolved

        Nit: might want to check for `range.size` 0 and continue immediately. Otherwise it'll do the work to query 1 page even though the accumulate function will always find 0 overlap. As long as `vec` isn't empty, that'd work, it's just inefficient.

        Line 122, Patchset 39 (Latest): base::bits::AlignDown(start_pointer, page_size);
        Joe Mason . resolved

        Nice! I didn't know about that func.

        Line 130, Patchset 39 (Latest): uintptr_t chunk_start = aligned_start + offset;
        Joe Mason . unresolved

        Nit: I think these calculations only work if kMaxChunkSize is an exact multiple of page_size. Otherwise `chunk_start` would end up within a page, and `page_addr` below wouldn't make sense. Can you add a CHECK for that at the start of the function, just in case?

        Line 135, Patchset 39 (Latest): [[maybe_unused]] auto accumulate_page_if_resident =
        Joe Mason . unresolved

        Nit: is the `maybe_unused` still needed with the `std:ignore` in the fuschia branch?

        Line 219, Patchset 39 (Latest): UNSAFE_BUFFERS(CountResidentBytes(base::span(&range, 1u)));
        Joe Mason . unresolved

        Nit: `base::span_from_ref(range)` won't need the UNSAFE_BUFFERS annotation.

        Line 245, Patchset 39 (Latest): const uintptr_t start_ptr =
        Joe Mason . unresolved

        What are all these changes for? Nothing in the patch calls CountResidentBytesInSharedMemory so they can't be necessary for it, and the original code didn't call CountResidentBytes so shouldn't be affected by any changes to it.

        File base/trace_event/process_memory_dump_unittest.cc
        Line 478, Patchset 39 (Latest): std::ranges::fill(memory2, 0u);
        Joe Mason . unresolved

        Nit: let's add a range with a size 0 alloc, to test the edge case.

        Also maybe a range with deallocated memory that should have 0 resident bytes. (Unless unmapping doesn't always mark the memory non-resident immediately, in which case that would be flaky.)

        Oh, another good test would be an unaligned pointer partway into one of the maps.

        Line 537, Patchset 39 (Latest): ASSERT_EQ(res1.value(), kDirtyMemorySize + page_size / 2);
        Joe Mason . unresolved

        I assume this is only needed because of the changes to CountResidentBytesInSharedMemory?

        Gerrit-Comment-Date: Fri, 24 Jul 2026 19:01:58 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Sean Maher (Gerrit)

        unread,
        Jul 28, 2026, 4:14:46 PM (9 days ago) Jul 28
        to Chromium Metrics Reviews, android-bu...@system.gserviceaccount.com, Etienne Bergeron, Chromium LUCI CQ, chromium...@chromium.org, Thiabaud Engelbrecht, asvitkine...@chromium.org, storage...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com, spang...@chromium.org, tracing...@chromium.org, wfh+...@chromium.org
        Attention needed from Joe Mason

        Sean Maher added 13 comments

        File base/sampling_heap_profiler/sampling_heap_profiler.cc
        Line 323, Patchset 39: if (ranges[range_idx].resident_bytes.has_value() && sample.size > 0) {
        Joe Mason . resolved

        Nit: >0 check is redundant, since size is unsigned.

        Sean Maher

        Done

        Line 330, Patchset 39: sample.resident_total = static_cast<size_t>(
        Joe Mason . resolved

        Nit: use `base::checked_cast` here? It looks like the llround should never overflow `size_t` since all the inputs are size_t, but that would verify it. (Or `base::saturated_cast` if it's possible for the result to be large, and we just want that to set resident_total to the max.)

        Sean Maher

        Done

        Line 332, Patchset 39: (*ranges[range_idx].resident_bytes) / sample.size));
        Joe Mason . resolved

        Nit: putting `resident_bytes` in a temporary would make this more clear. I miscounted the parens when I first read this and thought there was an order-of-operations bug.

        Sean Maher

        Done

        File base/sampling_heap_profiler/sampling_heap_profiler_unittest.cc
        Line 403, Patchset 39: profiler->SetSamplingInterval(1024);
        Joe Mason . resolved

        Nit: should also create a `PoissonAllocationSampler::ScopedSuppressRandomnessForTesting` object. That will make it sample at EXACTLY 1024 bytes, to avoid test flakes if it happens to sample more rarely than expected.

        Sean Maher

        Done

        Line 420, Patchset 39: if (sample.resident_total.has_value()) {
        Joe Mason . resolved

        Optional nit: When I first read this I thought the `if` meant the `resident_total` might not actually be set during the test, which confused me. It'd be more clear to use `ASSERT_TRUE(has_value())` which returns early if it's false, or gmock's EXPECT_THAT and Optional:

        `EXPECT_THAT(sample.resident_total, ::testing::Optional(::testing::Gt(0u)))`

        Sean Maher

        Done

        File base/trace_event/process_memory_dump.cc
        Line 105, Patchset 39: max_mapped_size = std::max(max_mapped_size, range.size);
        Joe Mason . resolved

        I don't think this is always the right max: for each entry in the range the `mapped_size` below is `aligned_end - aligned_start` and here it's just `end - start`. That could mean that an allocation that happens to be near the end of a page would span 2 pages, but this would only return 1 page. Which in turn could mean that `page_count` calculated below could be higher than the size of `vec`.

        (Also since this doesn't correspond exactly to `mapped_size` it should have a different name.)

        How about just dropping this calculation and always allocating a vector for kMaxChunkSize? It would be less efficient when querying a small amount of already-aligned memory, but that's probably not significant compared to the cost of actually calling mincore / QueryWorkingSetEx.

        Or you could repeat the calculation to find the fully aligned `mapped_size` in this loop.

        A trivial example of this: `ranges` has one entry, with a valid `start_pointer` and size `0`. `max_vec_size` will be 0, but `aligned_end` - `aligned_start` gives 1 page.

        Sean Maher

        right, i think this fixes it.

        Line 119, Patchset 39: for (auto& range : ranges) {
        Joe Mason . resolved

        Nit: might want to check for `range.size` 0 and continue immediately. Otherwise it'll do the work to query 1 page even though the accumulate function will always find 0 overlap. As long as `vec` isn't empty, that'd work, it's just inefficient.

        Sean Maher

        Done

        Line 130, Patchset 39: uintptr_t chunk_start = aligned_start + offset;
        Joe Mason . resolved

        Nit: I think these calculations only work if kMaxChunkSize is an exact multiple of page_size. Otherwise `chunk_start` would end up within a page, and `page_addr` below wouldn't make sense. Can you add a CHECK for that at the start of the function, just in case?

        Sean Maher

        Marked as resolved.

        Line 135, Patchset 39: [[maybe_unused]] auto accumulate_page_if_resident =
        Joe Mason . resolved

        Nit: is the `maybe_unused` still needed with the `std:ignore` in the fuschia branch?

        Sean Maher

        Done

        Line 219, Patchset 39: UNSAFE_BUFFERS(CountResidentBytes(base::span(&range, 1u)));
        Joe Mason . resolved

        Nit: `base::span_from_ref(range)` won't need the UNSAFE_BUFFERS annotation.

        Sean Maher

        Done

        Line 245, Patchset 39: const uintptr_t start_ptr =
        Joe Mason . unresolved

        What are all these changes for? Nothing in the patch calls CountResidentBytesInSharedMemory so they can't be necessary for it, and the original code didn't call CountResidentBytes so shouldn't be affected by any changes to it.

        Sean Maher

        getting rid of divergent behavior between two functions that are almost identically named. i could keep the divergent behavior, and just add a comment if you'd prefer this. I don't mind, just assumed it'd be better to have both deliver similar APIs

        File base/trace_event/process_memory_dump_unittest.cc
        Line 478, Patchset 39: std::ranges::fill(memory2, 0u);
        Joe Mason . resolved

        Nit: let's add a range with a size 0 alloc, to test the edge case.

        Also maybe a range with deallocated memory that should have 0 resident bytes. (Unless unmapping doesn't always mark the memory non-resident immediately, in which case that would be flaky.)

        Oh, another good test would be an unaligned pointer partway into one of the maps.

        Sean Maher

        Done

        Line 537, Patchset 39: ASSERT_EQ(res1.value(), kDirtyMemorySize + page_size / 2);
        Joe Mason . unresolved

        I assume this is only needed because of the changes to CountResidentBytesInSharedMemory?

        Sean Maher

        yes

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Joe Mason
        Submit Requirements:
        • requirement satisfiedCode-Coverage
        • requirement is not satisfiedCode-Owners
        • requirement is not satisfiedCode-Review
        • requirement is not satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: chromium/src
        Gerrit-Branch: main
        Gerrit-Change-Id: I59b98bb2e1466c325145a96df40efaa1dbc2bc88
        Gerrit-Change-Number: 8062015
        Gerrit-PatchSet: 44
        Gerrit-Owner: Sean Maher <sp...@chromium.org>
        Gerrit-Reviewer: Joe Mason <joenot...@google.com>
        Gerrit-Reviewer: Sean Maher <sp...@chromium.org>
        Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
        Gerrit-CC: Etienne Bergeron <etie...@chromium.org>
        Gerrit-CC: Thiabaud Engelbrecht <thia...@google.com>
        Gerrit-Attention: Joe Mason <joenot...@google.com>
        Gerrit-Comment-Date: Tue, 28 Jul 2026 20:14:39 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        Comment-In-Reply-To: Joe Mason <joenot...@google.com>
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Joe Mason (Gerrit)

        unread,
        Jul 28, 2026, 6:16:53 PM (8 days ago) Jul 28
        to Sean Maher, Chromium Metrics Reviews, android-bu...@system.gserviceaccount.com, Etienne Bergeron, Chromium LUCI CQ, chromium...@chromium.org, Thiabaud Engelbrecht, asvitkine...@chromium.org, storage...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com, spang...@chromium.org, tracing...@chromium.org, wfh+...@chromium.org
        Attention needed from Sean Maher

        Joe Mason voted and added 2 comments

        Votes added by Joe Mason

        Code-Review+1

        2 comments

        Patchset-level comments
        File-level comment, Patchset 44 (Latest):
        Joe Mason . resolved

        LGTM if the CountResidentBytesInSharedMemory are removed (I haven't reviewed them).

        File base/trace_event/process_memory_dump.cc
        Line 245, Patchset 39: const uintptr_t start_ptr =
        Joe Mason . unresolved

        What are all these changes for? Nothing in the patch calls CountResidentBytesInSharedMemory so they can't be necessary for it, and the original code didn't call CountResidentBytes so shouldn't be affected by any changes to it.

        Sean Maher

        getting rid of divergent behavior between two functions that are almost identically named. i could keep the divergent behavior, and just add a comment if you'd prefer this. I don't mind, just assumed it'd be better to have both deliver similar APIs

        Joe Mason

        Let's put a TODO comment "let CountResidentBytesInSharedMemory support unaligned addresses" in this patch, and move the changes to it to a followup. That way if there's a mistake in this fiddly math, it can be reverted separately.

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Sean Maher
        Submit Requirements:
          • requirement satisfiedCode-Coverage
          • requirement is not satisfiedCode-Owners
          • requirement satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement satisfiedReview-Enforcement
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: chromium/src
          Gerrit-Branch: main
          Gerrit-Change-Id: I59b98bb2e1466c325145a96df40efaa1dbc2bc88
          Gerrit-Change-Number: 8062015
          Gerrit-PatchSet: 44
          Gerrit-Owner: Sean Maher <sp...@chromium.org>
          Gerrit-Reviewer: Joe Mason <joenot...@google.com>
          Gerrit-Reviewer: Sean Maher <sp...@chromium.org>
          Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
          Gerrit-CC: Etienne Bergeron <etie...@chromium.org>
          Gerrit-CC: Thiabaud Engelbrecht <thia...@google.com>
          Gerrit-Attention: Sean Maher <sp...@chromium.org>
          Gerrit-Comment-Date: Tue, 28 Jul 2026 22:16:26 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: Yes
          Comment-In-Reply-To: Joe Mason <joenot...@google.com>
          Comment-In-Reply-To: Sean Maher <sp...@chromium.org>
          satisfied_requirement
          unsatisfied_requirement
          open
          diffy

          Joe Mason (Gerrit)

          unread,
          Jul 28, 2026, 6:18:23 PM (8 days ago) Jul 28
          to Sean Maher, Chromium Metrics Reviews, android-bu...@system.gserviceaccount.com, Etienne Bergeron, Chromium LUCI CQ, chromium...@chromium.org, Thiabaud Engelbrecht, asvitkine...@chromium.org, storage...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com, spang...@chromium.org, tracing...@chromium.org, wfh+...@chromium.org
          Attention needed from Sean Maher

          Joe Mason added 2 comments

          Patchset-level comments
          Joe Mason . unresolved

          LGTM if the CountResidentBytesInSharedMemory are removed (I haven't reviewed them).

          Joe Mason

          And I see I'm not OWNER of that file anyway, so if Etienne reviews and approves those changes, go ahead and commit.

          File base/trace_event/process_memory_dump_unittest.cc
          Line 537, Patchset 39: ASSERT_EQ(res1.value(), kDirtyMemorySize + page_size / 2);
          Joe Mason . resolved

          I assume this is only needed because of the changes to CountResidentBytesInSharedMemory?

          Sean Maher

          yes

          Joe Mason

          Acknowledged

          Gerrit-Comment-Date: Tue, 28 Jul 2026 22:18:16 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: No
          satisfied_requirement
          unsatisfied_requirement
          open
          diffy

          Sean Maher (Gerrit)

          unread,
          Jul 29, 2026, 11:06:25 AM (8 days ago) Jul 29
          to Etienne Pierre-Doray, Chromium Metrics Reviews, android-bu...@system.gserviceaccount.com, Etienne Bergeron, Chromium LUCI CQ, chromium...@chromium.org, Thiabaud Engelbrecht, asvitkine...@chromium.org, storage...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com, spang...@chromium.org, tracing...@chromium.org, wfh+...@chromium.org
          Attention needed from Etienne Pierre-Doray

          Sean Maher added 1 comment

          File base/trace_event/process_memory_dump.cc
          Line 245, Patchset 39: const uintptr_t start_ptr =
          Joe Mason . resolved

          What are all these changes for? Nothing in the patch calls CountResidentBytesInSharedMemory so they can't be necessary for it, and the original code didn't call CountResidentBytes so shouldn't be affected by any changes to it.

          Sean Maher

          getting rid of divergent behavior between two functions that are almost identically named. i could keep the divergent behavior, and just add a comment if you'd prefer this. I don't mind, just assumed it'd be better to have both deliver similar APIs

          Joe Mason

          Let's put a TODO comment "let CountResidentBytesInSharedMemory support unaligned addresses" in this patch, and move the changes to it to a followup. That way if there's a mistake in this fiddly math, it can be reverted separately.

          Sean Maher

          Done

          Open in Gerrit

          Related details

          Attention is currently required from:
          • Etienne Pierre-Doray
          Submit Requirements:
            • requirement satisfiedCode-Coverage
            • requirement is not satisfiedCode-Owners
            • requirement satisfiedCode-Review
            • requirement is not satisfiedNo-Unresolved-Comments
            • requirement is not satisfiedReview-Enforcement
            Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
            Gerrit-MessageType: comment
            Gerrit-Project: chromium/src
            Gerrit-Branch: main
            Gerrit-Change-Id: I59b98bb2e1466c325145a96df40efaa1dbc2bc88
            Gerrit-Change-Number: 8062015
            Gerrit-PatchSet: 45
            Gerrit-Owner: Sean Maher <sp...@chromium.org>
            Gerrit-Reviewer: Etienne Pierre-Doray <etie...@chromium.org>
            Gerrit-Reviewer: Joe Mason <joenot...@google.com>
            Gerrit-Reviewer: Sean Maher <sp...@chromium.org>
            Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
            Gerrit-CC: Etienne Bergeron <etie...@chromium.org>
            Gerrit-CC: Thiabaud Engelbrecht <thia...@google.com>
            Gerrit-Attention: Etienne Pierre-Doray <etie...@chromium.org>
            Gerrit-Comment-Date: Wed, 29 Jul 2026 15:06:13 +0000
            satisfied_requirement
            unsatisfied_requirement
            open
            diffy

            Sean Maher (Gerrit)

            unread,
            Jul 29, 2026, 11:07:20 AM (8 days ago) Jul 29
            to Etienne Pierre-Doray, Chromium Metrics Reviews, android-bu...@system.gserviceaccount.com, Etienne Bergeron, Chromium LUCI CQ, chromium...@chromium.org, Thiabaud Engelbrecht, asvitkine...@chromium.org, storage...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com, spang...@chromium.org, tracing...@chromium.org, wfh+...@chromium.org
            Attention needed from Etienne Pierre-Doray

            Sean Maher added 2 comments

            Patchset-level comments

            LGTM if the CountResidentBytesInSharedMemory are removed (I haven't reviewed them).

            Joe Mason

            And I see I'm not OWNER of that file anyway, so if Etienne reviews and approves those changes, go ahead and commit.

            Sean Maher

            I'll have him review the follow-up, good call on moving the changes out.

            File-level comment, Patchset 45 (Latest):
            Sean Maher . resolved

            etiennep@, can you PTAL @ the process memory dump changes?

            Open in Gerrit

            Related details

            Attention is currently required from:
            • Etienne Pierre-Doray
            Submit Requirements:
              • requirement satisfiedCode-Coverage
              • requirement is not satisfiedCode-Owners
              • requirement satisfiedCode-Review
              • requirement is not satisfiedReview-Enforcement
              Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
              Gerrit-MessageType: comment
              Gerrit-Project: chromium/src
              Gerrit-Branch: main
              Gerrit-Change-Id: I59b98bb2e1466c325145a96df40efaa1dbc2bc88
              Gerrit-Change-Number: 8062015
              Gerrit-PatchSet: 45
              Gerrit-Owner: Sean Maher <sp...@chromium.org>
              Gerrit-Reviewer: Etienne Pierre-Doray <etie...@chromium.org>
              Gerrit-Reviewer: Joe Mason <joenot...@google.com>
              Gerrit-Reviewer: Sean Maher <sp...@chromium.org>
              Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
              Gerrit-CC: Etienne Bergeron <etie...@chromium.org>
              Gerrit-CC: Thiabaud Engelbrecht <thia...@google.com>
              Gerrit-Attention: Etienne Pierre-Doray <etie...@chromium.org>
              Gerrit-Comment-Date: Wed, 29 Jul 2026 15:07:10 +0000
              satisfied_requirement
              unsatisfied_requirement
              open
              diffy

              Etienne Pierre-Doray (Gerrit)

              unread,
              Aug 5, 2026, 10:59:16 AM (17 hours ago) Aug 5
              to Sean Maher, Chromium Metrics Reviews, android-bu...@system.gserviceaccount.com, Etienne Bergeron, Chromium LUCI CQ, chromium...@chromium.org, Thiabaud Engelbrecht, asvitkine...@chromium.org, storage...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com, spang...@chromium.org, tracing...@chromium.org, wfh+...@chromium.org
              Attention needed from Sean Maher

              Etienne Pierre-Doray voted and added 1 comment

              Votes added by Etienne Pierre-Doray

              Code-Review+1

              1 comment

              Patchset-level comments
              File-level comment, Patchset 50 (Latest):
              Etienne Pierre-Doray . resolved

              base/trace_event LGTM

              Open in Gerrit

              Related details

              Attention is currently required from:
              • Sean Maher
              Submit Requirements:
                • requirement satisfiedCode-Coverage
                • requirement is not satisfiedCode-Owners
                • requirement satisfiedCode-Review
                • requirement satisfiedReview-Enforcement
                Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
                Gerrit-MessageType: comment
                Gerrit-Project: chromium/src
                Gerrit-Branch: main
                Gerrit-Change-Id: I59b98bb2e1466c325145a96df40efaa1dbc2bc88
                Gerrit-Change-Number: 8062015
                Gerrit-PatchSet: 50
                Gerrit-Owner: Sean Maher <sp...@chromium.org>
                Gerrit-Reviewer: Etienne Pierre-Doray <etie...@chromium.org>
                Gerrit-Reviewer: Joe Mason <joenot...@google.com>
                Gerrit-Reviewer: Sean Maher <sp...@chromium.org>
                Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
                Gerrit-CC: Etienne Bergeron <etie...@chromium.org>
                Gerrit-CC: Thiabaud Engelbrecht <thia...@google.com>
                Gerrit-Attention: Sean Maher <sp...@chromium.org>
                Gerrit-Comment-Date: Wed, 05 Aug 2026 14:59:03 +0000
                Gerrit-HasComments: Yes
                Gerrit-Has-Labels: Yes
                satisfied_requirement
                unsatisfied_requirement
                open
                diffy

                Etienne Pierre-Doray (Gerrit)

                unread,
                Aug 5, 2026, 11:03:57 AM (17 hours ago) Aug 5
                to Sean Maher, Chromium Metrics Reviews, android-bu...@system.gserviceaccount.com, Etienne Bergeron, Chromium LUCI CQ, chromium...@chromium.org, Thiabaud Engelbrecht, asvitkine...@chromium.org, storage...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com, spang...@chromium.org, tracing...@chromium.org, wfh+...@chromium.org
                Attention needed from Sean Maher

                Etienne Pierre-Doray added 1 comment

                File base/trace_event/process_memory_dump.h
                Line 63, Patchset 50 (Latest): // Returns the number of bytes in a kernel memory page. Some platforms may
                // have a different value for kernel page sizes from user page sizes. It is
                // important to use kernel memory page sizes for resident bytes calculation.
                // In most cases, the two are the same.
                static size_t GetSystemPageSize();

                // Returns the total bytes resident for a virtual address range, with given
                // |start_address| and |mapped_size|. |mapped_size| is specified in bytes. The
                // value returned is valid only if the given range is currently mmapped by the
                // process. Works with exact non-page-aligned boundaries, but precisely
                // page-aligned boundaries are performance-ideal. The returned value will
                // never exceed |mapped_size|.
                static std::optional<size_t> CountResidentBytes(void* start_address,
                size_t mapped_size);

                // The same as above, but the given mapped range should belong to the
                // shared_memory's mapped region. The |start_address| must be page-aligned.
                // TODO: let CountResidentBytesInSharedMemory support unaligned addresses
                static std::optional<size_t> CountResidentBytesInSharedMemory(
                void* start_address,
                size_t mapped_size);
                Etienne Pierre-Doray . unresolved

                Nit (feel free to ignore or punt): I feel like this has no place in base/trace_event/ and base/process/process_metrics.h would be the right place for these.

                Open in Gerrit

                Related details

                Attention is currently required from:
                • Sean Maher
                Submit Requirements:
                  • requirement satisfiedCode-Coverage
                  • requirement is not satisfiedCode-Owners
                  • requirement satisfiedCode-Review
                  • requirement is not satisfiedNo-Unresolved-Comments
                  • requirement satisfiedReview-Enforcement
                  Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
                  Gerrit-MessageType: comment
                  Gerrit-Project: chromium/src
                  Gerrit-Branch: main
                  Gerrit-Change-Id: I59b98bb2e1466c325145a96df40efaa1dbc2bc88
                  Gerrit-Change-Number: 8062015
                  Gerrit-PatchSet: 50
                  Gerrit-Owner: Sean Maher <sp...@chromium.org>
                  Gerrit-Reviewer: Etienne Pierre-Doray <etie...@chromium.org>
                  Gerrit-Reviewer: Joe Mason <joenot...@google.com>
                  Gerrit-Reviewer: Sean Maher <sp...@chromium.org>
                  Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
                  Gerrit-CC: Etienne Bergeron <etie...@chromium.org>
                  Gerrit-CC: Thiabaud Engelbrecht <thia...@google.com>
                  Gerrit-Attention: Sean Maher <sp...@chromium.org>
                  Gerrit-Comment-Date: Wed, 05 Aug 2026 15:03:44 +0000
                  Gerrit-HasComments: Yes
                  Gerrit-Has-Labels: No
                  satisfied_requirement
                  unsatisfied_requirement
                  open
                  diffy

                  Sean Maher (Gerrit)

                  unread,
                  Aug 5, 2026, 4:55:51 PM (11 hours ago) Aug 5
                  to Gabriel Charette, Etienne Pierre-Doray, Chromium Metrics Reviews, android-bu...@system.gserviceaccount.com, Etienne Bergeron, Chromium LUCI CQ, chromium...@chromium.org, Thiabaud Engelbrecht, asvitkine...@chromium.org, storage...@chromium.org, asvitki...@chromium.org, chromiumme...@microsoft.com, spang...@chromium.org, tracing...@chromium.org, wfh+...@chromium.org
                  Attention needed from Gabriel Charette

                  Sean Maher added 1 comment

                  Patchset-level comments
                  Sean Maher . resolved

                  gab@, could you PTAL at base/features.{h,cc}?

                  Open in Gerrit

                  Related details

                  Attention is currently required from:
                  • Gabriel Charette
                  Submit Requirements:
                  • requirement satisfiedCode-Coverage
                  • requirement is not satisfiedCode-Owners
                  • requirement satisfiedCode-Review
                  • requirement is not satisfiedNo-Unresolved-Comments
                  • requirement satisfiedReview-Enforcement
                  Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
                  Gerrit-MessageType: comment
                  Gerrit-Project: chromium/src
                  Gerrit-Branch: main
                  Gerrit-Change-Id: I59b98bb2e1466c325145a96df40efaa1dbc2bc88
                  Gerrit-Change-Number: 8062015
                  Gerrit-PatchSet: 50
                  Gerrit-Owner: Sean Maher <sp...@chromium.org>
                  Gerrit-Reviewer: Etienne Pierre-Doray <etie...@chromium.org>
                  Gerrit-Reviewer: Gabriel Charette <g...@chromium.org>
                  Gerrit-Reviewer: Joe Mason <joenot...@google.com>
                  Gerrit-Reviewer: Sean Maher <sp...@chromium.org>
                  Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
                  Gerrit-CC: Etienne Bergeron <etie...@chromium.org>
                  Gerrit-CC: Thiabaud Engelbrecht <thia...@google.com>
                  Gerrit-Attention: Gabriel Charette <g...@chromium.org>
                  Gerrit-Comment-Date: Wed, 05 Aug 2026 20:55:37 +0000
                  Gerrit-HasComments: Yes
                  Gerrit-Has-Labels: No
                  satisfied_requirement
                  unsatisfied_requirement
                  open
                  diffy
                  Reply all
                  Reply to author
                  Forward
                  0 new messages