This is an archive of the discontinued LLVM Phabricator instance.

Prevent data races in concurrent ThinLTO processes
ClosedPublic

Authored by kromanova on Mar 29 2018, 7:10 PM.

Details

Summary

I few days ago I sent an email to the llvm-dev mailing list, describing a list of problems that the user could face with concurrent ThinLTO processes with caching enabled. More specifically, I identified a data race condition and other inefficiencies, caused by resource sharing problems. Here it is for the reference.

http://lists.llvm.org/pipermail/llvm-dev/2018-March/122046.html

After the long subsequent discussion on the mailing list we decided to implement the following straightforward solution described in this proposal.

Namely,

a. Place temp file to the same place where the caching directory is (instead of creating it the directory pointed to by TMP/TEMP variable). This will help to prevent using non-atomic rename and falling back to non-atomic "direct" write to the cache file.
b. if rename failed do not write to the cache file directly (direct write to the file is non-atomic and could cause data race conditions).
c. if cache file doesn't exist (e.g., because 'rename' failed or because some other reasons), bypass using the cache altogether.

Diff Detail

Repository
rL LLVM

Event Timeline

kromanova created this revision.Mar 29 2018, 7:10 PM

LGTM with some feedback inline.

lib/LTO/ThinLTOCodeGenerator.cpp
417 ↗(On Diff #140378)

Can you rewrite this comment?

419 ↗(On Diff #140378)

You can remove {}

1035 ↗(On Diff #140378)

You also don't need {} here

Is there any specific reason why the error message is removed here? We should not hit that if we fixed all the races, but it can still happen from user errors.

kromanova updated this revision to Diff 140482.Mar 30 2018, 1:42 PM
kromanova marked 2 inline comments as done.

Fixed code review comments from Steven Wu.

lib/LTO/ThinLTOCodeGenerator.cpp
1033 ↗(On Diff #140378)

I reversed the meaning in the last sentence (wasn't too high -> was to high). Could you please double check that this is correct?

1035 ↗(On Diff #140378)

I restored the code the way it was before my change, except I modified the comment slightly. I don't understand what crashing the comment is referring to, so I removed it.
This error message is just a diagnostic printed on the stderr, it won't stop the compilation, right? We want the compilation to continue even if the error occurred.

steven_wu accepted this revision.Mar 30 2018, 1:52 PM

LGTM. Thanks!

lib/LTO/ThinLTOCodeGenerator.cpp
1035 ↗(On Diff #140378)

Looks correct. This is simply printing to stderr.

This revision is now accepted and ready to land.Mar 30 2018, 1:52 PM
This revision was automatically updated to reflect the committed changes.