diff options
author | Maxim Yurchuk <maxim-yurchuk@ydb.tech> | 2024-11-20 17:37:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-20 17:37:57 +0000 |
commit | f76323e9b295c15751e51e3443aa47a36bee8023 (patch) | |
tree | 4113c8cad473a33e0f746966e0cf087252fa1d7a /contrib/libs/tcmalloc | |
parent | 753ecb8d410a4cb459c26f3a0082fb2d1724fe63 (diff) | |
parent | a7b9a6afea2a9d7a7bfac4c5eb4c1a8e60adb9e6 (diff) | |
download | ydb-f76323e9b295c15751e51e3443aa47a36bee8023.tar.gz |
Merge pull request #11788 from ydb-platform/mergelibs-241120-1113
Library import 241120-1113
Diffstat (limited to 'contrib/libs/tcmalloc')
-rw-r--r-- | contrib/libs/tcmalloc/patches/handler.patch | 49 | ||||
-rw-r--r-- | contrib/libs/tcmalloc/tcmalloc/malloc_extension.cc | 14 | ||||
-rw-r--r-- | contrib/libs/tcmalloc/tcmalloc/malloc_extension.h | 4 | ||||
-rw-r--r-- | contrib/libs/tcmalloc/tcmalloc/page_allocator.cc | 4 |
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) { |