Skip to content

Commit 109f4b2

Browse files
Merge pull request #911 from ldorau/Remove_the_disable_provider_free_parameter_of_jemalloc_pool
Remove the disable provider free parameter of jemalloc pool
2 parents 5b3d7b6 + 4394ed7 commit 109f4b2

File tree

7 files changed

+4
-287
lines changed

7 files changed

+4
-287
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 & 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/libumf.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ EXPORTS
3535
umfGetIPCHandle
3636
umfGetLastFailedMemoryProvider
3737
umfJemallocPoolOps
38-
umfJemallocPoolParamsCreate
39-
umfJemallocPoolParamsDestroy
40-
umfJemallocPoolParamsSetKeepAllMemory
4138
umfLevelZeroMemoryProviderOps
4239
umfLevelZeroMemoryProviderParamsCreate
4340
umfLevelZeroMemoryProviderParamsDestroy

src/libumf.map

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ UMF_1.0 {
2929
umfGetIPCHandle;
3030
umfGetLastFailedMemoryProvider;
3131
umfJemallocPoolOps;
32-
umfJemallocPoolParamsCreate;
33-
umfJemallocPoolParamsDestroy;
34-
umfJemallocPoolParamsSetKeepAllMemory;
3532
umfLevelZeroMemoryProviderOps;
3633
umfLevelZeroMemoryProviderParamsCreate;
3734
umfLevelZeroMemoryProviderParamsDestroy;

src/pool/pool_jemalloc.c

Lines changed: 2 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,6 @@
2424

2525
umf_memory_pool_ops_t *umfJemallocPoolOps(void) { return NULL; }
2626

27-
umf_result_t
28-
umfJemallocPoolParamsCreate(umf_jemalloc_pool_params_handle_t *hParams) {
29-
(void)hParams; // unused
30-
return UMF_RESULT_ERROR_NOT_SUPPORTED;
31-
}
32-
33-
umf_result_t
34-
umfJemallocPoolParamsDestroy(umf_jemalloc_pool_params_handle_t hParams) {
35-
(void)hParams; // unused
36-
return UMF_RESULT_ERROR_NOT_SUPPORTED;
37-
}
38-
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-
4727
#else
4828

4929
#include <jemalloc/jemalloc.h>
@@ -53,16 +33,8 @@ umfJemallocPoolParamsSetKeepAllMemory(umf_jemalloc_pool_params_handle_t hParams,
5333
typedef struct jemalloc_memory_pool_t {
5434
umf_memory_provider_handle_t provider;
5535
unsigned int arena_index; // index of jemalloc arena
56-
// set to true if umfMemoryProviderFree() should never be called
57-
bool disable_provider_free;
5836
} jemalloc_memory_pool_t;
5937

60-
// Configuration of Jemalloc Pool
61-
typedef struct umf_jemalloc_pool_params_t {
62-
/// Set to true if umfMemoryProviderFree() should never be called.
63-
bool disable_provider_free;
64-
} umf_jemalloc_pool_params_t;
65-
6638
static __TLS umf_result_t TLS_last_allocation_error;
6739

6840
static jemalloc_memory_pool_t *pool_by_arena_index[MALLCTL_ARENAS_ALL];
@@ -75,52 +47,6 @@ static jemalloc_memory_pool_t *get_pool_by_arena_index(unsigned arena_ind) {
7547
return pool_by_arena_index[arena_ind];
7648
}
7749

78-
umf_result_t
79-
umfJemallocPoolParamsCreate(umf_jemalloc_pool_params_handle_t *hParams) {
80-
if (!hParams) {
81-
LOG_ERR("jemalloc pool params handle is NULL");
82-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
83-
}
84-
85-
umf_jemalloc_pool_params_t *params_data =
86-
umf_ba_global_alloc(sizeof(*params_data));
87-
if (!params_data) {
88-
LOG_ERR("cannot allocate memory for jemalloc poolparams");
89-
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
90-
}
91-
92-
params_data->disable_provider_free = false;
93-
94-
*hParams = (umf_jemalloc_pool_params_handle_t)params_data;
95-
96-
return UMF_RESULT_SUCCESS;
97-
}
98-
99-
umf_result_t
100-
umfJemallocPoolParamsDestroy(umf_jemalloc_pool_params_handle_t hParams) {
101-
if (!hParams) {
102-
LOG_ERR("jemalloc pool params handle is NULL");
103-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
104-
}
105-
106-
umf_ba_global_free(hParams);
107-
108-
return UMF_RESULT_SUCCESS;
109-
}
110-
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-
12450
// arena_extent_alloc - an extent allocation function conforms to the extent_alloc_t type and upon
12551
// success returns a pointer to size bytes of mapped memory on behalf of arena arena_ind such that
12652
// the extent's base address is a multiple of alignment, as well as setting *zero to indicate
@@ -150,9 +76,7 @@ static void *arena_extent_alloc(extent_hooks_t *extent_hooks, void *new_addr,
15076
}
15177

15278
if (new_addr != NULL && ptr != new_addr) {
153-
if (!pool->disable_provider_free) {
154-
umfMemoryProviderFree(pool->provider, ptr, size);
155-
}
79+
umfMemoryProviderFree(pool->provider, ptr, size);
15680
return NULL;
15781
}
15882

@@ -186,10 +110,6 @@ static void arena_extent_destroy(extent_hooks_t *extent_hooks, void *addr,
186110

187111
jemalloc_memory_pool_t *pool = get_pool_by_arena_index(arena_ind);
188112

189-
if (pool->disable_provider_free) {
190-
return;
191-
}
192-
193113
umf_result_t ret;
194114
ret = umfMemoryProviderFree(pool->provider, addr, size);
195115
if (ret != UMF_RESULT_SUCCESS) {
@@ -212,10 +132,6 @@ static bool arena_extent_dalloc(extent_hooks_t *extent_hooks, void *addr,
212132

213133
jemalloc_memory_pool_t *pool = get_pool_by_arena_index(arena_ind);
214134

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

467383
static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
468384
void *params, void **out_pool) {
385+
(void)params; // unused
469386
assert(provider);
470387
assert(out_pool);
471388

472-
umf_jemalloc_pool_params_handle_t je_params =
473-
(umf_jemalloc_pool_params_handle_t)params;
474-
475389
extent_hooks_t *pHooks = &arena_extent_hooks;
476390
size_t unsigned_size = sizeof(unsigned);
477391
int err;
@@ -484,12 +398,6 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
484398

485399
pool->provider = provider;
486400

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

0 commit comments

Comments
 (0)