Skip to content

Commit a9cc770

Browse files
authored
Set tcmalloc soft limit when profiling memory allocations (#12379)
1 parent 141ba2e commit a9cc770

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

ydb/core/memory_controller/memory_controller.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ::NFormatPrivate::THumanReadableSize HumanReadableBytes(ui64 bytes) {
3535
}
3636

3737
TString HumanReadableBytes(std::optional<ui64> bytes) {
38-
return bytes.has_value() ? TString(TStringBuilder() << HumanReadableBytes(bytes.value())) : "none";
38+
return bytes.has_value() ? TString(TStringBuilder() << HumanReadableBytes(bytes.value())) : "none";
3939
}
4040

4141
}
@@ -126,6 +126,14 @@ class TMemoryController : public TActorBootstrapped<TMemoryController> {
126126
new NConsole::TEvConfigsDispatcher::TEvSetConfigSubscriptionRequest({
127127
NKikimrConsole::TConfigItem::MemoryControllerConfigItem}));
128128

129+
// When profiling memory it's convenient to set initial tcmalloc soft limit
130+
#ifdef PROFILE_MEMORY_ALLOCATIONS
131+
tcmalloc::MallocExtension::MemoryLimit limit;
132+
limit.hard = false;
133+
limit.limit = GetSoftLimitBytes(Config, hardLimitBytes);
134+
tcmalloc::MallocExtension::SetMemoryLimit(limit);
135+
#endif
136+
129137
HandleWakeup(ctx);
130138

131139
LOG_INFO_S(ctx, NKikimrServices::MEMORY_CONTROLLER, "Bootstrapped with config " << Config.ShortDebugString());

ydb/core/memory_controller/ya.make

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ SRCS(
77

88
PEERDIR(
99
ydb/core/base
10-
ydb/library/actors/core
11-
ydb/library/services
12-
yql/essentials/minikql
1310
ydb/core/cms/console
1411
ydb/core/mon_alloc
1512
ydb/core/node_whiteboard
1613
ydb/core/tablet
14+
ydb/library/actors/core
15+
ydb/library/services
16+
yql/essentials/minikql
17+
yql/essentials/utils/memory_profiling
1718
)
1819

1920
YQL_LAST_ABI_VERSION()
@@ -22,4 +23,4 @@ END()
2223

2324
RECURSE_FOR_TESTS(
2425
ut
25-
)
26+
)

0 commit comments

Comments
 (0)