aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/stockpile/stockpile_linux.cpp
blob: 3ee83d93341a537dccf5436c2ec3aa22843d3cd9 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "stockpile.h"

#include <thread>
#include <mutex>

#include <sys/mman.h>

#include <util/system/thread.h>

namespace NYT {

////////////////////////////////////////////////////////////////////////////////

namespace {

void RunStockpile(const TStockpileOptions& options)
{
    TThread::SetCurrentThreadName("Stockpile");

    constexpr int MADV_STOCKPILE = 0x59410004;

    while (true) {
        ::madvise(nullptr, options.BufferSize, MADV_STOCKPILE);
        Sleep(options.Period);
    }
}

} // namespace

void ConfigureStockpile(const TStockpileOptions& options)
{
    static std::once_flag OnceFlag;
    std::call_once(OnceFlag, [options] {
        for (int i = 0; i < options.ThreadCount; i++) {
            std::thread(RunStockpile, options).detach();
        }
    });
}

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT