Skip to content

[CAS] sync memory mapped file when closing CAS #10625

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/lib/CAS/MappedFileRegionBumpPtr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@

#include "llvm/CAS/MappedFileRegionBumpPtr.h"
#include "OnDiskCommon.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/CAS/OnDiskCASLogger.h"

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

Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Support/Unix/Path.inc
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,12 @@ void mapped_file_region::unmapImpl() {
::munmap(Mapping, Size);
}

std::error_code mapped_file_region::sync() const {
if (int Res = ::msync(Mapping, Size, MS_SYNC))
return std::error_code(Res, std::generic_category());
return std::error_code();
}

void mapped_file_region::dontNeedImpl() {
assert(Mode == mapped_file_region::readonly);
if (!Mapping)
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Support/Windows/Path.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,12 @@ void mapped_file_region::unmapImpl() {

void mapped_file_region::dontNeedImpl() {}

std::error_code mapped_file_region::sync() const {
if (::FlushViewOfFile(Mapping, 0))
return std::error_code();
return mapWindowsError(::GetLastError());
}

int mapped_file_region::alignment() {
SYSTEM_INFO SysInfo;
::GetSystemInfo(&SysInfo);
Expand Down