From 7381558ef8b8639831dfdedf7edbd5e635afc85e Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Mon, 13 Oct 2025 12:33:16 +1100 Subject: [orc-rt] Rename SimpleNativeMemoryMap finalize & deallocate. NFCI. (#163114) This commit renames the "finalize" operation to "initialize", and "deallocate" to "deinitialize". The new names are chosen to better fit the point of view of the ORC-runtime and executor-process: After memory is *reserved* it can be *initialized* with some content, and *deinitialized* to return that memory to the reserved region. This seems more understandable to me than the original scheme, which named these operations after the controller-side JITLinkMemoryManager operations that they partially implemented. I.e. SimpleNativeMemoryMap::finalize implemented the final step of JITLinkMemoryManager::finalize, initializing the memory in the executor; and SimpleNativeMemoryMap::deallocate implemented the final step of JITLinkMemoryManager::deallocate, running dealloc actions and releasing the finalized region. The proper way to think of the relationship between these operations now is that: 1. The final step of finalization is to initialize the memory in the executor. 2. The final step of deallocation is to deinitialize the memory in the executor. --- orc-rt/lib/executor/SimpleNativeMemoryMap.cpp | 92 ++++++++++++++------------- 1 file changed, 48 insertions(+), 44 deletions(-) (limited to 'orc-rt/lib/executor/SimpleNativeMemoryMap.cpp') diff --git a/orc-rt/lib/executor/SimpleNativeMemoryMap.cpp b/orc-rt/lib/executor/SimpleNativeMemoryMap.cpp index 987bd857defe..bce5c1daa8ee 100644 --- a/orc-rt/lib/executor/SimpleNativeMemoryMap.cpp +++ b/orc-rt/lib/executor/SimpleNativeMemoryMap.cpp @@ -8,8 +8,8 @@ // // SimpleNativeMemoryMap and related APIs. // -// TODO: We don't reset / uncommit pages on deallocate, or on failure during -// finalize. We should do that to reduce memory pressure. +// TODO: We don't reset / uncommit pages on deinitialize, or on failure during +// initialize. We should do that to reduce memory pressure. // //===----------------------------------------------------------------------===// @@ -29,14 +29,16 @@ namespace orc_rt { struct SPSSimpleNativeMemoryMapSegment; template <> -class SPSSerializationTraits { +class SPSSerializationTraits< + SPSSimpleNativeMemoryMapSegment, + SimpleNativeMemoryMap::InitializeRequest::Segment> { using SPSType = SPSTuple>; public: - static bool deserialize(SPSInputBuffer &IB, - SimpleNativeMemoryMap::FinalizeRequest::Segment &S) { + static bool + deserialize(SPSInputBuffer &IB, + SimpleNativeMemoryMap::InitializeRequest::Segment &S) { AllocGroup AG; ExecutorAddr Address; uint64_t Size; @@ -50,17 +52,17 @@ public: } }; -struct SPSSimpleNativeMemoryMapFinalizeRequest; +struct SPSSimpleNativeMemoryMapInitializeRequest; template <> -class SPSSerializationTraits { +class SPSSerializationTraits { using SPSType = SPSTuple, SPSSequence>; public: static bool deserialize(SPSInputBuffer &IB, - SimpleNativeMemoryMap::FinalizeRequest &FR) { + SimpleNativeMemoryMap::InitializeRequest &FR) { return SPSType::AsArgList::deserialize(IB, FR.Segments, FR.AAPs); } }; @@ -121,13 +123,13 @@ void SimpleNativeMemoryMap::releaseMultiple(OnReleaseCompleteFn &&OnComplete, releaseNext(std::move(OnComplete), std::move(Addrs), false, Error::success()); } -void SimpleNativeMemoryMap::finalize(OnFinalizeCompleteFn &&OnComplete, - FinalizeRequest FR) { +void SimpleNativeMemoryMap::initialize(OnInitializeCompleteFn &&OnComplete, + InitializeRequest FR) { void *Base = nullptr; - // TODO: Record finalize segments for release. - // std::vector> FinalizeSegments; + // TODO: Record initialize segments for release. + // std::vector> InitializeSegments; // Check segment validity before proceeding. for (auto &S : FR.Segments) { @@ -166,9 +168,10 @@ void SimpleNativeMemoryMap::finalize(OnFinalizeCompleteFn &&OnComplete, } if (!Base) - return OnComplete(make_error( - "SimpleNativeMemoryMap finalize error: finalization requires at least " - "one standard-lifetime segment")); + return OnComplete( + make_error("SimpleNativeMemoryMap initialize error: " + "finalization requires at least " + "one standard-lifetime segment")); auto DeallocActions = runFinalizeActions(std::move(FR.AAPs)); if (!DeallocActions) @@ -182,8 +185,8 @@ void SimpleNativeMemoryMap::finalize(OnFinalizeCompleteFn &&OnComplete, OnComplete(Base); } -void SimpleNativeMemoryMap::deallocate(OnDeallocateCompleteFn &&OnComplete, - void *Base) { +void SimpleNativeMemoryMap::deinitialize(OnDeinitializeCompleteFn &&OnComplete, + void *Base) { std::vector DAAs; { @@ -191,16 +194,17 @@ void SimpleNativeMemoryMap::deallocate(OnDeallocateCompleteFn &&OnComplete, auto *SI = findSlabInfoFor(Base); if (!SI) { Lock.unlock(); - return OnComplete(makeBadSlabError(Base, "finalize")); + return OnComplete(makeBadSlabError(Base, "deinitialize")); } auto I = SI->DeallocActions.find(Base); if (I == SI->DeallocActions.end()) { Lock.unlock(); std::ostringstream ErrMsg; - ErrMsg << "SimpleNativeMemoryMap deallocate error: no deallocate actions " - "registered for segment base address " - << Base; + ErrMsg + << "SimpleNativeMemoryMap deinitialize error: no deallocate actions " + "registered for segment base address " + << Base; return OnComplete(make_error(ErrMsg.str())); } @@ -212,10 +216,10 @@ void SimpleNativeMemoryMap::deallocate(OnDeallocateCompleteFn &&OnComplete, OnComplete(Error::success()); } -void SimpleNativeMemoryMap::deallocateMultiple( - OnDeallocateCompleteFn &&OnComplete, std::vector Bases) { - deallocateNext(std::move(OnComplete), std::move(Bases), false, - Error::success()); +void SimpleNativeMemoryMap::deinitializeMultiple( + OnDeinitializeCompleteFn &&OnComplete, std::vector Bases) { + deinitializeNext(std::move(OnComplete), std::move(Bases), false, + Error::success()); } void SimpleNativeMemoryMap::detach(ResourceManager::OnCompleteFn OnComplete) { @@ -268,9 +272,9 @@ void SimpleNativeMemoryMap::releaseNext(OnReleaseCompleteFn &&OnComplete, NextAddr); } -void SimpleNativeMemoryMap::deallocateNext(OnDeallocateCompleteFn &&OnComplete, - std::vector Addrs, - bool AnyError, Error LastErr) { +void SimpleNativeMemoryMap::deinitializeNext( + OnDeinitializeCompleteFn &&OnComplete, std::vector Addrs, + bool AnyError, Error LastErr) { // TODO: Log error? if (LastErr) { consumeError(std::move(LastErr)); @@ -282,17 +286,17 @@ void SimpleNativeMemoryMap::deallocateNext(OnDeallocateCompleteFn &&OnComplete, return OnComplete(Error::success()); return OnComplete( - make_error("Failed to deallocate some addresses")); + make_error("Failed to deinitialize some addresses")); } void *NextAddr = Addrs.back(); Addrs.pop_back(); - deallocate( + deinitialize( [this, OnComplete = std::move(OnComplete), AnyError = AnyError, Addrs = std::move(Addrs)](Error Err) mutable { - deallocateNext(std::move(OnComplete), std::move(Addrs), AnyError, - std::move(Err)); + deinitializeNext(std::move(OnComplete), std::move(Addrs), AnyError, + std::move(Err)); }, NextAddr); } @@ -346,15 +350,15 @@ Error SimpleNativeMemoryMap::recordDeallocActions( auto *SI = findSlabInfoFor(Base); if (!SI) { Lock.unlock(); - return makeBadSlabError(Base, "deallocate"); + return makeBadSlabError(Base, "deinitialize"); } auto I = SI->DeallocActions.find(Base); if (I != SI->DeallocActions.end()) { Lock.unlock(); std::ostringstream ErrMsg; - ErrMsg << "SimpleNativeMemoryMap finalize error: segment base address " - "reused in subsequent finalize call"; + ErrMsg << "SimpleNativeMemoryMap initialize error: segment base address " + "reused in subsequent initialize call"; return make_error(ErrMsg.str()); } @@ -383,19 +387,19 @@ orc_rt_SimpleNativeMemoryMap_releaseMultiple_sps_wrapper( &SimpleNativeMemoryMap::releaseMultiple)); } -ORC_RT_SPS_INTERFACE void orc_rt_SimpleNativeMemoryMap_finalize_sps_wrapper( +ORC_RT_SPS_INTERFACE void orc_rt_SimpleNativeMemoryMap_initialize_sps_wrapper( orc_rt_SessionRef Session, void *CallCtx, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes) { using Sig = SPSExpected( - SPSExecutorAddr, SPSSimpleNativeMemoryMapFinalizeRequest); - SPSWrapperFunction::handle( - Session, CallCtx, Return, ArgBytes, - WrapperFunction::handleWithAsyncMethod(&SimpleNativeMemoryMap::finalize)); + SPSExecutorAddr, SPSSimpleNativeMemoryMapInitializeRequest); + SPSWrapperFunction::handle(Session, CallCtx, Return, ArgBytes, + WrapperFunction::handleWithAsyncMethod( + &SimpleNativeMemoryMap::initialize)); } ORC_RT_SPS_INTERFACE void -orc_rt_SimpleNativeMemoryMap_deallocateMultiple_sps_wrapper( +orc_rt_SimpleNativeMemoryMap_deinitializeMultiple_sps_wrapper( orc_rt_SessionRef Session, void *CallCtx, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes) { @@ -403,7 +407,7 @@ orc_rt_SimpleNativeMemoryMap_deallocateMultiple_sps_wrapper( SPSWrapperFunction::handle( Session, CallCtx, Return, ArgBytes, WrapperFunction::handleWithAsyncMethod( - &SimpleNativeMemoryMap::deallocateMultiple)); + &SimpleNativeMemoryMap::deinitializeMultiple)); } } // namespace orc_rt -- cgit v1.2.3