aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/util/malloc_mmap_guard.h
blob: 03e6d38c03c852563f6455e207519208a63e6dd9 (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
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