Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cpp/src/arrow/buffer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1001,8 +1001,14 @@ TYPED_TEST(TypedTestBuffer, ResizeOOM) {
TypeParam buf;
ASSERT_OK_AND_ASSIGN(buf, AllocateResizableBuffer(0));
ASSERT_OK(buf->Resize(100));
if (default_memory_pool()->backend_name() == "mimalloc") {
GTEST_SKIP() << "Skip synthetic OOM for mimalloc to avoid allocator fatal path";
}
int64_t to_alloc = std::min<uint64_t>(std::numeric_limits<int64_t>::max(),
std::numeric_limits<size_t>::max());
// Clamp to a still-impossible size so the allocator raises OutOfMemory
constexpr int64_t kHugeAlloc = static_cast<int64_t>(1) << 48; // 256 TB
to_alloc = std::min(to_alloc, kHugeAlloc);
// subtract 63 to prevent overflow after the size is aligned
to_alloc -= 63;
ASSERT_RAISES(OutOfMemory, buf->Resize(to_alloc));
Expand Down
9 changes: 9 additions & 0 deletions cpp/src/arrow/memory_pool_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <cstddef>
#include <cstdint>
#include <limits>
#include <string>

#include <gtest/gtest.h>

Expand Down Expand Up @@ -56,10 +57,18 @@ class TestMemoryPoolBase : public ::testing::Test {

void TestOOM() {
auto pool = memory_pool();
const std::string backend = pool->backend_name();
if (backend == "mimalloc") {
GTEST_SKIP() << "Skip synthetic OOM for mimalloc to avoid allocator fatal path";
}

uint8_t* data;
int64_t max_alloc = std::min<uint64_t>(std::numeric_limits<int64_t>::max(),
std::numeric_limits<size_t>::max());
// On big-memory systems/allocators this can trigger fatal paths before we see
// OutOfMemory. Clamp to a still-impossible size that will fail reliably.
constexpr int64_t kHugeAlloc = static_cast<int64_t>(1) << 48; // 256 TB
max_alloc = std::min(max_alloc, kHugeAlloc);
// subtract 63 to prevent overflow after the size is aligned
for (int64_t to_alloc : {max_alloc, max_alloc - 63, max_alloc - 127}) {
ASSERT_RAISES(OutOfMemory, pool->Allocate(to_alloc, &data));
Expand Down