aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/tcmalloc
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2024-11-20 11:14:58 +0000
committerAlexander Smirnov <alex@ydb.tech>2024-11-20 11:14:58 +0000
commit31773f157bf8164364649b5f470f52dece0a4317 (patch)
tree33d0f7eef45303ab68cf08ab381ce5e5e36c5240 /contrib/libs/tcmalloc
parent2c7938962d8689e175574fc1e817c05049f27905 (diff)
parenteff600952d5dfe17942f38f510a8ac2b203bb3a5 (diff)
downloadydb-31773f157bf8164364649b5f470f52dece0a4317.tar.gz
Merge branch 'rightlib' into mergelibs-241120-1113
Diffstat (limited to 'contrib/libs/tcmalloc')
-rw-r--r--contrib/libs/tcmalloc/patches/handler.patch49
-rw-r--r--contrib/libs/tcmalloc/tcmalloc/malloc_extension.cc14
-rw-r--r--contrib/libs/tcmalloc/tcmalloc/malloc_extension.h4
-rw-r--r--contrib/libs/tcmalloc/tcmalloc/page_allocator.cc4
4 files changed, 71 insertions, 0 deletions
diff --git a/contrib/libs/tcmalloc/patches/handler.patch b/contrib/libs/tcmalloc/patches/handler.patch
new file mode 100644
index 0000000000..ce30d7e1c2
--- /dev/null
+++ b/contrib/libs/tcmalloc/patches/handler.patch
@@ -0,0 +1,49 @@
+--- contrib/libs/tcmalloc/tcmalloc/malloc_extension.cc (index)
++++ contrib/libs/tcmalloc/tcmalloc/malloc_extension.cc (working tree)
+@@ -468,6 +468,20 @@ void MallocExtension::EnableForkSupport() {
+ #endif
+ }
+
++static std::atomic<MallocExtension::SoftMemoryLimitCallback*> SoftMemoryLimitHandler_;
++
++void MallocExtension::SetSoftMemoryLimitHandler(SoftMemoryLimitCallback* handler) {
++#if ABSL_INTERNAL_HAVE_WEAK_MALLOCEXTENSION_STUBS
++ SoftMemoryLimitHandler_.store(handler);
++#endif
++}
++
++MallocExtension::SoftMemoryLimitCallback* MallocExtension::GetSoftMemoryLimitHandler() {
++#if ABSL_INTERNAL_HAVE_WEAK_MALLOCEXTENSION_STUBS
++ return SoftMemoryLimitHandler_.load();
++#endif
++}
++
+ void MallocExtension::SetSampleUserDataCallbacks(
+ CreateSampleUserDataCallback create,
+ CopySampleUserDataCallback copy,
+--- contrib/libs/tcmalloc/tcmalloc/malloc_extension.h (index)
++++ contrib/libs/tcmalloc/tcmalloc/malloc_extension.h (working tree)
+@@ -475,6 +475,10 @@ class MallocExtension final {
+ // Allocator will continue to function correctly in the child, after calling fork().
+ static void EnableForkSupport();
+
++ using SoftMemoryLimitCallback = void();
++ static void SetSoftMemoryLimitHandler(SoftMemoryLimitCallback* handler);
++ static SoftMemoryLimitCallback* GetSoftMemoryLimitHandler();
++
+ using CreateSampleUserDataCallback = void*();
+ using CopySampleUserDataCallback = void*(void*);
+ using DestroySampleUserDataCallback = void(void*);
+--- contrib/libs/tcmalloc/tcmalloc/page_allocator.cc (index)
++++ contrib/libs/tcmalloc/tcmalloc/page_allocator.cc (working tree)
+@@ -151,6 +151,10 @@ void PageAllocator::ShrinkToUsageLimit() {
+ warned = true;
+ Log(kLogWithStack, __FILE__, __LINE__, "Couldn't respect usage limit of ",
+ limit_, "and OOM is likely to follow.");
++
++ if (auto* handler = MallocExtension::GetSoftMemoryLimitHandler()) {
++ (*handler)();
++ }
+ }
+
+ bool PageAllocator::ShrinkHardBy(Length pages) {
diff --git a/contrib/libs/tcmalloc/tcmalloc/malloc_extension.cc b/contrib/libs/tcmalloc/tcmalloc/malloc_extension.cc
index ad3205fcdc..5a4ad70043 100644
--- a/contrib/libs/tcmalloc/tcmalloc/malloc_extension.cc
+++ b/contrib/libs/tcmalloc/tcmalloc/malloc_extension.cc
@@ -468,6 +468,20 @@ void MallocExtension::EnableForkSupport() {
#endif
}
+static std::atomic<MallocExtension::SoftMemoryLimitCallback*> SoftMemoryLimitHandler_;
+
+void MallocExtension::SetSoftMemoryLimitHandler(SoftMemoryLimitCallback* handler) {
+#if ABSL_INTERNAL_HAVE_WEAK_MALLOCEXTENSION_STUBS
+ SoftMemoryLimitHandler_.store(handler);
+#endif
+}
+
+MallocExtension::SoftMemoryLimitCallback* MallocExtension::GetSoftMemoryLimitHandler() {
+#if ABSL_INTERNAL_HAVE_WEAK_MALLOCEXTENSION_STUBS
+ return SoftMemoryLimitHandler_.load();
+#endif
+}
+
void MallocExtension::SetSampleUserDataCallbacks(
CreateSampleUserDataCallback create,
CopySampleUserDataCallback copy,
diff --git a/contrib/libs/tcmalloc/tcmalloc/malloc_extension.h b/contrib/libs/tcmalloc/tcmalloc/malloc_extension.h
index fcbd347ca1..19b68ba8ac 100644
--- a/contrib/libs/tcmalloc/tcmalloc/malloc_extension.h
+++ b/contrib/libs/tcmalloc/tcmalloc/malloc_extension.h
@@ -475,6 +475,10 @@ class MallocExtension final {
// Allocator will continue to function correctly in the child, after calling fork().
static void EnableForkSupport();
+ using SoftMemoryLimitCallback = void();
+ static void SetSoftMemoryLimitHandler(SoftMemoryLimitCallback* handler);
+ static SoftMemoryLimitCallback* GetSoftMemoryLimitHandler();
+
using CreateSampleUserDataCallback = void*();
using CopySampleUserDataCallback = void*(void*);
using DestroySampleUserDataCallback = void(void*);
diff --git a/contrib/libs/tcmalloc/tcmalloc/page_allocator.cc b/contrib/libs/tcmalloc/tcmalloc/page_allocator.cc
index e9599ef46a..2999b28ad9 100644
--- a/contrib/libs/tcmalloc/tcmalloc/page_allocator.cc
+++ b/contrib/libs/tcmalloc/tcmalloc/page_allocator.cc
@@ -151,6 +151,10 @@ void PageAllocator::ShrinkToUsageLimit() {
warned = true;
Log(kLogWithStack, __FILE__, __LINE__, "Couldn't respect usage limit of ",
limit_, "and OOM is likely to follow.");
+
+ if (auto* handler = MallocExtension::GetSoftMemoryLimitHandler()) {
+ (*handler)();
+ }
}
bool PageAllocator::ShrinkHardBy(Length pages) {