[llvm] 0ecfee0 - [Orc] Provide correct Reservation address for slab allocations

Anubhab Ghosh via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 21 04:09:05 PDT 2022


Author: Anubhab Ghosh
Date: 2022-08-21T16:36:37+05:30
New Revision: 0ecfee0b9eafd75627f37e2c460818bf41b39996

URL: https://github.com/llvm/llvm-project/commit/0ecfee0b9eafd75627f37e2c460818bf41b39996
DIFF: https://github.com/llvm/llvm-project/commit/0ecfee0b9eafd75627f37e2c460818bf41b39996.diff

LOG: [Orc] Provide correct Reservation address for slab allocations

When slab allocator is used, the MappingBase is not necessarily
the same as the original reservation base as the allocation could
be a part of the whole reservation.

In this case the original reservation address needs to be passed to
ExecutorSharedMemoryMapperService to associate the new allocation
with the original reservation.

Differential Revision: https://reviews.llvm.org/D132313

Added: 
    

Modified: 
    llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp b/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
index 734b5f06f98d..773e6d26eea5 100644
--- a/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
@@ -11,6 +11,8 @@
 #include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
 #include "llvm/Support/WindowsError.h"
 
+#include <algorithm>
+
 #if defined(LLVM_ON_UNIX) && !defined(__ANDROID__)
 #include <fcntl.h>
 #include <sys/mman.h>
@@ -300,8 +302,10 @@ char *SharedMemoryMapper::prepare(ExecutorAddr Addr, size_t ContentSize) {
 
 void SharedMemoryMapper::initialize(MemoryMapper::AllocInfo &AI,
                                     OnInitializedFunction OnInitialized) {
-  auto Reservation = Reservations.find(AI.MappingBase);
-  assert(Reservation != Reservations.end() &&
+  auto Reservation = std::lower_bound(
+      Reservations.rbegin(), Reservations.rend(), AI.MappingBase,
+      [](const auto &A, const auto &B) { return A.first > B; });
+  assert(Reservation != Reservations.rend() &&
          "Attempt to initialize unreserved range");
 
   tpctypes::SharedMemoryFinalizeRequest FR;
@@ -336,7 +340,7 @@ void SharedMemoryMapper::initialize(MemoryMapper::AllocInfo &AI,
 
         OnInitialized(std::move(Result));
       },
-      SAs.Instance, AI.MappingBase, std::move(FR));
+      SAs.Instance, Reservation->first, std::move(FR));
 }
 
 void SharedMemoryMapper::deinitialize(
@@ -418,7 +422,6 @@ SharedMemoryMapper::~SharedMemoryMapper() {
     UnmapViewOfFile(R.second.LocalAddr);
 
 #endif
-
   }
 }
 


        


More information about the llvm-commits mailing list