Skip to content

Commit 326eabd

Browse files
committed
Remove the disable_provider_free parameter of jemalloc pool
Remove the disable_provider_free parameter of jemalloc pool. Replace it with the Coarse provider in the example. Fixes: #904 Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 3bcaffc commit 326eabd

File tree

5 files changed

+10
-188
lines changed

5 files changed

+10
-188
lines changed

README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,6 @@ Additionally, required for tests:
186186
A memory provider that provides memory from a device DAX (a character device file /dev/daxX.Y).
187187
It can be used when large memory mappings are needed.
188188

189-
The DevDax memory provider does not support the free operation
190-
(`umfMemoryProviderFree()` always returns `UMF_RESULT_ERROR_NOT_SUPPORTED`),
191-
so it should be used with a pool manager that will take over
192-
the managing of the provided memory - for example the jemalloc pool
193-
with the `disable_provider_free` parameter set to true.
194-
195189
##### Requirements
196190

197191
1) Linux OS
@@ -201,12 +195,6 @@ with the `disable_provider_free` parameter set to true.
201195

202196
A memory provider that provides memory by mapping a regular, extendable file.
203197

204-
The file memory provider does not support the free operation
205-
(`umfMemoryProviderFree()` always returns `UMF_RESULT_ERROR_NOT_SUPPORTED`),
206-
so it should be used with a pool manager that will take over
207-
the managing of the provided memory - for example the jemalloc pool
208-
with the `disable_provider_free` parameter set to true.
209-
210198
IPC API requires the `UMF_MEM_MAP_SHARED` memory `visibility` mode
211199
(`UMF_RESULT_ERROR_INVALID_ARGUMENT` is returned otherwise).
212200

examples/dram_and_fsdax/dram_and_fsdax.c

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -61,41 +61,14 @@ static umf_memory_pool_handle_t create_fsdax_pool(const char *path) {
6161
}
6262

6363
// Create an FSDAX memory pool
64-
//
65-
// The file memory provider does not support the free operation
66-
// (`umfMemoryProviderFree()` always returns `UMF_RESULT_ERROR_NOT_SUPPORTED`),
67-
// so it should be used with a pool manager that will take over
68-
// the managing of the provided memory - for example the jemalloc pool
69-
// with the `disable_provider_free` parameter set to true.
70-
umf_jemalloc_pool_params_handle_t pool_params;
71-
umf_result = umfJemallocPoolParamsCreate(&pool_params);
72-
if (umf_result != UMF_RESULT_SUCCESS) {
73-
fprintf(stderr, "Failed to create jemalloc params!\n");
74-
umfMemoryProviderDestroy(provider_fsdax);
75-
return NULL;
76-
}
77-
umf_result = umfJemallocPoolParamsSetKeepAllMemory(pool_params, true);
78-
if (umf_result != UMF_RESULT_SUCCESS) {
79-
fprintf(stderr, "Failed to set KeepAllMemory!\n");
80-
umfMemoryProviderDestroy(provider_fsdax);
81-
return NULL;
82-
}
83-
84-
// Create an FSDAX memory pool
85-
umf_result =
86-
umfPoolCreate(umfJemallocPoolOps(), provider_fsdax, pool_params,
87-
UMF_POOL_CREATE_FLAG_OWN_PROVIDER, &pool_fsdax);
64+
umf_result = umfPoolCreate(umfJemallocPoolOps(), provider_fsdax, NULL,
65+
UMF_POOL_CREATE_FLAG_OWN_PROVIDER, &pool_fsdax);
8866
if (umf_result != UMF_RESULT_SUCCESS) {
8967
fprintf(stderr, "Failed to create an FSDAX memory pool!\n");
9068
umfMemoryProviderDestroy(provider_fsdax);
9169
return NULL;
9270
}
9371

94-
umf_result = umfJemallocPoolParamsDestroy(pool_params);
95-
if (umf_result != UMF_RESULT_SUCCESS) {
96-
fprintf(stderr, "Failed to destroy jemalloc params!\n");
97-
}
98-
9972
return pool_fsdax;
10073
}
10174

include/umf/pools/pool_jemalloc.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,8 @@
1414
extern "C" {
1515
#endif
1616

17-
#include <stdbool.h>
1817
#include <umf/memory_pool_ops.h>
1918

20-
struct umf_jemalloc_pool_params_t;
21-
22-
/// @brief handle to the parameters of the jemalloc pool.
23-
typedef struct umf_jemalloc_pool_params_t *umf_jemalloc_pool_params_handle_t;
24-
25-
/// @brief Create a struct to store parameters of jemalloc pool.
26-
/// @param hParams [out] handle to the newly created parameters struct.
27-
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
28-
umf_result_t
29-
umfJemallocPoolParamsCreate(umf_jemalloc_pool_params_handle_t *hParams);
30-
31-
/// @brief Destroy parameters struct.
32-
/// @param hParams handle to the parameters of the jemalloc pool.
33-
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
34-
umf_result_t
35-
umfJemallocPoolParamsDestroy(umf_jemalloc_pool_params_handle_t hParams);
36-
37-
/// @brief Set if \p umfMemoryProviderFree() should never be called.
38-
/// @param hParams handle to the parameters of the jemalloc pool.
39-
/// @param keepAllMemory \p true if the jemalloc pool should not call
40-
/// \p umfMemoryProviderFree, \p false otherwise.
41-
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
42-
umf_result_t
43-
umfJemallocPoolParamsSetKeepAllMemory(umf_jemalloc_pool_params_handle_t hParams,
44-
bool keepAllMemory);
45-
4619
umf_memory_pool_ops_t *umfJemallocPoolOps(void);
4720

4821
#ifdef __cplusplus

src/pool/pool_jemalloc.c

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,8 @@
3737
typedef struct jemalloc_memory_pool_t {
3838
umf_memory_provider_handle_t provider;
3939
unsigned int arena_index; // index of jemalloc arena
40-
// set to true if umfMemoryProviderFree() should never be called
41-
bool disable_provider_free;
4240
} jemalloc_memory_pool_t;
4341

44-
// Configuration of Jemalloc Pool
45-
typedef struct umf_jemalloc_pool_params_t {
46-
/// Set to true if umfMemoryProviderFree() should never be called.
47-
bool disable_provider_free;
48-
} umf_jemalloc_pool_params_t;
49-
5042
static __TLS umf_result_t TLS_last_allocation_error;
5143

5244
static jemalloc_memory_pool_t *pool_by_arena_index[MALLCTL_ARENAS_ALL];
@@ -59,52 +51,6 @@ static jemalloc_memory_pool_t *get_pool_by_arena_index(unsigned arena_ind) {
5951
return pool_by_arena_index[arena_ind];
6052
}
6153

62-
umf_result_t
63-
umfJemallocPoolParamsCreate(umf_jemalloc_pool_params_handle_t *hParams) {
64-
if (!hParams) {
65-
LOG_ERR("jemalloc pool params handle is NULL");
66-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
67-
}
68-
69-
umf_jemalloc_pool_params_t *params_data =
70-
umf_ba_global_alloc(sizeof(*params_data));
71-
if (!params_data) {
72-
LOG_ERR("cannot allocate memory for jemalloc poolparams");
73-
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
74-
}
75-
76-
params_data->disable_provider_free = false;
77-
78-
*hParams = (umf_jemalloc_pool_params_handle_t)params_data;
79-
80-
return UMF_RESULT_SUCCESS;
81-
}
82-
83-
umf_result_t
84-
umfJemallocPoolParamsDestroy(umf_jemalloc_pool_params_handle_t hParams) {
85-
if (!hParams) {
86-
LOG_ERR("jemalloc pool params handle is NULL");
87-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
88-
}
89-
90-
umf_ba_global_free(hParams);
91-
92-
return UMF_RESULT_SUCCESS;
93-
}
94-
95-
umf_result_t
96-
umfJemallocPoolParamsSetKeepAllMemory(umf_jemalloc_pool_params_handle_t hParams,
97-
bool keepAllMemory) {
98-
if (!hParams) {
99-
LOG_ERR("jemalloc pool params handle is NULL");
100-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
101-
}
102-
103-
hParams->disable_provider_free = keepAllMemory;
104-
105-
return UMF_RESULT_SUCCESS;
106-
}
107-
10854
// arena_extent_alloc - an extent allocation function conforms to the extent_alloc_t type and upon
10955
// success returns a pointer to size bytes of mapped memory on behalf of arena arena_ind such that
11056
// the extent's base address is a multiple of alignment, as well as setting *zero to indicate
@@ -134,9 +80,7 @@ static void *arena_extent_alloc(extent_hooks_t *extent_hooks, void *new_addr,
13480
}
13581

13682
if (new_addr != NULL && ptr != new_addr) {
137-
if (!pool->disable_provider_free) {
138-
umfMemoryProviderFree(pool->provider, ptr, size);
139-
}
83+
umfMemoryProviderFree(pool->provider, ptr, size);
14084
return NULL;
14185
}
14286

@@ -170,10 +114,6 @@ static void arena_extent_destroy(extent_hooks_t *extent_hooks, void *addr,
170114

171115
jemalloc_memory_pool_t *pool = get_pool_by_arena_index(arena_ind);
172116

173-
if (pool->disable_provider_free) {
174-
return;
175-
}
176-
177117
umf_result_t ret;
178118
ret = umfMemoryProviderFree(pool->provider, addr, size);
179119
if (ret != UMF_RESULT_SUCCESS) {
@@ -196,10 +136,6 @@ static bool arena_extent_dalloc(extent_hooks_t *extent_hooks, void *addr,
196136

197137
jemalloc_memory_pool_t *pool = get_pool_by_arena_index(arena_ind);
198138

199-
if (pool->disable_provider_free) {
200-
return true; // opt-out from deallocation
201-
}
202-
203139
umf_result_t ret;
204140
ret = umfMemoryProviderFree(pool->provider, addr, size);
205141
if (ret != UMF_RESULT_SUCCESS) {
@@ -452,9 +388,7 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
452388
void *params, void **out_pool) {
453389
assert(provider);
454390
assert(out_pool);
455-
456-
umf_jemalloc_pool_params_handle_t je_params =
457-
(umf_jemalloc_pool_params_handle_t)params;
391+
(void)params; // unused
458392

459393
extent_hooks_t *pHooks = &arena_extent_hooks;
460394
size_t unsigned_size = sizeof(unsigned);
@@ -468,12 +402,6 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
468402

469403
pool->provider = provider;
470404

471-
if (je_params) {
472-
pool->disable_provider_free = je_params->disable_provider_free;
473-
} else {
474-
pool->disable_provider_free = false;
475-
}
476-
477405
unsigned arena_index;
478406
err = je_mallctl("arenas.create", (void *)&arena_index, &unsigned_size,
479407
NULL, 0);

test/pools/jemalloc_pool.cpp

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -71,31 +71,20 @@ struct umfJemallocPoolParamsTest
7171
static constexpr umf_memory_provider_ops_t VALIDATOR_PROVIDER_OPS =
7272
umf::providerMakeCOps<provider_validator, validation_params_t>();
7373

74-
umfJemallocPoolParamsTest() : expected_params{false}, params(nullptr) {}
75-
void SetUp() override {
76-
test::SetUp();
77-
expected_params.keep_all_memory = this->GetParam();
78-
umf_result_t ret = umfJemallocPoolParamsCreate(&params);
79-
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
80-
ret = umfJemallocPoolParamsSetKeepAllMemory(
81-
params, expected_params.keep_all_memory);
82-
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
83-
}
74+
umfJemallocPoolParamsTest() {}
75+
void SetUp() override { test::SetUp(); }
8476

85-
void TearDown() override {
86-
umfJemallocPoolParamsDestroy(params);
87-
test::TearDown();
88-
}
77+
void TearDown() override { test::TearDown(); }
8978

9079
umf::pool_unique_handle_t makePool() {
9180
umf_memory_provider_handle_t hProvider = nullptr;
9281
umf_memory_pool_handle_t hPool = nullptr;
9382

94-
auto ret = umfMemoryProviderCreate(&VALIDATOR_PROVIDER_OPS,
95-
&expected_params, &hProvider);
83+
auto ret = umfMemoryProviderCreate(&VALIDATOR_PROVIDER_OPS, nullptr,
84+
&hProvider);
9685
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
9786

98-
ret = umfPoolCreate(umfJemallocPoolOps(), hProvider, params,
87+
ret = umfPoolCreate(umfJemallocPoolOps(), hProvider, nullptr,
9988
UMF_POOL_CREATE_FLAG_OWN_PROVIDER, &hPool);
10089
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
10190

@@ -120,40 +109,11 @@ struct umfJemallocPoolParamsTest
120109
auto ret = umfPoolFree(pool.get(), ptrs[i]);
121110
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
122111
}
123-
124-
// Now pool can call free during pool destruction
125-
expected_params.keep_all_memory = false;
126112
}
127-
128-
validation_params_t expected_params;
129-
umf_jemalloc_pool_params_handle_t params;
130113
};
131114

132115
TEST_P(umfJemallocPoolParamsTest, allocFree) { allocFreeFlow(); }
133116

134-
TEST_P(umfJemallocPoolParamsTest, updateParams) {
135-
expected_params.keep_all_memory = !expected_params.keep_all_memory;
136-
umf_result_t ret = umfJemallocPoolParamsSetKeepAllMemory(
137-
params, expected_params.keep_all_memory);
138-
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
139-
140-
allocFreeFlow();
141-
}
142-
143-
TEST_P(umfJemallocPoolParamsTest, invalidParams) {
144-
umf_result_t ret = umfJemallocPoolParamsCreate(nullptr);
145-
ASSERT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
146-
147-
ret = umfJemallocPoolParamsSetKeepAllMemory(nullptr, true);
148-
ASSERT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
149-
150-
ret = umfJemallocPoolParamsSetKeepAllMemory(nullptr, false);
151-
ASSERT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
152-
153-
ret = umfJemallocPoolParamsDestroy(nullptr);
154-
ASSERT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
155-
}
156-
157117
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(umfJemallocPoolParamsTest);
158118

159119
/* TODO: enable this test after the issue #903 is fixed.

0 commit comments

Comments
 (0)