diff options
| author | alxmopo3ov <[email protected]> | 2026-03-26 18:13:33 +0300 |
|---|---|---|
| committer | alxmopo3ov <[email protected]> | 2026-03-26 19:36:00 +0300 |
| commit | 9d4e69b62e1f57d85025bccc76e217ae401004f9 (patch) | |
| tree | 996893f64b57bd4bc026219024a80ef15fe52bb7 /library/cpp | |
| parent | ab4fc65949569ba97be07763181915cbc7c661e7 (diff) | |
ClearCache() method in NMalloc
commit_hash:2a9ac53b44252aeea5188e821743fc79b064947b
Diffstat (limited to 'library/cpp')
| -rw-r--r-- | library/cpp/malloc/api/malloc.h | 4 | ||||
| -rw-r--r-- | library/cpp/malloc/jemalloc/malloc-info.cpp | 4 | ||||
| -rw-r--r-- | library/cpp/malloc/mimalloc/info.cpp | 5 | ||||
| -rw-r--r-- | library/cpp/malloc/system/malloc-info.cpp | 4 | ||||
| -rw-r--r-- | library/cpp/malloc/tcmalloc/malloc-info.cpp | 8 |
5 files changed, 24 insertions, 1 deletions
diff --git a/library/cpp/malloc/api/malloc.h b/library/cpp/malloc/api/malloc.h index ebd545d6dd9..0aa07c0571b 100644 --- a/library/cpp/malloc/api/malloc.h +++ b/library/cpp/malloc/api/malloc.h @@ -18,8 +18,10 @@ namespace NMalloc { extern volatile bool IsAllocatorCorrupted; void AbortFromCorruptedAllocator(const char* errorMessage = nullptr); - // this function should be implemented by malloc implementations + // these function should be implemented by malloc implementations TMallocInfo MallocInfo(); + // clear ALL caches of the allocator. Each implementation clears as much as possible. + void ClearCaches(); struct TAllocHeader { void* Block; diff --git a/library/cpp/malloc/jemalloc/malloc-info.cpp b/library/cpp/malloc/jemalloc/malloc-info.cpp index 87fadc9fb03..8674296b987 100644 --- a/library/cpp/malloc/jemalloc/malloc-info.cpp +++ b/library/cpp/malloc/jemalloc/malloc-info.cpp @@ -104,3 +104,7 @@ TMallocInfo NMalloc::MallocInfo() { return r; } #endif + +void NMalloc::ClearCaches() { + // nothing to do +} diff --git a/library/cpp/malloc/mimalloc/info.cpp b/library/cpp/malloc/mimalloc/info.cpp index 2862532065c..fd37cc165e8 100644 --- a/library/cpp/malloc/mimalloc/info.cpp +++ b/library/cpp/malloc/mimalloc/info.cpp @@ -1,4 +1,5 @@ #include <library/cpp/malloc/api/malloc.h> +#include <contrib/libs/mimalloc/include/mimalloc.h> using namespace NMalloc; @@ -7,3 +8,7 @@ TMallocInfo NMalloc::MallocInfo() { r.Name = "mimalloc"; return r; } + +void NMalloc::ClearCaches() { + mi_collect(true); +} diff --git a/library/cpp/malloc/system/malloc-info.cpp b/library/cpp/malloc/system/malloc-info.cpp index ab6742e203a..847aecf5d1d 100644 --- a/library/cpp/malloc/system/malloc-info.cpp +++ b/library/cpp/malloc/system/malloc-info.cpp @@ -7,3 +7,7 @@ TMallocInfo NMalloc::MallocInfo() { r.Name = "system"; return r; } + +void NMalloc::ClearCaches() { + // nothing to do +} diff --git a/library/cpp/malloc/tcmalloc/malloc-info.cpp b/library/cpp/malloc/tcmalloc/malloc-info.cpp index fbcfa7ee06a..fc4603de595 100644 --- a/library/cpp/malloc/tcmalloc/malloc-info.cpp +++ b/library/cpp/malloc/tcmalloc/malloc-info.cpp @@ -1,4 +1,5 @@ #include <library/cpp/malloc/api/malloc.h> +#include <contrib/libs/tcmalloc/tcmalloc/internal_malloc_extension.h> using namespace NMalloc; @@ -7,3 +8,10 @@ TMallocInfo NMalloc::MallocInfo() { r.Name = "tcmalloc"; return r; } + +void NMalloc::ClearCaches() { + // not available on darwin, see internal_malloc_extension.h for details +#ifndef _darwin_ + MallocExtension_Internal_ReleaseMemoryToSystem(std::numeric_limits<size_t>::max()); +#endif +} |
