Skip to content

Commit 2f1aa28

Browse files
committed
Remove the disable_provider_free parameter of jemalloc pool
Remove the disable_provider_free parameter of jemalloc pool. and the umfJemallocPoolParamsSetKeepAllMemory() API. Fixes: #904 Signed-off-by: Lukasz Dorau <[email protected]>
1 parent fb53918 commit 2f1aa28

File tree

7 files changed

+11
-116
lines changed

7 files changed

+11
-116
lines changed

README.md

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

212-
The DevDax memory provider does not support the free operation
213-
(`umfMemoryProviderFree()` always returns `UMF_RESULT_ERROR_NOT_SUPPORTED`),
214-
so it should be used with a pool manager that will take over
215-
the managing of the provided memory - for example the jemalloc pool
216-
with the `disable_provider_free` parameter set to true.
217-
218212
##### Requirements
219213

220214
1) Linux OS
@@ -224,12 +218,6 @@ with the `disable_provider_free` parameter set to true.
224218

225219
A memory provider that provides memory by mapping a regular, extendable file.
226220

227-
The file memory provider does not support the free operation
228-
(`umfMemoryProviderFree()` always returns `UMF_RESULT_ERROR_NOT_SUPPORTED`),
229-
so it should be used with a pool manager that will take over
230-
the managing of the provided memory - for example the jemalloc pool
231-
with the `disable_provider_free` parameter set to true.
232-
233221
IPC API requires the `UMF_MEM_MAP_SHARED` memory `visibility` mode
234222
(`UMF_RESULT_ERROR_INVALID_ARGUMENT` is returned otherwise).
235223

examples/dram_and_fsdax/dram_and_fsdax.c

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

8080
// Create an FSDAX memory pool
81-
//
82-
// The file memory provider does not support the free operation
83-
// (`umfMemoryProviderFree()` always returns `UMF_RESULT_ERROR_NOT_SUPPORTED`),
84-
// so it should be used with a pool manager that will take over
85-
// the managing of the provided memory - for example the jemalloc pool
86-
// with the `disable_provider_free` parameter set to true.
87-
umf_jemalloc_pool_params_handle_t pool_params;
88-
umf_result = umfJemallocPoolParamsCreate(&pool_params);
89-
if (umf_result != UMF_RESULT_SUCCESS) {
90-
fprintf(stderr, "Failed to create jemalloc params!\n");
91-
umfMemoryProviderDestroy(provider_fsdax);
92-
return NULL;
93-
}
94-
umf_result = umfJemallocPoolParamsSetKeepAllMemory(pool_params, true);
95-
if (umf_result != UMF_RESULT_SUCCESS) {
96-
fprintf(stderr, "Failed to set KeepAllMemory!\n");
97-
umfMemoryProviderDestroy(provider_fsdax);
98-
return NULL;
99-
}
100-
101-
// Create an FSDAX memory pool
102-
umf_result =
103-
umfPoolCreate(umfJemallocPoolOps(), provider_fsdax, pool_params,
104-
UMF_POOL_CREATE_FLAG_OWN_PROVIDER, &pool_fsdax);
81+
umf_result = umfPoolCreate(umfJemallocPoolOps(), provider_fsdax, NULL,
82+
UMF_POOL_CREATE_FLAG_OWN_PROVIDER, &pool_fsdax);
10583
if (umf_result != UMF_RESULT_SUCCESS) {
10684
fprintf(stderr, "Failed to create an FSDAX memory pool!\n");
10785
umfMemoryProviderDestroy(provider_fsdax);
10886
return NULL;
10987
}
11088

111-
umf_result = umfJemallocPoolParamsDestroy(pool_params);
112-
if (umf_result != UMF_RESULT_SUCCESS) {
113-
fprintf(stderr, "Failed to destroy jemalloc params!\n");
114-
}
115-
11689
return pool_fsdax;
11790
}
11891

include/umf/pools/pool_jemalloc.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,6 @@ umfJemallocPoolParamsCreate(umf_jemalloc_pool_params_handle_t *hParams);
3434
umf_result_t
3535
umfJemallocPoolParamsDestroy(umf_jemalloc_pool_params_handle_t hParams);
3636

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-
4637
umf_memory_pool_ops_t *umfJemallocPoolOps(void);
4738

4839
#ifdef __cplusplus

src/libumf.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ EXPORTS
3939
umfJemallocPoolOps
4040
umfJemallocPoolParamsCreate
4141
umfJemallocPoolParamsDestroy
42-
umfJemallocPoolParamsSetKeepAllMemory
4342
umfLevelZeroMemoryProviderOps
4443
umfLevelZeroMemoryProviderParamsCreate
4544
umfLevelZeroMemoryProviderParamsDestroy

src/libumf.map

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ UMF_1.0 {
3333
umfJemallocPoolOps;
3434
umfJemallocPoolParamsCreate;
3535
umfJemallocPoolParamsDestroy;
36-
umfJemallocPoolParamsSetKeepAllMemory;
3736
umfLevelZeroMemoryProviderOps;
3837
umfLevelZeroMemoryProviderParamsCreate;
3938
umfLevelZeroMemoryProviderParamsDestroy;

src/pool/pool_jemalloc.c

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ umfJemallocPoolParamsDestroy(umf_jemalloc_pool_params_handle_t hParams) {
3636
return UMF_RESULT_ERROR_NOT_SUPPORTED;
3737
}
3838

39-
umf_result_t
40-
umfJemallocPoolParamsSetKeepAllMemory(umf_jemalloc_pool_params_handle_t hParams,
41-
bool keepAllMemory) {
42-
(void)hParams; // unused
43-
(void)keepAllMemory; // unused
44-
return UMF_RESULT_ERROR_NOT_SUPPORTED;
45-
}
46-
4739
#else
4840

4941
#include <jemalloc/jemalloc.h>
@@ -53,14 +45,11 @@ umfJemallocPoolParamsSetKeepAllMemory(umf_jemalloc_pool_params_handle_t hParams,
5345
typedef struct jemalloc_memory_pool_t {
5446
umf_memory_provider_handle_t provider;
5547
unsigned int arena_index; // index of jemalloc arena
56-
// set to true if umfMemoryProviderFree() should never be called
57-
bool disable_provider_free;
5848
} jemalloc_memory_pool_t;
5949

6050
// Configuration of Jemalloc Pool
6151
typedef struct umf_jemalloc_pool_params_t {
62-
/// Set to true if umfMemoryProviderFree() should never be called.
63-
bool disable_provider_free;
52+
int placeholder; // just a placeholder
6453
} umf_jemalloc_pool_params_t;
6554

6655
static __TLS umf_result_t TLS_last_allocation_error;
@@ -89,7 +78,7 @@ umfJemallocPoolParamsCreate(umf_jemalloc_pool_params_handle_t *hParams) {
8978
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
9079
}
9180

92-
params_data->disable_provider_free = false;
81+
params_data->placeholder = 1;
9382

9483
*hParams = (umf_jemalloc_pool_params_handle_t)params_data;
9584

@@ -108,19 +97,6 @@ umfJemallocPoolParamsDestroy(umf_jemalloc_pool_params_handle_t hParams) {
10897
return UMF_RESULT_SUCCESS;
10998
}
11099

111-
umf_result_t
112-
umfJemallocPoolParamsSetKeepAllMemory(umf_jemalloc_pool_params_handle_t hParams,
113-
bool keepAllMemory) {
114-
if (!hParams) {
115-
LOG_ERR("jemalloc pool params handle is NULL");
116-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
117-
}
118-
119-
hParams->disable_provider_free = keepAllMemory;
120-
121-
return UMF_RESULT_SUCCESS;
122-
}
123-
124100
// arena_extent_alloc - an extent allocation function conforms to the extent_alloc_t type and upon
125101
// success returns a pointer to size bytes of mapped memory on behalf of arena arena_ind such that
126102
// the extent's base address is a multiple of alignment, as well as setting *zero to indicate
@@ -150,9 +126,7 @@ static void *arena_extent_alloc(extent_hooks_t *extent_hooks, void *new_addr,
150126
}
151127

152128
if (new_addr != NULL && ptr != new_addr) {
153-
if (!pool->disable_provider_free) {
154-
umfMemoryProviderFree(pool->provider, ptr, size);
155-
}
129+
umfMemoryProviderFree(pool->provider, ptr, size);
156130
return NULL;
157131
}
158132

@@ -186,10 +160,6 @@ static void arena_extent_destroy(extent_hooks_t *extent_hooks, void *addr,
186160

187161
jemalloc_memory_pool_t *pool = get_pool_by_arena_index(arena_ind);
188162

189-
if (pool->disable_provider_free) {
190-
return;
191-
}
192-
193163
umf_result_t ret;
194164
ret = umfMemoryProviderFree(pool->provider, addr, size);
195165
if (ret != UMF_RESULT_SUCCESS) {
@@ -212,10 +182,6 @@ static bool arena_extent_dalloc(extent_hooks_t *extent_hooks, void *addr,
212182

213183
jemalloc_memory_pool_t *pool = get_pool_by_arena_index(arena_ind);
214184

215-
if (pool->disable_provider_free) {
216-
return true; // opt-out from deallocation
217-
}
218-
219185
umf_result_t ret;
220186
ret = umfMemoryProviderFree(pool->provider, addr, size);
221187
if (ret != UMF_RESULT_SUCCESS) {
@@ -466,12 +432,10 @@ static void *op_aligned_alloc(void *pool, size_t size, size_t alignment) {
466432

467433
static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
468434
void *params, void **out_pool) {
435+
(void)params; // unused
469436
assert(provider);
470437
assert(out_pool);
471438

472-
umf_jemalloc_pool_params_handle_t je_params =
473-
(umf_jemalloc_pool_params_handle_t)params;
474-
475439
extent_hooks_t *pHooks = &arena_extent_hooks;
476440
size_t unsigned_size = sizeof(unsigned);
477441
int err;
@@ -484,12 +448,6 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
484448

485449
pool->provider = provider;
486450

487-
if (je_params) {
488-
pool->disable_provider_free = je_params->disable_provider_free;
489-
} else {
490-
pool->disable_provider_free = false;
491-
}
492-
493451
unsigned arena_index;
494452
err = je_mallctl("arenas.create", (void *)&arena_index, &unsigned_size,
495453
NULL, 0);

test/pools/jemalloc_pool.cpp

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct umfJemallocPoolParamsTest
6969
::testing::WithParamInterface<jemallocPoolParams> {
7070

7171
struct validation_params_t {
72-
bool keep_all_memory;
72+
bool placeholder;
7373
};
7474

7575
struct provider_validator : public umf_test::provider_ba_global {
@@ -81,7 +81,7 @@ struct umfJemallocPoolParamsTest
8181
return UMF_RESULT_SUCCESS;
8282
}
8383
umf_result_t free(void *ptr, size_t size) {
84-
EXPECT_EQ(expected_params->keep_all_memory, false);
84+
EXPECT_EQ(expected_params->placeholder, false);
8585
return base_provider::free(ptr, size);
8686
}
8787

@@ -94,12 +94,9 @@ struct umfJemallocPoolParamsTest
9494
umfJemallocPoolParamsTest() : expected_params{false}, params(nullptr) {}
9595
void SetUp() override {
9696
test::SetUp();
97-
expected_params.keep_all_memory = this->GetParam();
97+
expected_params.placeholder = this->GetParam();
9898
umf_result_t ret = umfJemallocPoolParamsCreate(&params);
9999
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
100-
ret = umfJemallocPoolParamsSetKeepAllMemory(
101-
params, expected_params.keep_all_memory);
102-
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
103100
}
104101

105102
void TearDown() override {
@@ -142,7 +139,7 @@ struct umfJemallocPoolParamsTest
142139
}
143140

144141
// Now pool can call free during pool destruction
145-
expected_params.keep_all_memory = false;
142+
expected_params.placeholder = false;
146143
}
147144

148145
validation_params_t expected_params;
@@ -152,24 +149,14 @@ struct umfJemallocPoolParamsTest
152149
TEST_P(umfJemallocPoolParamsTest, allocFree) { allocFreeFlow(); }
153150

154151
TEST_P(umfJemallocPoolParamsTest, updateParams) {
155-
expected_params.keep_all_memory = !expected_params.keep_all_memory;
156-
umf_result_t ret = umfJemallocPoolParamsSetKeepAllMemory(
157-
params, expected_params.keep_all_memory);
158-
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
159-
152+
expected_params.placeholder = !expected_params.placeholder;
160153
allocFreeFlow();
161154
}
162155

163156
TEST_P(umfJemallocPoolParamsTest, invalidParams) {
164157
umf_result_t ret = umfJemallocPoolParamsCreate(nullptr);
165158
ASSERT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
166159

167-
ret = umfJemallocPoolParamsSetKeepAllMemory(nullptr, true);
168-
ASSERT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
169-
170-
ret = umfJemallocPoolParamsSetKeepAllMemory(nullptr, false);
171-
ASSERT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
172-
173160
ret = umfJemallocPoolParamsDestroy(nullptr);
174161
ASSERT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
175162
}

0 commit comments

Comments
 (0)