Skip to content

Commit bebb567

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 bebb567

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/pools/jemalloc_pool.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,35 @@
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+
// this test makes sure that jemalloc does not use
21+
// memory provider to allocate metadata (and hence
22+
// is suitable for cases where memory is not accessible
23+
// on the host)
24+
TEST_F(test, metadataNotAllocatedUsingProvider) {
25+
static constexpr size_t allocSize = 1024;
26+
static constexpr size_t numAllocs = 1024;
27+
28+
// set coarse grain allocations to PROT_NONE so that we can be sure
29+
// jemalloc does not touch any of the allocated memory
30+
auto params = umfOsMemoryProviderParamsDefault();
31+
params.protection = UMF_PROTECTION_NONE;
32+
33+
auto pool = poolCreateExtUnique({&UMF_JEMALLOC_POOL_OPS, nullptr,
34+
&UMF_OS_MEMORY_PROVIDER_OPS, &params});
35+
36+
std::vector<std::shared_ptr<void>> allocs;
37+
for (size_t i = 0; i < numAllocs; i++) {
38+
allocs.emplace_back(
39+
umfPoolMalloc(pool.get(), allocSize),
40+
[pool = pool.get()](void *ptr) { umfPoolFree(pool, ptr); });
41+
}
42+
}

0 commit comments

Comments
 (0)