Skip to content

Commit

Permalink
[Orc] Only unmap shared memory in controller process destructor
Browse files Browse the repository at this point in the history
By the time SharedMemoryMapper destructor is called, the RPC
connection is no longer available causing the release() call to
always fail. Instead at this point only shared memory regions
can be unmapped safely.

Deinitializers are called and mapped memory is released at the
executor side by ExecutorSharedMemoryMapperService::shutdown()
instead. Memory can also be released earlier by calling release()
earlier before RPC connection is closed.

Differential Revision: https://reviews.llvm.org/D132313
  • Loading branch information
argentite committed Aug 21, 2022
1 parent 5df428e commit 1134d3a
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
Expand Up @@ -407,23 +407,19 @@ void SharedMemoryMapper::release(ArrayRef<ExecutorAddr> Bases,
}

SharedMemoryMapper::~SharedMemoryMapper() {
std::vector<ExecutorAddr> ReservationAddrs;
if (!Reservations.empty()) {
std::lock_guard<std::mutex> Lock(Mutex);
{
ReservationAddrs.reserve(Reservations.size());
for (const auto &R : Reservations) {
ReservationAddrs.push_back(R.first);
}
}
}
for (const auto R : Reservations) {

std::promise<MSVCPError> P;
auto F = P.get_future();
release(ReservationAddrs, [&](Error Err) { P.set_value(std::move(Err)); });
// FIXME: Release can actually fail. The error should be propagated.
// Meanwhile, a better option is to explicitly call release().
cantFail(F.get());
#if defined(LLVM_ON_UNIX) && !defined(__ANDROID__)

munmap(R.second.LocalAddr, R.second.Size);

#elif defined(_WIN32)

UnmapViewOfFile(R.second.LocalAddr);

#endif

}
}

} // namespace orc
Expand Down

0 comments on commit 1134d3a

Please sign in to comment.