Skip to content

Commit 76af328

Browse files
committed
Add provider_free_always_fails parameter to pool jemalloc
Add the provider_free_always_fails parameter to pool jemalloc. It should be set to true if umfMemoryProviderFree() of the chosen provider always fails. It is used to turn of the error messages. This option will be needed by the future memory providers that will not provide the free() op. Signed-off-by: Lukasz Dorau <[email protected]>
1 parent c39f4aa commit 76af328

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

include/umf/pools/pool_jemalloc.h

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

17+
#include <stdbool.h>
1718
#include <umf/memory_pool_ops.h>
1819

20+
/// @brief Configuration of Jemalloc Pool
21+
typedef struct umf_jemalloc_pool_params_t {
22+
/// Set to true if umfMemoryProviderFree()
23+
/// of the chosen provider always fails.
24+
/// It is used to turn of the error messages.
25+
bool provider_free_always_fails;
26+
} umf_jemalloc_pool_params_t;
27+
1928
umf_memory_pool_ops_t *umfJemallocPoolOps(void);
2029

2130
#ifdef __cplusplus

src/pool/pool_jemalloc.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
typedef struct jemalloc_memory_pool_t {
3838
umf_memory_provider_handle_t provider;
3939
unsigned int arena_index; // index of jemalloc arena
40+
bool provider_free_always_fails;
4041
} jemalloc_memory_pool_t;
4142

4243
static __TLS umf_result_t TLS_last_allocation_error;
@@ -116,7 +117,7 @@ static void arena_extent_destroy(extent_hooks_t *extent_hooks, void *addr,
116117

117118
umf_result_t ret;
118119
ret = umfMemoryProviderFree(pool->provider, addr, size);
119-
if (ret != UMF_RESULT_SUCCESS) {
120+
if (ret != UMF_RESULT_SUCCESS && !pool->provider_free_always_fails) {
120121
LOG_ERR("umfMemoryProviderFree failed");
121122
}
122123
}
@@ -138,7 +139,7 @@ static bool arena_extent_dalloc(extent_hooks_t *extent_hooks, void *addr,
138139

139140
umf_result_t ret;
140141
ret = umfMemoryProviderFree(pool->provider, addr, size);
141-
if (ret != UMF_RESULT_SUCCESS) {
142+
if (ret != UMF_RESULT_SUCCESS && !pool->provider_free_always_fails) {
142143
LOG_ERR("umfMemoryProviderFree failed in dalloc");
143144
}
144145

@@ -388,7 +389,9 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
388389
void *params, void **out_pool) {
389390
assert(provider);
390391
assert(out_pool);
391-
(void)params; // unused
392+
393+
umf_jemalloc_pool_params_t *je_params =
394+
(umf_jemalloc_pool_params_t *)params;
392395

393396
extent_hooks_t *pHooks = &arena_extent_hooks;
394397
size_t unsigned_size = sizeof(unsigned);
@@ -402,6 +405,13 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
402405

403406
pool->provider = provider;
404407

408+
if (je_params) {
409+
pool->provider_free_always_fails =
410+
je_params->provider_free_always_fails;
411+
} else {
412+
pool->provider_free_always_fails = false;
413+
}
414+
405415
unsigned arena_index;
406416
err = je_mallctl("arenas.create", (void *)&arena_index, &unsigned_size,
407417
NULL, 0);

0 commit comments

Comments
 (0)