Skip to content

Remove the disable provider free parameter of jemalloc pool #911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,6 @@ Additionally, required for tests:
A memory provider that provides memory from a device DAX (a character device file /dev/daxX.Y).
It can be used when large memory mappings are needed.

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

##### Requirements

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

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

The file memory provider does not support the free operation
(`umfMemoryProviderFree()` always returns `UMF_RESULT_ERROR_NOT_SUPPORTED`),
so it should be used with a pool manager that will take over
the managing of the provided memory - for example the jemalloc pool
with the `disable_provider_free` parameter set to true.

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

Expand Down
31 changes: 2 additions & 29 deletions examples/dram_and_fsdax/dram_and_fsdax.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,41 +78,14 @@ static umf_memory_pool_handle_t create_fsdax_pool(const char *path) {
}

// Create an FSDAX memory pool
//
// The file memory provider does not support the free operation
// (`umfMemoryProviderFree()` always returns `UMF_RESULT_ERROR_NOT_SUPPORTED`),
// so it should be used with a pool manager that will take over
// the managing of the provided memory - for example the jemalloc pool
// with the `disable_provider_free` parameter set to true.
umf_jemalloc_pool_params_handle_t pool_params;
umf_result = umfJemallocPoolParamsCreate(&pool_params);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to create jemalloc params!\n");
umfMemoryProviderDestroy(provider_fsdax);
return NULL;
}
umf_result = umfJemallocPoolParamsSetKeepAllMemory(pool_params, true);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to set KeepAllMemory!\n");
umfMemoryProviderDestroy(provider_fsdax);
return NULL;
}

// Create an FSDAX memory pool
umf_result =
umfPoolCreate(umfJemallocPoolOps(), provider_fsdax, pool_params,
UMF_POOL_CREATE_FLAG_OWN_PROVIDER, &pool_fsdax);
umf_result = umfPoolCreate(umfJemallocPoolOps(), provider_fsdax, NULL,
UMF_POOL_CREATE_FLAG_OWN_PROVIDER, &pool_fsdax);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to create an FSDAX memory pool!\n");
umfMemoryProviderDestroy(provider_fsdax);
return NULL;
}

umf_result = umfJemallocPoolParamsDestroy(pool_params);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to destroy jemalloc params!\n");
}

return pool_fsdax;
}

