Skip to content

Commit 272bee1

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 59b89c6 commit 272bee1

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
@@ -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/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
@@ -91,31 +91,20 @@ struct umfJemallocPoolParamsTest
9191
static constexpr umf_memory_provider_ops_t VALIDATOR_PROVIDER_OPS =
9292
umf::providerMakeCOps<provider_validator, validation_params_t>();
9393

94-
umfJemallocPoolParamsTest() : expected_params{false}, params(nullptr) {}
95-
void SetUp() override {
96-
test::SetUp();
97-
expected_params.keep_all_memory = this->GetParam();
98-
umf_result_t ret = umfJemallocPoolParamsCreate(&params);
99-
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
100-
ret = umfJemallocPoolParamsSetKeepAllMemory(
101-
params, expected_params.keep_all_memory);
102-
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
103-
}
94+
umfJemallocPoolParamsTest() {}
95+
void SetUp() override { test::SetUp(); }
10496

105-
void TearDown() override {
106-
umfJemallocPoolParamsDestroy(params);
107-
test::TearDown();
108-
}
97+
void TearDown() override { test::TearDown(); }
10998

11099
umf::pool_unique_handle_t makePool() {
111100
umf_memory_provider_handle_t hProvider = nullptr;
112101
umf_memory_pool_handle_t hPool = nullptr;
113102

114-
auto ret = umfMemoryProviderCreate(&VALIDATOR_PROVIDER_OPS,
115-
&expected_params, &hProvider);
103+
auto ret = umfMemoryProviderCreate(&VALIDATOR_PROVIDER_OPS, nullptr,
104+
&hProvider);
116105
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
117106

118-
ret = umfPoolCreate(umfJemallocPoolOps(), hProvider, params,
107+
ret = umfPoolCreate(umfJemallocPoolOps(), hProvider, nullptr,
119108
UMF_POOL_CREATE_FLAG_OWN_PROVIDER, &hPool);
120109
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
121110

@@ -140,40 +129,11 @@ struct umfJemallocPoolParamsTest
140129
auto ret = umfPoolFree(pool.get(), ptrs[i]);
141130
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
142131
}
143-
144-
// Now pool can call free during pool destruction
145-
expected_params.keep_all_memory = false;
146132
}
147-
148-
validation_params_t expected_params;
149-
umf_jemalloc_pool_params_handle_t params;
150133
};
151134

152135
TEST_P(umfJemallocPoolParamsTest, allocFree) { allocFreeFlow(); }
153136

154-
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-
160-
allocFreeFlow();
161-
}
162-
163-
TEST_P(umfJemallocPoolParamsTest, invalidParams) {
164-
umf_result_t ret = umfJemallocPoolParamsCreate(nullptr);
165-
ASSERT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
166-
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-
173-
ret = umfJemallocPoolParamsDestroy(nullptr);
174-
ASSERT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
175-
}
176-
177137
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(umfJemallocPoolParamsTest);
178138

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

0 commit comments

Comments
 (0)