<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 3, 2015 at 10:26 PM, Xinliang David Li via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">LLVM Profile instrumentation incurs very large size (memory, storage)<br>
overhead. For instance, the following is the binary size comparison of<br>
the Clang binaries built  (-O2 -DNDEBUG) with different<br>
configurations:<br>
<br>
<br>
1) 60.9M  (built with Clang itself)<br>
2) 280.4M (same as 1, but added -fprofile-instr-generate)<br>
3) 54.9M (built with GCC 4.8)<br>
4) 156.5M (same as 3, but added -fprofile-generate)<br>
<br>
In other words, Clang's instrumentation increases binary size by 4.6X,<br>
while GCC's instrumentation overhead is only  2.8X.<br>
<br>
The profile data size from Clang instrumented binary is also much<br>
larger. The following is a comparison:<br>
<br>
1) 114.5M (raw profile data emitted by Clang instrumented by Clang)<br>
2) 63.7M (indexed profile data emitted by Clang instrumented by Clang)<br>
3) 33.1M (total size of GCDA files emitted by Clang instrumented by GCC).<br>
<br>
Large size of overhead can limit the usability of PGO greatly:<br>
a) devices with small system partition does not have much room left --<br>
greatly bloated image due to instrumentation can prevent it from being<br>
installed<br>
b) Linker can be highly stressed when linking very large C++<br>
applications -- large size increase due to instrumentation can prevent<br>
those apps from being successfully linked<br>
c) Large raw profile dumps may also cause problems, e.g. running out<br>
of space. It can also profile bootstrap build really slow.<br>
<br>
<br>
Looking at various sources of size increase caused by instrumentation,<br>
it is clear that the biggest contributor is the __llvm_prf_names<br>
section. The current PGO implementation uses function  assembly names<br>
as the lookup keys in the indexed format so it needs to be emitted in<br>
both rodata of the binary and in the raw/indexed profiles.<br>
<br>
On the other hand, LLVM's indexed format also supports 'key collision'<br>
-- it allows functions with the same key share the same entry in the<br>
hash table. Function's structural hash values will be used as a<br>
secondary key to find a real match.<br>
<br>
The above feature allows us to use a different key other than function<br>
assembly names and this can reduce binary/profile data size<br>
significantly.  Function name's MD5 hash is a good candidate, and I<br>
have a patch (3 parts: runtime, reader/writer, clang) that does just<br>
that. The results are very promising. With this change, the clang<br>
instrumented binary size is now 216M (down from 280M); the raw profile<br>
size is only 40.1M (a 2.85X size reduction); and the indexed profile<br>
size is only 29.5M (a 2.2X size reduction).<br>
<br>
With the change, the indexed format size is smaller than GCC's (but<br>
the latter has value profile data).  The binary size is still much<br>
larger than GCC's, but with the late instrumentation, we will have<br>
more size reduction.<br>
<br>
A couple of more details of the patch:<br>
<br>
1) When -fcoverage-mapping is specified, the llvm_prf_names will be<br>
emitted to the binary, but they won't be dumped into the profile data.<br>
In other words, with -fcoverage-mapping, only profile data will be<br>
shrinked.   The reason is that llvm-cov tool reads function names from<br>
the section (referenced from covmap) to support name based filtering<br>
(including regular expression) when dumping line coverage report<br>
2) The change is backward compatible such that old version of both raw<br>
and index formats  can still be read by the new profile reader (and<br>
therefore clients such as clang, llvm-profdata, llvm-cov tools)<br>
<br>
<br>
I plan to submit the patch for review after some cleanups.<br>
<br>
Thoughts, concerns?<br></blockquote><div><br></div><div>I think it is reasonable to simply replace the key we currently use with MD5(key) for getting a size reduction.  In practice for my use cases, I have not observed any of the issues you mentioned under "<span style="font-size:12.8000001907349px">Large size of overhead can limit the usability of PGO greatly", but I can understand that some of these issues could become problems in Google's use case. I would personally prefer to keep the existing behavior as the default (see below), and have MD5(key) as an option.</span></div><div><br></div><div>My primary concern is that if the function name are not kept at all stages, then it becomes difficult to analyze the profile data in a standalone way. Many times, I have used `llvm-profdata show -all-functions foo.profdata` on the resulting profile data and then imported that data into Mathematica for analysis. My understanding of your proposal is that `llvm-profdata show -all-functions foo.profdata` will not show the actual function names but instead MD5 hashes, which will make it more difficult for me to do this kind of analysis (would require using nm on the original binary, hashing everything, etc.).</div><div><br></div><div>btw, feel free to attach the patch even if it in a rough state. It can still help to clarify the proposal and be a good talking point. Fine-grained patch review for caring about the rough parts will happen on llvm-commits; the rough parts will not distract the discussion here on llvm-dev.</div><div><br></div><div>-- Sean Silva</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
thanks,<br>
<br>
David<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br></div></div>