// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "malloc_mmap_guard.h" #include #ifdef __linux__ #include #endif #include #include namespace vespalib { MallocMmapGuard::MallocMmapGuard(size_t mmapLimit) : _threadId(std::this_thread::get_id()) { #ifdef __linux__ int limit = mmapLimit <= std::numeric_limits::max() ? mmapLimit : std::numeric_limits::max(); mallopt(M_MMAP_THRESHOLD, limit); #else (void) mmapLimit; #endif } MallocMmapGuard::~MallocMmapGuard() { assert(_threadId == std::this_thread::get_id()); #ifdef __linux__ mallopt(M_MMAP_THRESHOLD, 1_Gi); #endif } }