mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-12 19:02:12 +00:00
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 dafe22dd83)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user