This is an archive of the discontinued LLVM Phabricator instance.

[MemProf] Fix inline propagation of memprof metadata
ClosedPublic

Authored by tejohnson on Dec 29 2022, 12:39 PM.

Details

Summary

It isn't correct to always remove memprof metadata MIBs from the
original allocation call after inlining.

Let's say we have the following partial call graph:

C     D
 \   /
  v v
   B   E
   |  /
   v v
    A

where A contains an allocation call. If both contexts including B have
the same allocation behavior, the context in the memprof metadata on the
allocation will be pruned, and we will have 2 MIBs with contexts:
A,B and A,E.

Previously, if we inlined A into B we propagate the matching MIBs onto
the inlined allocation call in B' (A,B in this case), and remove it from
the original out of line allocation in A. This is correct if we have a
single round of bottom up inlining.

However, in the compiler we can have multiple invocations of the inliner
pass (e.g. LTO). We may also inline non-bottom up with an alternative
inliner such as the ModuleInliner. In that case, we could end up first
inlining B into C, without having inlined A into B. The call graph then
looks like:

    D
    |
    v
C'  B   E
 \  |  /
  v v v
    A

If we subsequently (perhaps on a later invocation of bottom up inlining)
inline A into B, the previous handling would propagate the memprof MIB
context A,B up into the inlined allocation in B', and remove it from the
original allocation in A. The propagation into B' is fine, however, by
removing it from A's allocation, we no longer reflect the context coming
from C'.

To fix this, simply prevent the removal of MIB from the original
allocation callsites.

Diff Detail

Event Timeline

tejohnson created this revision.Dec 29 2022, 12:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 29 2022, 12:39 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
tejohnson requested review of this revision.Dec 29 2022, 12:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 29 2022, 12:39 PM
tejohnson edited the summary of this revision. (Show Details)Dec 29 2022, 12:40 PM

Fixed the rendering of the call graphs in phabricator.

Is the MIB removal purely for the purpose of reducing memory usage? It seems safe to always keep them.

Is the MIB removal purely for the purpose of reducing memory usage? It seems safe to always keep them.

Yep, it was purely a "space" optimization. I noticed this problem when creating test cases for the context cloning patches I'm prepping.

snehasish accepted this revision.Dec 29 2022, 4:04 PM

LGTM.

Please add a note to the commit message about the noncold -> notcold change in the tests.

This revision is now accepted and ready to land.Dec 29 2022, 4:04 PM
This revision was landed with ongoing or failed builds.Dec 30 2022, 7:33 AM
This revision was automatically updated to reflect the committed changes.

LGTM.

Please add a note to the commit message about the noncold -> notcold change in the tests.

Added a note to the commit message.