This is an archive of the discontinued LLVM Phabricator instance.

[ThinLTO/gold] Implement ThinLTO cache pruning support
ClosedPublic

Authored by kongyi on Sep 18 2017, 12:52 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

kongyi created this revision.Sep 18 2017, 12:52 PM
tejohnson edited edge metadata.Sep 18 2017, 1:17 PM

Thanks for working on adding this missing feature! Please add a test and include an update to the info on where cache pruning is supported in ThinLTO.rst (for examples of both, see https://reviews.llvm.org/D37607, where it was added to lld).

kongyi updated this revision to Diff 115725.Sep 18 2017, 2:27 PM

Tests added.

Thanks for working on adding this missing feature! Please add a test and include an update to the info on where cache pruning is supported in ThinLTO.rst (for examples of both, see https://reviews.llvm.org/D37607, where it was added to lld).

Done, thanks.

This revision is now accepted and ready to land.Sep 18 2017, 4:19 PM
This revision was automatically updated to reflect the committed changes.

LGTM

Thanks!

mehdi_amini added inline comments.Sep 18 2017, 5:04 PM
llvm/trunk/tools/gold/gold-plugin.cpp
229

Did you consider using the same option name as lld for consistency?
(i.e. why diverging when unnecessary)

kongyi added inline comments.Sep 18 2017, 5:24 PM
llvm/trunk/tools/gold/gold-plugin.cpp
229

I named this to be consistent with gold plugin's name for cache directory, "cache-dir".

pcc added a subscriber: pcc.Oct 10 2017, 10:50 AM

Is it a good idea to support cache pruning in the gold plugin? As I mentioned in D31063 there are some unavoidable race conditions due to limitations in the plugin API.

llvm/trunk/tools/gold/gold-plugin.cpp
980

I think this should check cache_dir, not cache_policy.

pcc added a comment.Oct 31 2017, 5:17 PM
In D37993#893466, @pcc wrote:

Is it a good idea to support cache pruning in the gold plugin? As I mentioned in D31063 there are some unavoidable race conditions due to limitations in the plugin API.

Ping... not sure whether it's a good idea to ship a known racy feature.

If you really want this feature in gold I'd suggest extending the gold plugin API so that it accepts file descriptors, and then have the plugin support this feature conditionally on whether the gold version is new enough.

In D37993#912428, @pcc wrote:
In D37993#893466, @pcc wrote:

Is it a good idea to support cache pruning in the gold plugin? As I mentioned in D31063 there are some unavoidable race conditions due to limitations in the plugin API.

Ping... not sure whether it's a good idea to ship a known racy feature.

If you really want this feature in gold I'd suggest extending the gold plugin API so that it accepts file descriptors, and then have the plugin support this feature conditionally on whether the gold version is new enough.

Hi Peter, thanks for pointing this out, and sorry for the delay in responding. Wondering whether instead of removing cache pruning support from gold-plugin for now, we could do something else: write the MemoryBuffer to another temp file and use that path (setting IsTemporary to true so it gets cleaned up). This would obviously require more space on disk, but maybe worth it to enable the pruning safely.

llvm/trunk/tools/gold/gold-plugin.cpp
980

It seems fine since pruneCache will return immediately if cache_dir is empty. But we could save some work if both were checked. I assume parseCachePruningPolicy will also work if cache_policy is empty, but it seems fine to have the checking.

pcc added a comment.Nov 7 2017, 8:39 PM
In D37993#912428, @pcc wrote:
In D37993#893466, @pcc wrote:

Is it a good idea to support cache pruning in the gold plugin? As I mentioned in D31063 there are some unavoidable race conditions due to limitations in the plugin API.

Ping... not sure whether it's a good idea to ship a known racy feature.

If you really want this feature in gold I'd suggest extending the gold plugin API so that it accepts file descriptors, and then have the plugin support this feature conditionally on whether the gold version is new enough.

Hi Peter, thanks for pointing this out, and sorry for the delay in responding. Wondering whether instead of removing cache pruning support from gold-plugin for now, we could do something else: write the MemoryBuffer to another temp file and use that path (setting IsTemporary to true so it gets cleaned up). This would obviously require more space on disk, but maybe worth it to enable the pruning safely.

Copying to a temporary file sounds fine to me. And if gold ever gets support for file descriptors we could always use the copying code path as a fallback for older versions.

llvm/trunk/tools/gold/gold-plugin.cpp
980

I was more thinking about the behaviour when a cache directory is specified and no cache policy is specified. In that case the behaviour of the other linkers is to prune with the default policy, so it's probably best to be consistent with that.

In D37993#918921, @pcc wrote:
In D37993#912428, @pcc wrote:
In D37993#893466, @pcc wrote:

Is it a good idea to support cache pruning in the gold plugin? As I mentioned in D31063 there are some unavoidable race conditions due to limitations in the plugin API.

Ping... not sure whether it's a good idea to ship a known racy feature.

If you really want this feature in gold I'd suggest extending the gold plugin API so that it accepts file descriptors, and then have the plugin support this feature conditionally on whether the gold version is new enough.

Hi Peter, thanks for pointing this out, and sorry for the delay in responding. Wondering whether instead of removing cache pruning support from gold-plugin for now, we could do something else: write the MemoryBuffer to another temp file and use that path (setting IsTemporary to true so it gets cleaned up). This would obviously require more space on disk, but maybe worth it to enable the pruning safely.

Copying to a temporary file sounds fine to me. And if gold ever gets support for file descriptors we could always use the copying code path as a fallback for older versions.

Yi, can you address these suggestions?

llvm/trunk/tools/gold/gold-plugin.cpp
980

Oh, I see what you are saying. Yes, this makes sense.

kongyi added a comment.Nov 9 2017, 7:15 PM
In D37993#893466, @pcc wrote:

Is it a good idea to support cache pruning in the gold plugin? As I mentioned in D31063 there are some unavoidable race conditions due to limitations in the plugin API.

Gold plugin

In D37993#918921, @pcc wrote:
In D37993#912428, @pcc wrote:
In D37993#893466, @pcc wrote:

Is it a good idea to support cache pruning in the gold plugin? As I mentioned in D31063 there are some unavoidable race conditions due to limitations in the plugin API.

Ping... not sure whether it's a good idea to ship a known racy feature.

If you really want this feature in gold I'd suggest extending the gold plugin API so that it accepts file descriptors, and then have the plugin support this feature conditionally on whether the gold version is new enough.

Hi Peter, thanks for pointing this out, and sorry for the delay in responding. Wondering whether instead of removing cache pruning support from gold-plugin for now, we could do something else: write the MemoryBuffer to another temp file and use that path (setting IsTemporary to true so it gets cleaned up). This would obviously require more space on disk, but maybe worth it to enable the pruning safely.

Copying to a temporary file sounds fine to me. And if gold ever gets support for file descriptors we could always use the copying code path as a fallback for older versions.

Yi, can you address these suggestions?

Sure, will fix these in a follow up change.

In D37993#893466, @pcc wrote:

Is it a good idea to support cache pruning in the gold plugin? As I mentioned in D31063 there are some unavoidable race conditions due to limitations in the plugin API.

Gold plugin

In D37993#918921, @pcc wrote:
In D37993#912428, @pcc wrote:
In D37993#893466, @pcc wrote:

Is it a good idea to support cache pruning in the gold plugin? As I mentioned in D31063 there are some unavoidable race conditions due to limitations in the plugin API.

Ping... not sure whether it's a good idea to ship a known racy feature.

If you really want this feature in gold I'd suggest extending the gold plugin API so that it accepts file descriptors, and then have the plugin support this feature conditionally on whether the gold version is new enough.

Hi Peter, thanks for pointing this out, and sorry for the delay in responding. Wondering whether instead of removing cache pruning support from gold-plugin for now, we could do something else: write the MemoryBuffer to another temp file and use that path (setting IsTemporary to true so it gets cleaned up). This would obviously require more space on disk, but maybe worth it to enable the pruning safely.

Copying to a temporary file sounds fine to me. And if gold ever gets support for file descriptors we could always use the copying code path as a fallback for older versions.

Yi, can you address these suggestions?

Sure, will fix these in a follow up change.

Ping - Yi, can you fix these?

pcc added a comment.Feb 7 2018, 11:32 AM

Ping.

llvm/trunk/tools/gold/gold-plugin.cpp
980

Please at least address this.

tejohnson added inline comments.Feb 16 2018, 7:50 AM
llvm/trunk/tools/gold/gold-plugin.cpp
980

Since we haven't heard from Yi, I will go ahead and fix these. Just mailed you D43389 to fix this issue, I'll address the possible race separately.