Expand Down
27 changes: 0 additions & 27 deletions include/umf/pools/pool_jemalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,8 @@
extern "C" {
#endif

#include <stdbool.h>
#include <umf/memory_pool_ops.h>

struct umf_jemalloc_pool_params_t;

/// @brief handle to the parameters of the jemalloc pool.
typedef struct umf_jemalloc_pool_params_t *umf_jemalloc_pool_params_handle_t;

/// @brief Create a struct to store parameters of jemalloc pool.
/// @param hParams [out] handle to the newly created parameters struct.
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
umf_result_t
umfJemallocPoolParamsCreate(umf_jemalloc_pool_params_handle_t *hParams);

/// @brief Destroy parameters struct.
/// @param hParams handle to the parameters of the jemalloc pool.
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
umf_result_t
umfJemallocPoolParamsDestroy(umf_jemalloc_pool_params_handle_t hParams);

/// @brief Set if \p umfMemoryProviderFree() should never be called.
/// @param hParams handle to the parameters of the jemalloc pool.
/// @param keepAllMemory \p true if the jemalloc pool should not call
/// \p umfMemoryProviderFree, \p false otherwise.
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
umf_result_t
umfJemallocPoolParamsSetKeepAllMemory(umf_jemalloc_pool_params_handle_t hParams,
bool keepAllMemory);

umf_memory_pool_ops_t *umfJemallocPoolOps(void);

#ifdef __cplusplus
Expand Down
3 changes: 0 additions & 3 deletions src/libumf.def
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ EXPORTS
umfGetIPCHandle
umfGetLastFailedMemoryProvider
umfJemallocPoolOps
umfJemallocPoolParamsCreate
umfJemallocPoolParamsDestroy
umfJemallocPoolParamsSetKeepAllMemory
umfLevelZeroMemoryProviderOps
umfLevelZeroMemoryProviderParamsCreate
umfLevelZeroMemoryProviderParamsDestroy
Expand Down
3 changes: 0 additions & 3 deletions src/libumf.map
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ UMF_1.0 {
umfGetIPCHandle;
umfGetLastFailedMemoryProvider;
umfJemallocPoolOps;
umfJemallocPoolParamsCreate;
umfJemallocPoolParamsDestroy;
umfJemallocPoolParamsSetKeepAllMemory;
umfLevelZeroMemoryProviderOps;
umfLevelZeroMemoryProviderParamsCreate;
umfLevelZeroMemoryProviderParamsDestroy;
Expand Down
96 changes: 2 additions & 94 deletions src/pool/pool_jemalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,6 @@

umf_memory_pool_ops_t *umfJemallocPoolOps(void) { return NULL; }

umf_result_t
umfJemallocPoolParamsCreate(umf_jemalloc_pool_params_handle_t *hParams) {
(void)hParams; // unused
return UMF_RESULT_ERROR_NOT_SUPPORTED;
}

umf_result_t
umfJemallocPoolParamsDestroy(umf_jemalloc_pool_params_handle_t hParams) {
(void)hParams; // unused
return UMF_RESULT_ERROR_NOT_SUPPORTED;
}

umf_result_t
umfJemallocPoolParamsSetKeepAllMemory(umf_jemalloc_pool_params_handle_t hParams,
bool keepAllMemory) {
(void)hParams; // unused
(void)keepAllMemory; // unused
return UMF_RESULT_ERROR_NOT_SUPPORTED;
}

#else

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

// Configuration of Jemalloc Pool
typedef struct umf_jemalloc_pool_params_t {
/// Set to true if umfMemoryProviderFree() should never be called.
bool disable_provider_free;
} umf_jemalloc_pool_params_t;

static __TLS umf_result_t TLS_last_allocation_error;

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

umf_result_t
umfJemallocPoolParamsCreate(umf_jemalloc_pool_params_handle_t *hParams) {
if (!hParams) {
LOG_ERR("jemalloc pool params handle is NULL");
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

umf_jemalloc_pool_params_t *params_data =
umf_ba_global_alloc(sizeof(*params_data));
if (!params_data) {
LOG_ERR("cannot allocate memory for jemalloc poolparams");
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}

params_data->disable_provider_free = false;

*hParams = (umf_jemalloc_pool_params_handle_t)params_data;

return UMF_RESULT_SUCCESS;
}

umf_result_t
umfJemallocPoolParamsDestroy(umf_jemalloc_pool_params_handle_t hParams) {
if (!hParams) {
LOG_ERR("jemalloc pool params handle is NULL");
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

umf_ba_global_free(hParams);

return UMF_RESULT_SUCCESS;
}

umf_result_t
umfJemallocPoolParamsSetKeepAllMemory(umf_jemalloc_pool_params_handle_t hParams,
bool keepAllMemory) {
if (!hParams) {
LOG_ERR("jemalloc pool params handle is NULL");
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

hParams->disable_provider_free = keepAllMemory;

return UMF_RESULT_SUCCESS;
}

// arena_extent_alloc - an extent allocation function conforms to the extent_alloc_t type and upon
// success returns a pointer to size bytes of mapped memory on behalf of arena arena_ind such that
// the extent's base address is a multiple of alignment, as well as setting *zero to indicate
Expand Down Expand Up @@ -150,9 +76,7 @@ static void *arena_extent_alloc(extent_hooks_t *extent_hooks, void *new_addr,
}

if (new_addr != NULL && ptr != new_addr) {
if (!pool->disable_provider_free) {
umfMemoryProviderFree(pool->provider, ptr, size);
}
umfMemoryProviderFree(pool->provider, ptr, size);
return NULL;
}

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

jemalloc_memory_pool_t *pool = get_pool_by_arena_index(arena_ind);

if (pool->disable_provider_free) {
return;
}

umf_result_t ret;
ret = umfMemoryProviderFree(pool->provider, addr, size);
if (ret != UMF_RESULT_SUCCESS) {
Expand All @@ -212,10 +132,6 @@ static bool arena_extent_dalloc(extent_hooks_t *extent_hooks, void *addr,

jemalloc_memory_pool_t *pool = get_pool_by_arena_index(arena_ind);

if (pool->disable_provider_free) {
return true; // opt-out from deallocation
}

umf_result_t ret;
ret = umfMemoryProviderFree(pool->provider, addr, size);
if (ret != UMF_RESULT_SUCCESS) {
Expand Down Expand Up @@ -466,12 +382,10 @@ static void *op_aligned_alloc(void *pool, size_t size, size_t alignment) {

static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
void *params, void **out_pool) {
(void)params; // unused
assert(provider);
assert(out_pool);

umf_jemalloc_pool_params_handle_t je_params =
(umf_jemalloc_pool_params_handle_t)params;

extent_hooks_t *pHooks = &arena_extent_hooks;
size_t unsigned_size = sizeof(unsigned);
int err;
Expand All @@ -484,12 +398,6 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,

pool->provider = provider;

if (je_params) {
pool->disable_provider_free = je_params->disable_provider_free;
} else {
pool->disable_provider_free = false;
}

unsigned arena_index;
err = je_mallctl("arenas.create", (void *)&arena_index, &unsigned_size,
NULL, 0);
Expand Down
Loading
Loading