aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/stockpile/stockpile_linux.cpp
diff options
context:
space:
mode:
authorqrort <qrort@yandex-team.com>2022-11-30 23:47:12 +0300
committerqrort <qrort@yandex-team.com>2022-11-30 23:47:12 +0300
commit22f8ae0e3f5d68b92aecccdf96c1d841a0334311 (patch)
treebffa27765faf54126ad44bcafa89fadecb7a73d7 /library/cpp/yt/stockpile/stockpile_linux.cpp
parent332b99e2173f0425444abb759eebcb2fafaa9209 (diff)
downloadydb-22f8ae0e3f5d68b92aecccdf96c1d841a0334311.tar.gz
validate canons without yatest_common
Diffstat (limited to 'library/cpp/yt/stockpile/stockpile_linux.cpp')
-rw-r--r--library/cpp/yt/stockpile/stockpile_linux.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/library/cpp/yt/stockpile/stockpile_linux.cpp b/library/cpp/yt/stockpile/stockpile_linux.cpp
new file mode 100644
index 0000000000..9be33e3811
--- /dev/null
+++ b/library/cpp/yt/stockpile/stockpile_linux.cpp
@@ -0,0 +1,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 StockpileMemory(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