summaryrefslogtreecommitdiffstats
path: root/staging_vespalib/src/vespa/vespalib/util/malloc_mmap_guard.h
blob: 3cf26202f9b495ae67d73caa3a8e13bd8d914761 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// 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 givem limit.
 * 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