Skip to content

Commit 3f2f9ea

Browse files
committed
Implement metadata allocation test for jemalloc
this test makes sure that jemalloc does not use memory provider to allocate metadata.
1 parent f43e36b commit 3f2f9ea

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/pools/jemalloc_pool.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,31 @@
88
#include "pool.hpp"
99
#include "poolFixtures.hpp"
1010

11+
using umf_test::test;
12+
using namespace umf_test;
13+
1114
auto defaultParams = umfOsMemoryProviderParamsDefault();
1215
INSTANTIATE_TEST_SUITE_P(jemallocPoolTest, umfPoolTest,
1316
::testing::Values(poolCreateExtParams{
1417
&UMF_JEMALLOC_POOL_OPS, nullptr,
1518
&UMF_OS_MEMORY_PROVIDER_OPS, &defaultParams}));
19+
20+
TEST_F(test, metadataNotAllocatedUsingProvider) {
21+
static constexpr size_t allocSize = 1024;
22+
static constexpr size_t numAllocs = 1024;
23+
24+
// set coarse grain allocations to PROT_NONE so that we can be sure
25+
// jemalloc does not touch any of the allocated memory
26+
auto params = umfOsMemoryProviderParamsDefault();
27+
params.protection = UMF_PROTECTION_NONE;
28+
29+
auto pool = poolCreateExtUnique({&UMF_JEMALLOC_POOL_OPS, nullptr,
30+
&UMF_OS_MEMORY_PROVIDER_OPS, &params});
31+
32+
std::vector<std::shared_ptr<void>> allocs;
33+
for (size_t i = 0; i < numAllocs; i++) {
34+
allocs.emplace_back(
35+
umfPoolMalloc(pool.get(), allocSize),
36+
[pool = pool.get()](void *ptr) { umfPoolFree(pool, ptr); });
37+
}
38+
}

0 commit comments

Comments
 (0)