From a4becdac81238ff7fbcaa2ae9b154b1bc2aad55b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20Laferrie=CC=80re?= Date: Fri, 17 Jul 2020 18:03:37 -0700 Subject: [PATCH 1/2] [Serialization] Load swiftmodule files as volatile to avoid mmap Avoid mmaping swiftmodule files to hopefully fix issues seen when building many Swift projects in parallel on NFS. This only affects loading ModuleFile, it doesn't affect scanning swiftmodule for dependecies which are still handled as non-volatile. rdar://63755989 --- lib/Serialization/SerializedModuleLoader.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Serialization/SerializedModuleLoader.cpp b/lib/Serialization/SerializedModuleLoader.cpp index 25a81335ad015..15aa373282b56 100644 --- a/lib/Serialization/SerializedModuleLoader.cpp +++ b/lib/Serialization/SerializedModuleLoader.cpp @@ -347,8 +347,15 @@ std::error_code SerializedModuleLoaderBase::openModuleFile( } // Actually load the file and error out if necessary. + // + // Use the default arguments except for IsVolatile. Force avoiding the use of + // mmap to workaround issues on NFS when the swiftmodule file loaded changes + // on disk while it's in use. llvm::ErrorOr> ModuleOrErr = - FS.getBufferForFile(ModulePath); + FS.getBufferForFile(ModulePath, + /*FileSize=*/-1, + /*RequiresNullTerminator=*/true, + /*IsVolatile=*/true); if (!ModuleOrErr) return ModuleOrErr.getError(); From 0ede7282bb83e27a1b05e6fc5f67699c34ffa227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20Laferrie=CC=80re?= Date: Tue, 21 Jul 2020 12:17:57 -0700 Subject: [PATCH 2/2] [Serialization] Add more context to why we load swiftmodule files as volatile --- lib/Serialization/SerializedModuleLoader.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/Serialization/SerializedModuleLoader.cpp b/lib/Serialization/SerializedModuleLoader.cpp index 15aa373282b56..9a33b4a4b8f2a 100644 --- a/lib/Serialization/SerializedModuleLoader.cpp +++ b/lib/Serialization/SerializedModuleLoader.cpp @@ -351,6 +351,16 @@ std::error_code SerializedModuleLoaderBase::openModuleFile( // Use the default arguments except for IsVolatile. Force avoiding the use of // mmap to workaround issues on NFS when the swiftmodule file loaded changes // on disk while it's in use. + // + // In practice, a swiftmodule file can chane when a client uses a + // swiftmodule file from a framework while the framework is recompiled and + // installed over existing files. Or when many processes rebuild the same + // module interface. + // + // We have seen these scenarios leading to deserialization errors that on + // the surface look like memory corruption. + // + // rdar://63755989 llvm::ErrorOr> ModuleOrErr = FS.getBufferForFile(ModulePath, /*FileSize=*/-1,