From 4ff1d731bd4ddff90fff6d3aeeb04101e4824468 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Tue, 19 Feb 2019 18:31:33 +0100 Subject: [PATCH] lsa: Fix spurios abort with --enable-abort-on-lsa-bad-alloc allocate_segment() can fail even though we're not out of memory, when it's invoked inside an allocating section with the cache region locked. That section may later succeed after retried after memory reclamation. We should ignore bad_alloc thrown inside allocating section body and fail only when the whole section fails. Fixes #2924 Message-Id: <1550597493-22500-1-git-send-email-tgrabiec@scylladb.com> (cherry picked from commit dafe22dd832078d3522ad7991071c10fa4fabf05) --- utils/logalloc.cc | 15 ++++++++++----- utils/logalloc.hh | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/utils/logalloc.cc b/utils/logalloc.cc index 728d67356f..7ffaa55758 100644 --- a/utils/logalloc.cc +++ b/utils/logalloc.cc @@ -667,6 +667,7 @@ segment* segment_pool::allocate_segment(size_t reserve, size_t reclamation_step) return seg; } if (can_allocate_more_memory(segment::size)) { + memory::disable_abort_on_alloc_failure_temporarily dfg; auto p = aligned_alloc(segment::size, segment::size); if (!p) { continue; @@ -677,10 +678,6 @@ segment* segment_pool::allocate_segment(size_t reserve, size_t reclamation_step) return seg; } } while (shard_tracker().get_impl().compact_and_evict(reclamation_step * segment::size)); - if (shard_tracker().should_abort_on_bad_alloc()) { - llogger.error("Aborting due to segment allocation failure"); - abort(); - } return nullptr; } @@ -2286,7 +2283,15 @@ void allocating_section::on_alloc_failure(logalloc::region& r) { _std_reserve *= 2; // FIXME: decay? llogger.debug("Standard allocator failure, increasing head-room in section {} to {} [B]", this, _std_reserve); } - reserve(); + try { + reserve(); + } catch (const std::bad_alloc&) { + if (shard_tracker().should_abort_on_bad_alloc()) { + llogger.error("Aborting due to allocation failure"); + abort(); + } + throw; + } } #else diff --git a/utils/logalloc.hh b/utils/logalloc.hh index 43261d941b..58c253266d 100644 --- a/utils/logalloc.hh +++ b/utils/logalloc.hh @@ -710,6 +710,7 @@ public: while (true) { try { logalloc::reclaim_lock _(r); + memory::disable_abort_on_alloc_failure_temporarily dfg; return fn(); } catch (const std::bad_alloc&) { on_alloc_failure(r);