summaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorbabenko <[email protected]>2024-12-21 13:54:47 +0300
committerbabenko <[email protected]>2024-12-21 14:13:54 +0300
commit13408ecdc4c6a6f32aa53066716a601a47f145ff (patch)
tree0bb0357544f9326e162dfa467c8a7fcc10fefb55 /library/cpp
parent57ca1197846b1449c0c778219f9a0524e4c7dd07 (diff)
YT-18571: Pluggable singleton registry
commit_hash:534ea2df7961feea6932d1e243df20d825c7fe69
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/yt/stockpile/README.md12
-rw-r--r--library/cpp/yt/stockpile/stockpile.h52
-rw-r--r--library/cpp/yt/stockpile/stockpile_linux.cpp158
-rw-r--r--library/cpp/yt/stockpile/stockpile_other.cpp12
-rw-r--r--library/cpp/yt/stockpile/ya.make18
5 files changed, 0 insertions, 252 deletions
diff --git a/library/cpp/yt/stockpile/README.md b/library/cpp/yt/stockpile/README.md
deleted file mode 100644
index 6ee4cd1b1f1..00000000000
--- a/library/cpp/yt/stockpile/README.md
+++ /dev/null
@@ -1,12 +0,0 @@
-# stockpile
-
-При приближении к лимиту памяти в memory cgroup, linux запускает механизм direct reclaim,
-чтобы освободить свободную память. По опыту YT, direct reclaim очень сильно замедляет работу
-всего процесса.
-
-Проблема возникает не только, когда память занята анонимными страницами. 50% памяти контейнера
-может быть занято не dirty страницами page cache, но проблема всёравно будет проявляться. Например,
-если процесс активно читает файлы с диска без O_DIRECT, вся память очень быстро будет забита.
-
-Чтобы бороться с этой проблемой, в яндексовом ядре добавлена ручка `madvise(MADV_STOCKPILE)`.
-Больше подробностей в https://st.yandex-team.ru/KERNEL-186 \ No newline at end of file
diff --git a/library/cpp/yt/stockpile/stockpile.h b/library/cpp/yt/stockpile/stockpile.h
deleted file mode 100644
index fae1b3a569e..00000000000
--- a/library/cpp/yt/stockpile/stockpile.h
+++ /dev/null
@@ -1,52 +0,0 @@
-#pragma once
-
-#include <library/cpp/yt/cpu_clock/clock.h>
-
-#include <library/cpp/yt/misc/enum.h>
-
-#include <util/system/types.h>
-
-#include <util/generic/size_literals.h>
-
-#include <util/datetime/base.h>
-
-namespace NYT {
-
-////////////////////////////////////////////////////////////////////////////////
-
-DEFINE_ENUM(EStockpileStrategy,
- ((FixedBreaks) (0))
- ((FlooredLoad) (1))
- ((ProgressiveBackoff) (2))
-);
-
-////////////////////////////////////////////////////////////////////////////////
-
-struct TStockpileOptions
-{
- static constexpr i64 DefaultBufferSize = 4_GBs;
- i64 BufferSize = DefaultBufferSize;
-
- static constexpr int DefaultThreadCount = 4;
- int ThreadCount = DefaultThreadCount;
-
- static constexpr EStockpileStrategy DefaultStrategy = EStockpileStrategy::FixedBreaks;
- EStockpileStrategy Strategy = DefaultStrategy;
-
- static constexpr TDuration DefaultPeriod = TDuration::MilliSeconds(10);
- TDuration Period = DefaultPeriod;
-};
-
-////////////////////////////////////////////////////////////////////////////////
-
-class TStockpileManager
-{
-public:
- //! Configures the background stockpile threads.
- //! Safe to call multiple times.
- static void Reconfigure(TStockpileOptions options);
-};
-
-////////////////////////////////////////////////////////////////////////////////
-
-} // namespace NYT
diff --git a/library/cpp/yt/stockpile/stockpile_linux.cpp b/library/cpp/yt/stockpile/stockpile_linux.cpp
deleted file mode 100644
index 8ae847dec77..00000000000
--- a/library/cpp/yt/stockpile/stockpile_linux.cpp
+++ /dev/null
@@ -1,158 +0,0 @@
-#include "stockpile.h"
-
-#include <library/cpp/yt/threading/spin_lock.h>
-
-#include <library/cpp/yt/misc/global.h>
-
-#include <library/cpp/yt/memory/leaky_singleton.h>
-
-#include <library/cpp/yt/logging/logger.h>
-
-#include <thread>
-
-#include <sys/mman.h>
-
-#include <util/system/thread.h>
-
-#include <string.h>
-
-namespace NYT {
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace {
-
-YT_DEFINE_GLOBAL(const NLogging::TLogger, Logger, "Stockpile");
-constexpr int MADV_STOCKPILE = 0x59410004;
-
-} // namespace
-
-class TStockpileManagerImpl
-{
-public:
- static TStockpileManagerImpl* Get()
- {
- return LeakySingleton<TStockpileManagerImpl>();
- }
-
- void Reconfigure(TStockpileOptions options)
- {
- auto guard = Guard(SpinLock_);
-
- Run_.store(false);
- for (const auto& thread : Threads_) {
- thread->join();
- }
-
- Threads_.clear();
- Run_.store(true);
-
- Options_ = options;
-
- for (int threadIndex = 0; threadIndex < Options_.ThreadCount; ++threadIndex) {
- Threads_.push_back(std::make_unique<std::thread>(&TStockpileManagerImpl::ThreadMain, this));
- }
- }
-
-private:
- DECLARE_LEAKY_SINGLETON_FRIEND();
-
- const i64 PageSize_ = sysconf(_SC_PAGESIZE);
-
- YT_DECLARE_SPIN_LOCK(NThreading::TSpinLock, SpinLock_);
- std::vector<std::unique_ptr<std::thread>> Threads_;
- TStockpileOptions Options_;
- std::atomic<bool> Run_ = false;
-
- void ThreadMain()
- {
- TThread::SetCurrentThreadName("Stockpile");
-
- auto bufferSize = Options_.BufferSize;
- auto period = Options_.Period;
-
- while (Run_.load()) {
- switch (Options_.Strategy) {
- case EStockpileStrategy::FixedBreaks:
- RunWithFixedBreaks(Options_.BufferSize, Options_.Period);
- break;
-
- case EStockpileStrategy::FlooredLoad:
- RunWithCappedLoad(Options_.BufferSize, Options_.Period);
- break;
-
- case EStockpileStrategy::ProgressiveBackoff:
- std::tie(bufferSize, period) = RunWithBackoffs(bufferSize, period);
- break;
-
- default:
- YT_ABORT();
- }
- }
- }
-
- void RunWithFixedBreaks(i64 bufferSize, TDuration period)
- {
- auto returnCode = -::madvise(nullptr, bufferSize, MADV_STOCKPILE);
- YT_LOG_DEBUG_IF(returnCode != 0, "System call \"madvise\" failed: %v", strerror(returnCode));
-
- Sleep(period);
- }
-
- void RunWithCappedLoad(i64 bufferSize, TDuration period)
- {
- auto started = GetApproximateCpuInstant();
-
- auto returnCode = -::madvise(nullptr, bufferSize, MADV_STOCKPILE);
- YT_LOG_DEBUG_IF(returnCode != 0, "System call \"madvise\" failed: %v", strerror(returnCode));
-
- auto duration = CpuDurationToDuration(GetApproximateCpuInstant() - started);
- if (duration < period) {
- Sleep(period - duration);
- }
- }
-
- std::pair<i64, TDuration> RunWithBackoffs(
- i64 adjustedBufferSize,
- TDuration adjustedPeriod)
- {
- int result = ::madvise(nullptr, adjustedBufferSize, MADV_STOCKPILE);
- if (result == 0) {
- Sleep(Options_.Period);
- return {Options_.BufferSize, Options_.Period};
- }
-
- YT_LOG_DEBUG("System call \"madvise\" failed: %v", strerror(errno));
- switch (errno) {
- case ENOMEM:
- if (adjustedBufferSize / 2 >= PageSize_) {
- // Immediately make an attempt to reclaim half as much.
- adjustedBufferSize = adjustedBufferSize / 2;
- } else {
- // Unless there is not even a single reclaimable page.
- Sleep(Options_.Period);
- }
- return {adjustedBufferSize, Options_.Period};
-
- case EAGAIN:
- case EINTR:
- Sleep(adjustedPeriod);
- return {Options_.BufferSize, adjustedPeriod + Options_.Period};
-
- default:
- Sleep(Options_.Period);
- return {Options_.BufferSize, Options_.Period};
- }
- }
-};
-
-////////////////////////////////////////////////////////////////////////////////
-
-void TStockpileManager::Reconfigure(TStockpileOptions options)
-{
- TStockpileManagerImpl::Get()->Reconfigure(std::move(options));
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-} // namespace NYT
diff --git a/library/cpp/yt/stockpile/stockpile_other.cpp b/library/cpp/yt/stockpile/stockpile_other.cpp
deleted file mode 100644
index 481b111b56b..00000000000
--- a/library/cpp/yt/stockpile/stockpile_other.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-#include "stockpile.h"
-
-namespace NYT {
-
-////////////////////////////////////////////////////////////////////////////////
-
-void TStockpileManager::Reconfigure(TStockpileOptions /*options*/)
-{ }
-
-////////////////////////////////////////////////////////////////////////////////
-
-} // namespace NYT
diff --git a/library/cpp/yt/stockpile/ya.make b/library/cpp/yt/stockpile/ya.make
deleted file mode 100644
index 36ce673ba67..00000000000
--- a/library/cpp/yt/stockpile/ya.make
+++ /dev/null
@@ -1,18 +0,0 @@
-LIBRARY()
-
-INCLUDE(${ARCADIA_ROOT}/library/cpp/yt/ya_cpp.make.inc)
-
-IF (OS_LINUX AND NOT SANITIZER_TYPE)
- SRCS(stockpile_linux.cpp)
-ELSE()
- SRCS(stockpile_other.cpp)
-ENDIF()
-
-PEERDIR(
- library/cpp/yt/misc
- library/cpp/yt/threading
- library/cpp/yt/logging
- library/cpp/yt/memory
-)
-
-END()