[COMMIT seastar master] Allow abort on OOM to be set both ways

54 views
Skip to first unread message

Commit Bot

<bot@cloudius-systems.com>
unread,
Mar 2, 2023, 2:07:08 AM3/2/23
to seastar-dev@googlegroups.com, Travis Downs
From: Travis Downs <travis...@redpanda.com>
Committer: Travis Downs <travis...@redpanda.com>
Branch: master

Allow abort on OOM to be set both ways

There is a global "abort on OOM" setting in the seastar, and
we allow enabling it via a public method in seastar::memory.

There was no corresponding method to disable it, but such
a method is useful in order to give applications full control
over this setting.

Introduce a new method which takes a boolean parameter in order to allow
both enabling and disabling the abort behavior. The old call is
deprecated and simply falls the new method with enabled=true.

---
diff --git a/include/seastar/core/memory.hh b/include/seastar/core/memory.hh
--- a/include/seastar/core/memory.hh
+++ b/include/seastar/core/memory.hh
@@ -139,6 +139,8 @@ static constexpr size_t huge_page_size =
void configure(std::vector<resource::memory> m, bool mbind,
std::optional<std::string> hugetlbfs_path = {});

+// A deprecated alias for set_abort_on_allocation_failure(true).
+[[deprecated("use set_abort_on_allocation_failure(true) instead")]]
void enable_abort_on_allocation_failure();

class disable_abort_on_alloc_failure_temporarily {
@@ -223,6 +225,24 @@ void set_reclaim_hook(

/// \endcond

+/// \brief Set the global state of the abort on allocation failure behavior.
+///
+/// If enabled, an allocation failure (i.e., the requested memory
+/// could not be allocated even after reclaim was attempted), will
+/// generally result in `abort()` being called. If disabled, the
+/// failure is reported to the caller, e.g., by throwing a
+/// `std::bad_alloc` for C++ allocations such as new, or returning
+/// a null pointer from malloc.
+///
+/// Note that even if the global state is set to enabled, the
+/// `disable_abort_on_alloc_failure_temporarily` class may override
+/// the behavior tepmorarily on a given shard. That is, abort only
+/// occurs if abort is globablly enabled on this shard _and_ there
+/// are no `disable_abort_on_alloc_failure_temporarily` objects
+/// currently alive on this shard.
+void set_abort_on_allocation_failure(bool enabled);
+
+
class statistics;

/// Capture a snapshot of memory allocation statistics for this lcore.
diff --git a/src/core/memory.cc b/src/core/memory.cc
--- a/src/core/memory.cc
+++ b/src/core/memory.cc
@@ -100,6 +100,10 @@ disable_abort_on_alloc_failure_temporarily::~disable_abort_on_alloc_failure_temp
--abort_on_alloc_failure_suppressed;
}

+void enable_abort_on_allocation_failure() {
+ set_abort_on_allocation_failure(true);
+}
+
static std::pmr::polymorphic_allocator<char> static_malloc_allocator{std::pmr::get_default_resource()};;
std::pmr::polymorphic_allocator<char>* malloc_allocator{&static_malloc_allocator};

@@ -1600,8 +1604,8 @@ class disable_report_on_alloc_failure_temporarily {
static std::atomic<bool> abort_on_allocation_failure{false};
static std::atomic<alloc_failure_kind> dump_diagnostics_on_alloc_failure_kind{alloc_failure_kind::critical};

-void enable_abort_on_allocation_failure() {
- abort_on_allocation_failure.store(true, std::memory_order_seq_cst);
+void set_abort_on_allocation_failure(bool enabled) {
+ abort_on_allocation_failure.store(enabled, std::memory_order_seq_cst);
}

void set_dump_memory_diagnostics_on_alloc_failure_kind(alloc_failure_kind kind) {
@@ -2268,8 +2272,11 @@ scoped_heap_profiling::scoped_heap_profiling() noexcept {
scoped_heap_profiling::~scoped_heap_profiling() {
}

-void enable_abort_on_allocation_failure() {
- seastar_logger.warn("Seastar compiled with default allocator, will not abort on bad_alloc");
+void set_abort_on_allocation_failure(bool enabled) {
+ if (enabled) {
+ seastar_logger.warn("Seastar compiled with default allocator, will not abort on bad_alloc");
+ }
+}
}

reclaimer::reclaimer(std::function<reclaiming_result ()> reclaim, reclaimer_scope) {
Reply all
Reply to author
Forward
0 new messages