Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for matching split mappings to segments. #641

Merged
merged 2 commits into from
Jul 20, 2021

Conversation

gmarin13
Copy link
Contributor

@gmarin13 gmarin13 commented Jul 20, 2021

Update the heuristic that matches mappings to segments to support split mappings.

The existing logic assumes a mapping is at least as large as the program segment. However, the loader, or some managing service, may split a program segment into multiple mappings for different reasons:

  • to map part of the segment to huge pages, while other parts use regular sized pages;
  • the last page may be remapped with write protection to zero out the bytes after the segment end in the last partial mapping page;
  • if the segment includes both initialized and uninitialized data.

The list is not exhaustive. While https://github.com/google/perf_data_converter tries to combine associated split mappings into a single mapping, that heuristic also has limitations. Being able to match split mappings to segments increases symbolization coverage.

It's not precise in some corner cases. It assumes a mapping includes at most one
segment, but the loader may map memory for the entire binary at first, and under
the right circumstances, this test can select the wrong segment. The filtering
by sample offset works more reliably.

Also, the strict test on segment memory size is less effective after adding
support for matching split mappings to segments.
Update ProgramHeadersForMapping to match a mapping to any segment with
overlapping file offsets, except if:
- if the mapping starts before the page aligned offset associated with a segment.
  There is no known instance where the loader would load the content of a segment
  to include preceding pages of the file that don't include any segment content.
  The mapping must be associated with an earlier segment in such cases.
- if the mappings includes the last page of the segment, but not the full
  segment, and it includes additional pages after the segment end. It's more
  likely that the mapping is associated with the following segment in such cases.
@gmarin13 gmarin13 requested a review from aalexand July 20, 2021 17:37
@google-cla google-cla bot added the cla: yes label Jul 20, 2021
@codecov-commenter
Copy link

codecov-commenter commented Jul 20, 2021

Codecov Report

Merging #641 (f716cdf) into master (86eeefc) will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #641      +/-   ##
==========================================
- Coverage   67.89%   67.88%   -0.02%     
==========================================
  Files          40       40              
  Lines        7320     7311       -9     
==========================================
- Hits         4970     4963       -7     
+ Misses       1909     1908       -1     
+ Partials      441      440       -1     
Impacted Files Coverage Δ
...ithub.com/google/pprof/internal/elfexec/elfexec.go 43.51% <0.00%> (-2.21%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 86eeefc...f716cdf. Read the comment docs.

Copy link
Collaborator

@aalexand aalexand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For posterity, would it be possible to mention in the PR description the circumstances when this change is needed?

@gmarin13
Copy link
Contributor Author

For posterity, would it be possible to mention in the PR description the circumstances when this change is needed?

Updated the PR description to better explain the problem we try to solve.

@aalexand aalexand merged commit 4bb14d4 into google:master Jul 20, 2021
@gmarin13 gmarin13 deleted the split_mappings branch July 20, 2021 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants