aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials
diff options
context:
space:
mode:
authorilezhankin <ilezhankin@yandex-team.com>2024-11-12 18:36:18 +0300
committerilezhankin <ilezhankin@yandex-team.com>2024-11-12 18:50:50 +0300
commit1620cea68d4380267df949c1a62270c7e961ba89 (patch)
tree6971203a7600eeb954a42706a16c9c1e7750e0d6 /yql/essentials
parentc24e1e13cf409f09b125968fd3717ede0147c52d (diff)
downloadydb-1620cea68d4380267df949c1a62270c7e961ba89.tar.gz
Improve profiling of memory allocations
1. С точки зрения кода не все сценарии в режиме PROFILE_MEMORY_ALLOCATIONS правильно работали - например, arrow аллокации. Это исправлено. 2. С точки зрения сборки не все таргеты правильно получали флаг PROFILE_MEMORY_ALLOCATIONS и в результате, например, аллокация могла быть через tcmalloc, а освобождение через механизм учёта памяти mkql аллокатора. Здесь сделана отдельная либа в yql/utils, которую нужно подключать в сборке. commit_hash:02ceea3de95ce6a2587238552d0b834d2016333b
Diffstat (limited to 'yql/essentials')
-rw-r--r--yql/essentials/minikql/aligned_page_pool.cpp6
-rw-r--r--yql/essentials/minikql/mkql_alloc.cpp17
-rw-r--r--yql/essentials/minikql/ya.make9
-rw-r--r--yql/essentials/utils/memory_profiling/ya.make7
-rw-r--r--yql/essentials/utils/ya.make1
5 files changed, 33 insertions, 7 deletions
diff --git a/yql/essentials/minikql/aligned_page_pool.cpp b/yql/essentials/minikql/aligned_page_pool.cpp
index 6c149ca84c..ec9199bc27 100644
--- a/yql/essentials/minikql/aligned_page_pool.cpp
+++ b/yql/essentials/minikql/aligned_page_pool.cpp
@@ -373,6 +373,7 @@ void* TAlignedPagePoolImpl<T>::GetPage() {
throw TMemoryLimitExceededException();
}
+#ifndef PROFILE_MEMORY_ALLOCATIONS
if (const auto ptr = TGlobalPools<T, false>::Instance().Get(0).GetPage()) {
TotalAllocated += POOL_PAGE_SIZE;
if (AllocNotifyCallback) {
@@ -389,23 +390,24 @@ void* TAlignedPagePoolImpl<T>::GetPage() {
}
++PageMissCount;
+#endif
#ifdef PROFILE_MEMORY_ALLOCATIONS
const auto res = GetBlock(POOL_PAGE_SIZE);
#else
const auto res = Alloc(POOL_PAGE_SIZE);
+ AllPages.emplace(res);
#endif
- AllPages.emplace(res);
return res;
}
template<typename T>
void TAlignedPagePoolImpl<T>::ReturnPage(void* addr) noexcept {
- Y_DEBUG_ABORT_UNLESS(AllPages.find(addr) != AllPages.end());
#ifdef PROFILE_MEMORY_ALLOCATIONS
ReturnBlock(addr, POOL_PAGE_SIZE);
#else
+ Y_DEBUG_ABORT_UNLESS(AllPages.find(addr) != AllPages.end());
FreePages.emplace(addr);
#endif
}
diff --git a/yql/essentials/minikql/mkql_alloc.cpp b/yql/essentials/minikql/mkql_alloc.cpp
index aba89a4890..1708cbfde8 100644
--- a/yql/essentials/minikql/mkql_alloc.cpp
+++ b/yql/essentials/minikql/mkql_alloc.cpp
@@ -49,10 +49,14 @@ void TAllocState::CleanupPAllocList(TListEntry* root) {
void TAllocState::CleanupArrowList(TListEntry* root) {
for (auto curr = root->Right; curr != root; ) {
auto next = curr->Right;
+#ifdef PROFILE_MEMORY_ALLOCATIONS
+ free(curr);
+#else
auto size = ((TMkqlArrowHeader*)curr)->Size;
auto fullSize = size + sizeof(TMkqlArrowHeader);
ReleaseAlignedPage(curr, fullSize);
curr = next;
+#endif
}
root->InitLinks();
@@ -251,8 +255,15 @@ void* MKQLArrowAllocate(ui64 size) {
if (state->EnableArrowTracking) {
state->OffloadAlloc(fullSize);
}
-
+
+#ifdef PROFILE_MEMORY_ALLOCATIONS
+ auto ptr = malloc(fullSize);
+ if (!ptr) {
+ throw TMemoryLimitExceededException();
+ }
+#else
auto ptr = GetAlignedPage(fullSize);
+#endif
auto header = (TMkqlArrowHeader*)ptr;
if (state->EnableArrowTracking) {
header->Entry.Link(&state->ArrowBlocksRoot);
@@ -286,7 +297,11 @@ void MKQLArrowFree(const void* mem, ui64 size) {
}
Y_ENSURE(size == header->Size);
+#ifdef PROFILE_MEMORY_ALLOCATIONS
+ free(header);
+#else
ReleaseAlignedPage(header, fullSize);
+#endif
}
void MKQLArrowUntrack(const void* mem) {
diff --git a/yql/essentials/minikql/ya.make b/yql/essentials/minikql/ya.make
index 5c1d732f77..5976632607 100644
--- a/yql/essentials/minikql/ya.make
+++ b/yql/essentials/minikql/ya.make
@@ -61,17 +61,18 @@ PEERDIR(
library/cpp/packedtypes
library/cpp/resource
library/cpp/yson
- yql/essentials/types/binary_json
- yql/essentials/types/dynumber
- yql/essentials/types/uuid
yql/essentials/core/pg_settings
+ yql/essentials/core/sql_types
yql/essentials/minikql/dom
yql/essentials/parser/pg_catalog
yql/essentials/parser/pg_wrapper/interface
yql/essentials/public/udf
yql/essentials/public/udf/tz
+ yql/essentials/types/binary_json
+ yql/essentials/types/dynumber
+ yql/essentials/types/uuid
yql/essentials/utils
- yql/essentials/core/sql_types
+ yql/essentials/utils/memory_profiling
)
IF (MKQL_RUNTIME_VERSION)
diff --git a/yql/essentials/utils/memory_profiling/ya.make b/yql/essentials/utils/memory_profiling/ya.make
new file mode 100644
index 0000000000..8c26d79785
--- /dev/null
+++ b/yql/essentials/utils/memory_profiling/ya.make
@@ -0,0 +1,7 @@
+LIBRARY()
+
+IF (PROFILE_MEMORY_ALLOCATIONS)
+ CFLAGS(GLOBAL -DPROFILE_MEMORY_ALLOCATIONS)
+ENDIF()
+
+END()
diff --git a/yql/essentials/utils/ya.make b/yql/essentials/utils/ya.make
index 8f34cc54ba..768c5538b9 100644
--- a/yql/essentials/utils/ya.make
+++ b/yql/essentials/utils/ya.make
@@ -61,6 +61,7 @@ IF (OPENSOURCE_PROJECT != "yt")
failure_injector
fetch
log
+ memory_profiling
network
signals
sys