aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-07-26 23:58:57 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-07-27 00:08:51 +0300
commit58ee0112394bf094049e31802f591067f96a4ed9 (patch)
treeb5f34a4986db964b04690697df9b0b9bdcb6b66b
parentb71dc560d0fafeef490a495954022bd0110f3ecb (diff)
downloadydb-58ee0112394bf094049e31802f591067f96a4ed9.tar.gz
Intermediate changes
-rw-r--r--yt/yt/library/oom/oom.cpp12
-rw-r--r--yt/yt/library/oom/oom.h6
-rw-r--r--yt/yt/library/oom/tcmalloc_memory_limit_handler.cpp23
-rw-r--r--yt/yt/library/oom/unittests/oom_ut.cpp4
4 files changed, 26 insertions, 19 deletions
diff --git a/yt/yt/library/oom/oom.cpp b/yt/yt/library/oom/oom.cpp
index 648485c77b..10b3e64e7b 100644
--- a/yt/yt/library/oom/oom.cpp
+++ b/yt/yt/library/oom/oom.cpp
@@ -21,7 +21,9 @@
namespace NYT {
-static NYT::NLogging::TLogger Logger{"OOM"};
+////////////////////////////////////////////////////////////////////////////////
+
+YT_DEFINE_GLOBAL(const NYT::NLogging::TLogger, Logger, "OOM");
////////////////////////////////////////////////////////////////////////////////
@@ -45,10 +47,10 @@ static const char* TCMallocStats[] = {
"tcmalloc.transfer_cache_free",
"tcmalloc.hard_usage_limit_bytes",
"tcmalloc.desired_usage_limit_bytes",
- "tcmalloc.required_bytes"
+ "tcmalloc.required_bytes",
};
-void OOMWatchdog(TOOMOptions options)
+void OomWatchdog(TOomWatchdogOptions options)
{
while (true) {
auto rss = GetProcessMemoryUsage().Rss;
@@ -124,12 +126,12 @@ void OOMWatchdog(TOOMOptions options)
}
}
-void EnableEarlyOOMWatchdog(TOOMOptions options)
+void EnableEarlyOomWatchdog(TOomWatchdogOptions options)
{
static std::once_flag onceFlag;
std::call_once(onceFlag, [options] {
- std::thread(OOMWatchdog, options).detach();
+ std::thread(OomWatchdog, options).detach();
});
}
diff --git a/yt/yt/library/oom/oom.h b/yt/yt/library/oom/oom.h
index aa85cc678b..11edd7ca02 100644
--- a/yt/yt/library/oom/oom.h
+++ b/yt/yt/library/oom/oom.h
@@ -10,20 +10,20 @@ namespace NYT {
////////////////////////////////////////////////////////////////////////////////
-struct TOOMOptions
+struct TOomWatchdogOptions
{
std::optional<i64> MemoryLimit;
TString HeapDumpPath = "oom.pb.gz";
};
-void EnableEarlyOOMWatchdog(TOOMOptions options);
+void EnableEarlyOomWatchdog(TOomWatchdogOptions options);
////////////////////////////////////////////////////////////////////////////////
struct TTCMallocLimitHandlerOptions
{
TString HeapDumpDirectory;
- TDuration Timeout = TDuration::Seconds(300);
+ TDuration Timeout = TDuration::Minutes(5);
};
void EnableTCMallocLimitHandler(TTCMallocLimitHandlerOptions options);
diff --git a/yt/yt/library/oom/tcmalloc_memory_limit_handler.cpp b/yt/yt/library/oom/tcmalloc_memory_limit_handler.cpp
index 48520bd873..ef63f60b83 100644
--- a/yt/yt/library/oom/tcmalloc_memory_limit_handler.cpp
+++ b/yt/yt/library/oom/tcmalloc_memory_limit_handler.cpp
@@ -93,6 +93,7 @@ public:
private:
const TTCMallocLimitHandlerOptions Options_;
+
bool Fired_ = false;
bool NeedToHandle_ = false;
std::mutex Mutex_;
@@ -123,12 +124,12 @@ private:
SetupMemoryProfileTimeout(Options_.Timeout.Seconds());
CollectAndDumpMemoryProfile(heapDumpPath);
- Cerr << "TTCMallocLimitHandler: Heap profile written." << Endl;
+ Cerr << "TTCMallocLimitHandler: Heap profile written" << Endl;
::_exit(0);
}
if (childPid < 0) {
- Cerr << "TTCMallocLimitHandler: fork failed with code:" << LastSystemErrorText() << Endl;
+ Cerr << "TTCMallocLimitHandler: Fork failed: " << LastSystemErrorText() << Endl;
::_exit(1);
}
@@ -180,26 +181,28 @@ void SetSoftMemoryLimitHandler(THandler handler)
////////////////////////////////////////////////////////////////////////////////
-static TAtomicIntrusivePtr<TTCMallocLimitHandler> LimitHandler_;
+namespace {
-////////////////////////////////////////////////////////////////////////////////
+YT_DEFINE_GLOBAL(TAtomicIntrusivePtr<TTCMallocLimitHandler>, LimitHandler);
void HandleTCMallocLimit()
{
- if (auto handler = LimitHandler_.Acquire()) {
+ if (auto handler = LimitHandler().Acquire()) {
handler->Fire();
}
}
+} // namespace
+
void EnableTCMallocLimitHandler(TTCMallocLimitHandlerOptions options)
{
{
- if (LimitHandler_.Acquire()) {
+ if (LimitHandler().Acquire()) {
return;
}
- TAtomicIntrusivePtr<TTCMallocLimitHandler>::TRawPtr expected{nullptr};
- LimitHandler_.CompareAndSwap(expected, New<TTCMallocLimitHandler>(options));
+ TAtomicIntrusivePtr<TTCMallocLimitHandler>::TRawPtr expected = nullptr;
+ LimitHandler().CompareAndSwap(expected, New<TTCMallocLimitHandler>(options));
}
SetSoftMemoryLimitHandler<tcmalloc::MallocExtension>(&HandleTCMallocLimit);
@@ -207,7 +210,9 @@ void EnableTCMallocLimitHandler(TTCMallocLimitHandlerOptions options)
void DisableTCMallocLimitHandler()
{
- LimitHandler_.Reset();
+ LimitHandler().Reset();
}
+////////////////////////////////////////////////////////////////////////////////
+
} // namespace NYT
diff --git a/yt/yt/library/oom/unittests/oom_ut.cpp b/yt/yt/library/oom/unittests/oom_ut.cpp
index 6c61f456f9..692fb85232 100644
--- a/yt/yt/library/oom/unittests/oom_ut.cpp
+++ b/yt/yt/library/oom/unittests/oom_ut.cpp
@@ -14,7 +14,7 @@ namespace {
TEST(EarlyOOM, Crash)
{
auto checkOOM = [] {
- EnableEarlyOOMWatchdog(TOOMOptions{
+ EnableEarlyOomWatchdog(TOomWatchdogOptions{
.MemoryLimit = 0,
});
@@ -28,7 +28,7 @@ TEST(EarlyOOM, Crash)
TEST(EarlyOOM, NoCrash)
{
- EnableEarlyOOMWatchdog(TOOMOptions{
+ EnableEarlyOomWatchdog(TOomWatchdogOptions{
.MemoryLimit = 1_GB,
});