This is an archive of the discontinued LLVM Phabricator instance.

[ThinLTO/gold] Add caching support to gold-plugin
ClosedPublic

Authored by tejohnson on Aug 24 2016, 6:33 AM.

Details

Summary

With support now in the new LTO API for caching (r279576), add
optional ThinLTO caching in the gold-plugin.

Diff Detail

Repository
rL LLVM

Event Timeline

tejohnson updated this revision to Diff 69109.Aug 24 2016, 6:33 AM
tejohnson retitled this revision from to [ThinLTO/gold] Add caching support to gold-plugin.
tejohnson updated this object.
tejohnson added a reviewer: mehdi_amini.
tejohnson added a subscriber: llvm-commits.
mehdi_amini accepted this revision.Aug 24 2016, 7:57 AM
mehdi_amini edited edge metadata.

LGTM.

(Note: you'll have to prune the cache dir manually)

This revision is now accepted and ready to land.Aug 24 2016, 7:57 AM
This revision was automatically updated to reflect the committed changes.
mehdi_amini added inline comments.Aug 24 2016, 10:38 AM
llvm/trunk/tools/gold/gold-plugin.cpp
812

I just noticed: this is largely suboptimal, the Buffer will be a mmap'd file in memory, and you're duplicating it here.

mehdi_amini added inline comments.Aug 24 2016, 10:40 AM
llvm/trunk/tools/gold/gold-plugin.cpp
812

I didn't notice earlier because the libLTO interface returns a pointer to the memory to the linker, so the MemoryBuffer is untouched till the linker needs it (it does not need to be paged in memory, which can contributes to explains why you have much more memory pressure)

tejohnson added inline comments.Aug 24 2016, 10:48 AM
llvm/trunk/tools/gold/gold-plugin.cpp
812

I just noticed: this is largely suboptimal, the Buffer will be a mmap'd file in memory, and you're duplicating it here.

Dumb question - where is the duplication happening? getBuffer will give back a StringRef to the memory pointed to by the MemoryBuffer. And we then stream it to an output file (which we would have done earlier without caching).

mehdi_amini added inline comments.Aug 24 2016, 10:51 AM
llvm/trunk/tools/gold/gold-plugin.cpp
812

The StringRef points to the memory mapped from the cache. So this is data on disk that you load in memory while you access it here.
The duplication is that you're creating a new file, while there is already a file on disk, this wouldn't happen in the libLTO implementation.

tejohnson added inline comments.Aug 24 2016, 11:10 AM
llvm/trunk/tools/gold/gold-plugin.cpp
812

Ah ok, yes the file is duplicated unfortunately (temporarily), gold cleans up the temp object files written here. I didn't noticed a memory increase from this change.

Not sure if there is a way for gold-plugin to pass back the native object in memory, but I don't see a hook for that unfortunately.

mehdi_amini added inline comments.Aug 24 2016, 11:13 AM
llvm/trunk/tools/gold/gold-plugin.cpp
812

Even if the peak memory does not increase, the memory traffic (and cache trashing) is probably important (let along that these data need to be flushed to disk...)