summaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/memory
diff options
context:
space:
mode:
authorbabenko <[email protected]>2024-11-06 13:35:13 +0300
committerbabenko <[email protected]>2024-11-06 14:01:26 +0300
commit14a70ab65849ee4dcf734051372b1ff5be87a793 (patch)
tree073b90a3452607dc47222c2065e6b2b6c214b040 /library/cpp/yt/memory
parentb60a78031c047a8c8543bf6a3dc4f828d104dd3c (diff)
Better diagnostics in AbortProcess(Silently|Dramatically)
commit_hash:7bbc13afbd569ca9bb064aed656c12644fd2de96
Diffstat (limited to 'library/cpp/yt/memory')
-rw-r--r--library/cpp/yt/memory/chunked_memory_pool-inl.h7
-rw-r--r--library/cpp/yt/memory/new-inl.h12
-rw-r--r--library/cpp/yt/memory/new.cpp18
-rw-r--r--library/cpp/yt/memory/ya.make1
4 files changed, 29 insertions, 9 deletions
diff --git a/library/cpp/yt/memory/chunked_memory_pool-inl.h b/library/cpp/yt/memory/chunked_memory_pool-inl.h
index 25022041607..00733235f49 100644
--- a/library/cpp/yt/memory/chunked_memory_pool-inl.h
+++ b/library/cpp/yt/memory/chunked_memory_pool-inl.h
@@ -31,9 +31,10 @@ TDerived* TAllocationHolder::Allocate(size_t size, TRefCountedTypeCookie cookie)
{
auto requestedSize = sizeof(TDerived) + size;
auto* ptr = ::malloc(requestedSize);
-
- if (!ptr) {
- AbortProcess(ToUnderlying(EProcessExitCode::OutOfMemory));
+ if (Y_UNLIKELY(!ptr)) {
+ AbortProcessDramatically(
+ EProcessExitCode::OutOfMemory,
+ "Out-of-memory during chunked memory pool allocation");
}
#ifndef _win_
diff --git a/library/cpp/yt/memory/new-inl.h b/library/cpp/yt/memory/new-inl.h
index f0646582ec8..53308fb254e 100644
--- a/library/cpp/yt/memory/new-inl.h
+++ b/library/cpp/yt/memory/new-inl.h
@@ -10,8 +10,6 @@
#include <library/cpp/yt/malloc//malloc.h>
-#include <library/cpp/yt/system/exit.h>
-
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
@@ -178,6 +176,8 @@ Y_FORCE_INLINE TIntrusivePtr<T> SafeConstruct(void* ptr, As&&... args)
}
}
+void AbortOnOom();
+
template <size_t Size, size_t Alignment>
Y_FORCE_INLINE void* AllocateConstSizeAlignedOrCrash()
{
@@ -192,7 +192,7 @@ Y_FORCE_INLINE void* AllocateConstSizeAlignedOrCrash()
}
#endif
if (Y_UNLIKELY(!ptr)) {
- AbortProcess(ToUnderlying(EProcessExitCode::OutOfMemory));
+ AbortOnOom();
}
return ptr;
}
@@ -211,7 +211,7 @@ Y_FORCE_INLINE void* AllocateOrCrash(size_t size)
}
#endif
if (Y_UNLIKELY(!ptr)) {
- AbortProcess(ToUnderlying(EProcessExitCode::OutOfMemory));
+ AbortOnOom();
}
return ptr;
}
@@ -249,7 +249,7 @@ Y_FORCE_INLINE TIntrusivePtr<T> New(
{
auto obj = TryNew<T>(allocator, std::forward<As>(args)...);
if (Y_UNLIKELY(!obj)) {
- AbortProcess(ToUnderlying(EProcessExitCode::OutOfMemory));
+ NYT::NDetail::AbortOnOom();
}
return obj;
}
@@ -288,7 +288,7 @@ Y_FORCE_INLINE TIntrusivePtr<T> NewWithExtraSpace(
{
auto obj = TryNewWithExtraSpace<T>(allocator, extraSpaceSize, std::forward<As>(args)...);
if (Y_UNLIKELY(!obj)) {
- AbortProcess(ToUnderlying(EProcessExitCode::OutOfMemory));
+ NYT::NDetail::AbortOnOom();
}
return obj;
}
diff --git a/library/cpp/yt/memory/new.cpp b/library/cpp/yt/memory/new.cpp
new file mode 100644
index 00000000000..0b4a4b3b8b8
--- /dev/null
+++ b/library/cpp/yt/memory/new.cpp
@@ -0,0 +1,18 @@
+#include "new.h"
+
+#include <library/cpp/yt/system/exit.h>
+
+namespace NYT::NDetail {
+
+////////////////////////////////////////////////////////////////////////////////
+
+void AbortOnOom()
+{
+ AbortProcessDramatically(
+ EProcessExitCode::OutOfMemory,
+ "Out-of-memory during object allocation");
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT::NDetail
diff --git a/library/cpp/yt/memory/ya.make b/library/cpp/yt/memory/ya.make
index bd817454a93..5397dccf32f 100644
--- a/library/cpp/yt/memory/ya.make
+++ b/library/cpp/yt/memory/ya.make
@@ -15,6 +15,7 @@ SRCS(
chunked_memory_pool_output.cpp
chunked_output_stream.cpp
memory_tag.cpp
+ new.cpp
ref.cpp
ref_tracked.cpp
safe_memory_reader.cpp