diff options
Diffstat (limited to 'staging_vespalib/src/vespa/vespalib/util/malloc_mmap_guard.h')
-rw-r--r-- | staging_vespalib/src/vespa/vespalib/util/malloc_mmap_guard.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/staging_vespalib/src/vespa/vespalib/util/malloc_mmap_guard.h b/staging_vespalib/src/vespa/vespalib/util/malloc_mmap_guard.h new file mode 100644 index 00000000000..03e6d38c03c --- /dev/null +++ b/staging_vespalib/src/vespa/vespalib/util/malloc_mmap_guard.h @@ -0,0 +1,28 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#pragma once + +#include <thread> + +namespace vespalib { + +/** + * Provides a hint to malloc implementation that all allocations in the scope of this guard + * will use mmap directly for allocation larger than the given limit. + * NB !! Note that guards can not be nested. Intention is to use around third party libraries where + * you do not control allocation yourself. + * The effect is implementation dependent. vespamalloc applies this only for the calling thread. + **/ +class MallocMmapGuard +{ +public: + MallocMmapGuard(size_t mmapLimit); + MallocMmapGuard(const MallocMmapGuard &) = delete; + MallocMmapGuard & operator=(const MallocMmapGuard &) = delete; + MallocMmapGuard(MallocMmapGuard &&) = delete; + MallocMmapGuard & operator=(MallocMmapGuard &&) = delete; + ~MallocMmapGuard(); +private: + std::thread::id _threadId; +}; + +} // namespace vespalib |