From: Min-Yih Hsu Date: Sat, 17 Feb 2024 00:19:56 +0000 (-0800) Subject: [PATCH] [JITLink] Always unmap standard segments in InProcessMemoryManager::deallocat... X-Git-Tag: archive/raspbian/1%18.1.8-12+rpi1~3 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=05a71363b13ca4b806b0b57fef14da8e15d26825;p=llvm-toolchain-18.git [PATCH] [JITLink] Always unmap standard segments in InProcessMemoryManager::deallocate (#81943) Right now InProcessMemoryManager only releases a standard segment (via sys::Memory::releaseMappedMemory) in `deallocate` when there is a DeallocAction associated, leaving residual memory pages in the process until termination. Despite being a de facto memory leak, it won't cause a major issue if users only create a single LLJIT instance per process, which is the most common use cases. It will, however, drain virtual memory pages if we create thousands of ephemeral LLJIT instances in the same process. This patch fixes this issue by releasing every standard segments regardless of the attached DeallocAction. Gbp-Pq: Name rv64-fix-mm-leak.diff --- diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp index 474a0b5160..dacf0e6c8a 100644 --- a/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp @@ -449,8 +449,7 @@ void InProcessMemoryManager::deallocate(std::vector Allocs, for (auto &Alloc : Allocs) { auto *FA = Alloc.release().toPtr(); StandardSegmentsList.push_back(std::move(FA->StandardSegments)); - if (!FA->DeallocActions.empty()) - DeallocActionsList.push_back(std::move(FA->DeallocActions)); + DeallocActionsList.push_back(std::move(FA->DeallocActions)); FA->~FinalizedAllocInfo(); FinalizedAllocInfos.Deallocate(FA); }