Skip to content

Commit b0d6e64

Browse files
authored
Merge pull request #10634 from cachemeifyoucan/eng/PR-150379440-release
[6.2][CAS] sync memory mapped file when closing CAS
2 parents 7f20e18 + bbc8589 commit b0d6e64

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

llvm/lib/CAS/MappedFileRegionBumpPtr.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353

5454
#include "llvm/CAS/MappedFileRegionBumpPtr.h"
5555
#include "OnDiskCommon.h"
56-
#include "llvm/ADT/StringMap.h"
5756
#include "llvm/CAS/OnDiskCASLogger.h"
5857

5958
using namespace llvm;
@@ -196,6 +195,8 @@ void MappedFileRegionBumpPtr::destroyImpl() {
196195
size_t Size = size();
197196
size_t Capacity = capacity();
198197
assert(Size < Capacity);
198+
// sync to file system to make sure all contents are up-to-date.
199+
(void)Region.sync();
199200
(void)sys::fs::resize_file(*FD, size());
200201
(void)unlockFileThreadSafe(*SharedLockFD);
201202

llvm/lib/Support/Unix/Path.inc

+6
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,12 @@ void mapped_file_region::unmapImpl() {
876876
::munmap(Mapping, Size);
877877
}
878878

879+
std::error_code mapped_file_region::sync() const {
880+
if (int Res = ::msync(Mapping, Size, MS_SYNC))
881+
return std::error_code(Res, std::generic_category());
882+
return std::error_code();
883+
}
884+
879885
void mapped_file_region::dontNeedImpl() {
880886
assert(Mode == mapped_file_region::readonly);
881887
if (!Mapping)

llvm/lib/Support/Windows/Path.inc

+6
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,12 @@ void mapped_file_region::unmapImpl() {
10111011

10121012
void mapped_file_region::dontNeedImpl() {}
10131013

1014+
std::error_code mapped_file_region::sync() const {
1015+
if (::FlushViewOfFile(Mapping, 0))
1016+
return std::error_code();
1017+
return mapWindowsError(::GetLastError());
1018+
}
1019+
10141020
int mapped_file_region::alignment() {
10151021
SYSTEM_INFO SysInfo;
10161022
::GetSystemInfo(&SysInfo);

0 commit comments

Comments
 (0)