Skip to content

Commit a2749fa

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 467be17 commit a2749fa

File tree

4 files changed

+26
-34
lines changed

4 files changed

+26
-34
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,7 @@ It can be used when large memory mappings are needed.
188188

189189
The DevDax memory provider does not support the free operation
190190
(`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.
191+
so it should be always used with the Coarse provider.
194192

195193
##### Requirements
196194

@@ -203,9 +201,7 @@ A memory provider that provides memory by mapping a regular, extendable file.
203201

204202
The file memory provider does not support the free operation
205203
(`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.
204+
so it should be always used with the Coarse provider.
209205

210206
IPC API requires the `UMF_MEM_MAP_SHARED` memory `visibility` mode
211207
(`UMF_RESULT_ERROR_INVALID_ARGUMENT` is returned otherwise).

examples/dram_and_fsdax/dram_and_fsdax.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <string.h>
1111

1212
#include <umf/memory_provider.h>
13+
#include <umf/providers/provider_coarse.h>
1314
#include <umf/providers/provider_file_memory.h>
1415
#include <umf/providers/provider_os_memory.h>
1516

@@ -60,20 +61,32 @@ static umf_memory_pool_handle_t create_fsdax_pool(const char *path) {
6061
return NULL;
6162
}
6263

64+
coarse_memory_provider_params_t coarse_params;
65+
// make sure there are no undefined members - prevent a UB
66+
memset(&coarse_params, 0, sizeof(coarse_params));
67+
coarse_params.upstream_memory_provider = provider_fsdax;
68+
coarse_params.destroy_upstream_memory_provider = true;
69+
coarse_params.immediate_init_from_upstream = true;
70+
coarse_params.init_buffer = NULL;
71+
coarse_params.init_buffer_size = 8 * 1024 * 1024; // == 8 MB
72+
73+
umf_memory_provider_handle_t coarse_memory_provider;
74+
umf_result = umfMemoryProviderCreate(
75+
umfCoarseMemoryProviderOps(), &coarse_params, &coarse_memory_provider);
76+
if (umf_result != UMF_RESULT_SUCCESS) {
77+
fprintf(stderr, "Failed to create the Coarse provider");
78+
return NULL;
79+
}
80+
6381
// Create an FSDAX memory pool
6482
//
6583
// The file memory provider does not support the free operation
6684
// (`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_t pool_params;
71-
pool_params.disable_provider_free = true;
85+
// so it should be always used with the Coarse provider.
7286

7387
// Create an FSDAX memory pool
74-
umf_result =
75-
umfPoolCreate(umfJemallocPoolOps(), provider_fsdax, &pool_params,
76-
UMF_POOL_CREATE_FLAG_OWN_PROVIDER, &pool_fsdax);
88+
umf_result = umfPoolCreate(umfJemallocPoolOps(), provider_fsdax, NULL,
89+
UMF_POOL_CREATE_FLAG_OWN_PROVIDER, &pool_fsdax);
7790
if (umf_result != UMF_RESULT_SUCCESS) {
7891
fprintf(stderr, "Failed to create an FSDAX memory pool!\n");
7992
umfMemoryProviderDestroy(provider_fsdax);

include/umf/pools/pool_jemalloc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ extern "C" {
1919

2020
/// @brief Configuration of Jemalloc Pool
2121
typedef struct umf_jemalloc_pool_params_t {
22-
/// Set to true if umfMemoryProviderFree() should never be called.
22+
/// DEPRECATED and unused, will be removed in the next release,
23+
/// the Coarse provider should be used instead
2324
bool disable_provider_free;
2425
} umf_jemalloc_pool_params_t;
2526

src/pool/pool_jemalloc.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
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

4442
static __TLS umf_result_t TLS_last_allocation_error;
@@ -82,9 +80,7 @@ static void *arena_extent_alloc(extent_hooks_t *extent_hooks, void *new_addr,
8280
}
8381

8482
if (new_addr != NULL && ptr != new_addr) {
85-
if (!pool->disable_provider_free) {
86-
umfMemoryProviderFree(pool->provider, ptr, size);
87-
}
83+
umfMemoryProviderFree(pool->provider, ptr, size);
8884
return NULL;
8985
}
9086

@@ -118,10 +114,6 @@ static void arena_extent_destroy(extent_hooks_t *extent_hooks, void *addr,
118114

119115
jemalloc_memory_pool_t *pool = get_pool_by_arena_index(arena_ind);
120116

121-
if (pool->disable_provider_free) {
122-
return;
123-
}
124-
125117
umf_result_t ret;
126118
ret = umfMemoryProviderFree(pool->provider, addr, size);
127119
if (ret != UMF_RESULT_SUCCESS) {
@@ -144,10 +136,6 @@ static bool arena_extent_dalloc(extent_hooks_t *extent_hooks, void *addr,
144136

145137
jemalloc_memory_pool_t *pool = get_pool_by_arena_index(arena_ind);
146138

147-
if (pool->disable_provider_free) {
148-
return true; // opt-out from deallocation
149-
}
150-
151139
umf_result_t ret;
152140
ret = umfMemoryProviderFree(pool->provider, addr, size);
153141
if (ret != UMF_RESULT_SUCCESS) {
@@ -416,12 +404,6 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
416404

417405
pool->provider = provider;
418406

419-
if (je_params) {
420-
pool->disable_provider_free = je_params->disable_provider_free;
421-
} else {
422-
pool->disable_provider_free = false;
423-
}
424-
425407
unsigned arena_index;
426408
err = je_mallctl("arenas.create", (void *)&arena_index, &unsigned_size,
427409
NULL, 0);

0 commit comments

Comments
 (0)