diff options
author | Martin Leitner-Ankerl <martin.ankerl@gmail.com> | 2023-11-19 15:57:03 +0100 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2023-11-22 11:33:01 +0000 |
commit | bcc183cccefdc84a09e43965d6b88a8bec3a5446 (patch) | |
tree | 08f264194fb049b562137f15464d3e82cf017afe /src | |
parent | 7dda4991a875ca9bd9f79b3d52b12837ad7f92f1 (diff) |
pool: make sure PoolAllocator uses the correct alignment
This changes the PoolAllocator to default the alignment to the given type. This makes the code simpler, and most importantly
fixes a bug on ARM 32bit that caused OOM: The class CTxOut has a member CAmount which is an int64_t and on ARM 32bit int64_t
are 8 byte aligned which is larger than the pointer alignment of 4 bytes. So for CCoinsMap to be able to use the pool, we
need to use the alignment of the member instead of just alignof(void*).
Github-Pull: #28913
Rebased-From: ce881bf9fcb7c30bb1fafd6ce38844f4f829452a
Diffstat (limited to 'src')
-rw-r--r-- | src/bench/pool.cpp | 3 | ||||
-rw-r--r-- | src/coins.h | 3 | ||||
-rw-r--r-- | src/support/allocators/pool.h | 2 | ||||
-rw-r--r-- | src/test/pool_tests.cpp | 3 |
4 files changed, 4 insertions, 7 deletions
diff --git a/src/bench/pool.cpp b/src/bench/pool.cpp index b3e54d85a2..b2a5f8debf 100644 --- a/src/bench/pool.cpp +++ b/src/bench/pool.cpp @@ -37,8 +37,7 @@ static void PoolAllocator_StdUnorderedMapWithPoolResource(benchmark::Bench& benc std::hash<uint64_t>, std::equal_to<uint64_t>, PoolAllocator<std::pair<const uint64_t, uint64_t>, - sizeof(std::pair<const uint64_t, uint64_t>) + 4 * sizeof(void*), - alignof(void*)>>; + sizeof(std::pair<const uint64_t, uint64_t>) + 4 * sizeof(void*)>>; // make sure the resource supports large enough pools to hold the node. We do this by adding the size of a few pointers to it. auto pool_resource = Map::allocator_type::ResourceType(); diff --git a/src/coins.h b/src/coins.h index a6cbb03133..bbf9e3895f 100644 --- a/src/coins.h +++ b/src/coins.h @@ -145,8 +145,7 @@ using CCoinsMap = std::unordered_map<COutPoint, SaltedOutpointHasher, std::equal_to<COutPoint>, PoolAllocator<std::pair<const COutPoint, CCoinsCacheEntry>, - sizeof(std::pair<const COutPoint, CCoinsCacheEntry>) + sizeof(void*) * 4, - alignof(void*)>>; + sizeof(std::pair<const COutPoint, CCoinsCacheEntry>) + sizeof(void*) * 4>>; using CCoinsMapMemoryResource = CCoinsMap::allocator_type::ResourceType; diff --git a/src/support/allocators/pool.h b/src/support/allocators/pool.h index c8e70ebacf..873e260b65 100644 --- a/src/support/allocators/pool.h +++ b/src/support/allocators/pool.h @@ -272,7 +272,7 @@ public: /** * Forwards all allocations/deallocations to the PoolResource. */ -template <class T, std::size_t MAX_BLOCK_SIZE_BYTES, std::size_t ALIGN_BYTES> +template <class T, std::size_t MAX_BLOCK_SIZE_BYTES, std::size_t ALIGN_BYTES = alignof(T)> class PoolAllocator { PoolResource<MAX_BLOCK_SIZE_BYTES, ALIGN_BYTES>* m_resource; diff --git a/src/test/pool_tests.cpp b/src/test/pool_tests.cpp index 8a07e09a44..2663e088eb 100644 --- a/src/test/pool_tests.cpp +++ b/src/test/pool_tests.cpp @@ -163,8 +163,7 @@ BOOST_AUTO_TEST_CASE(memusage_test) std::hash<int>, std::equal_to<int>, PoolAllocator<std::pair<const int, int>, - sizeof(std::pair<const int, int>) + sizeof(void*) * 4, - alignof(void*)>>; + sizeof(std::pair<const int, int>) + sizeof(void*) * 4>>; auto resource = Map::allocator_type::ResourceType(1024); PoolResourceTester::CheckAllDataAccountedFor(resource); |