-
Notifications
You must be signed in to change notification settings - Fork 339
[llvm][cas] Fix thread safety issues with MappedFileRegionBumpPtr #8621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@swift-ci please test llvm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine in general as long as this doesn't regress linux.
#include <thread> | ||
|
||
#if __has_include(<sys/file.h>) | ||
#include <sys/file.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a common unix header or is this macOS only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the same on Linux https://man7.org/linux/man-pages/man2/flock.2.html
@@ -52,12 +52,14 @@ | |||
//===----------------------------------------------------------------------===// | |||
|
|||
#include "llvm/CAS/MappedFileRegionBumpPtr.h" | |||
#include "llvm/ADT/ScopeExit.h" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need empty line around this include?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I see a mix of styles for including lib-directory headers. Some have empty lines around it, some only have empty line above it, some have no empty lines. Not clear to me what it should be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No spaces seems more common, going with that.
llvm::sys::fs::lockFile and friends, which are implemented with fcntl F_SETLK, are only safe to use across processes and not across threads. We were attempting to workaround that using createShared, which tries to unique the mapped file per process, but (a) that only works if you have a single copy of llvm in your process, which may not always be true, and (b) we had a race in the implementation between closing one CAS and opening a new one at the same path. Replace these with an flock-based implementation. Since this is not available on all platforms LLVM supports we use a separate implementation for the on-disk CAS rather than change llvm::sys::fs::lockFile. rdar://126882843
1f262eb
to
15a76e0
Compare
llvm::sys::fs::lockFile
and friends, which are implemented withfcntl F_SETLK
, are only safe to use across processes and not across threads. We were attempting to workaround that usingcreateShared
, which tries to unique the mapped file per process, but (a) that only works if you have a single copy of llvm in your process, which may not always be true, and (b) we had a race in the implementation between closing one CAS and opening a new one at the same path. Replace these with an flock-based implementation. Since this is not available on all platforms LLVM supports we use a separate implementation for the on-disk CAS rather than change llvm::sys::fs::lockFile.rdar://126882843