Skip to content

Align size of allocation to provider's page size in arena_extent_alloc() #853

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

Closed
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
17 changes: 16 additions & 1 deletion src/pool/pool_jemalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

typedef struct jemalloc_memory_pool_t {
umf_memory_provider_handle_t provider;
size_t page_size; // cached page size of the provider
unsigned int arena_index; // index of jemalloc arena
// set to true if umfMemoryProviderFree() should never be called
bool disable_provider_free;
Expand Down Expand Up @@ -75,6 +76,9 @@ static void *arena_extent_alloc(extent_hooks_t *extent_hooks, void *new_addr,

jemalloc_memory_pool_t *pool = get_pool_by_arena_index(arena_ind);

// align a size of the allocation to the provider's page size
size = ALIGN_UP(size, pool->page_size);

void *ptr = new_addr;
ret = umfMemoryProviderAlloc(pool->provider, size, alignment, &ptr);
if (ret != UMF_RESULT_SUCCESS) {
Expand Down Expand Up @@ -401,6 +405,8 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
assert(provider);
assert(out_pool);

umf_result_t umf_result = UMF_RESULT_ERROR_UNKNOWN;

umf_jemalloc_pool_params_t *je_params =
(umf_jemalloc_pool_params_t *)params;

Expand All @@ -416,6 +422,13 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,

pool->provider = provider;

umf_result =
umfMemoryProviderGetMinPageSize(provider, NULL, &pool->page_size);
if (umf_result != UMF_RESULT_SUCCESS) {
LOG_ERR("umfMemoryProviderGetMinPageSize() failed");
goto err_free_pool;
}

if (je_params) {
pool->disable_provider_free = je_params->disable_provider_free;
} else {
Expand All @@ -427,6 +440,7 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
NULL, 0);
if (err) {
LOG_ERR("Could not create arena.");
umf_result = UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC;
goto err_free_pool;
}

Expand All @@ -438,6 +452,7 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
snprintf(cmd, sizeof(cmd), "arena.%u.destroy", arena_index);
je_mallctl(cmd, NULL, 0, NULL, 0);
LOG_ERR("Could not setup extent_hooks for newly created arena.");
umf_result = UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC;
goto err_free_pool;
}

Expand All @@ -452,7 +467,7 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,

err_free_pool:
umf_ba_global_free(pool);
return UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC;
return umf_result;
}

static void op_finalize(void *pool) {
Expand Down
Loading