|
12 | 12 | #include <string.h>
|
13 | 13 |
|
14 | 14 | #include "base_alloc_global.h"
|
| 15 | +#include "memory_provider_internal.h" |
| 16 | +#include "provider_tracking.h" |
15 | 17 | #include "utils_common.h"
|
16 | 18 | #include "utils_concurrency.h"
|
17 | 19 | #include "utils_log.h"
|
@@ -283,8 +285,15 @@ static bool arena_extent_split(extent_hooks_t *extent_hooks, void *addr,
|
283 | 285 |
|
284 | 286 | jemalloc_memory_pool_t *pool = get_pool_by_arena_index(arena_ind);
|
285 | 287 | assert(pool);
|
286 |
| - return umfMemoryProviderAllocationSplit(pool->provider, addr, size, |
287 |
| - size_a) != UMF_RESULT_SUCCESS; |
| 288 | + |
| 289 | + umf_result_t ret = |
| 290 | + umfMemoryProviderAllocationSplit(pool->provider, addr, size, size_a); |
| 291 | + if (ret != UMF_RESULT_SUCCESS) { |
| 292 | + LOG_ERR("memory provider failed to split a memory region, while " |
| 293 | + "jemalloc requires that"); |
| 294 | + } |
| 295 | + |
| 296 | + return ret != UMF_RESULT_SUCCESS; |
288 | 297 | }
|
289 | 298 |
|
290 | 299 | // arena_extent_merge - an extent merge function conforms to the extent_merge_t type and optionally
|
@@ -435,11 +444,45 @@ static void *op_aligned_alloc(void *pool, size_t size, size_t alignment) {
|
435 | 444 | return ptr;
|
436 | 445 | }
|
437 | 446 |
|
| 447 | +// Verify if the memory provider supports the split() operation, |
| 448 | +// because jemalloc pool requires that. |
| 449 | +static umf_result_t verify_split(umf_memory_provider_handle_t provider) { |
| 450 | + // Retrieve the upstream memory provider |
| 451 | + umf_memory_provider_handle_t upstream_provider = NULL; |
| 452 | + umfTrackingMemoryProviderGetUpstreamProvider( |
| 453 | + umfMemoryProviderGetPriv(provider), &upstream_provider); |
| 454 | + |
| 455 | + size_t page_size; |
| 456 | + umf_result_t ret = |
| 457 | + umfMemoryProviderGetMinPageSize(upstream_provider, NULL, &page_size); |
| 458 | + if (ret != UMF_RESULT_SUCCESS) { |
| 459 | + return ret; |
| 460 | + } |
| 461 | + |
| 462 | + size_t size = 2 * page_size; // use double the page size for the split test |
| 463 | + if (UMF_RESULT_ERROR_NOT_SUPPORTED == |
| 464 | + umfMemoryProviderAllocationSplit(upstream_provider, (void *)size, size, |
| 465 | + page_size)) { |
| 466 | + LOG_ERR("memory provider does not support the split operation, while " |
| 467 | + "jemalloc pool requires that"); |
| 468 | + return UMF_RESULT_ERROR_NOT_SUPPORTED; |
| 469 | + } |
| 470 | + |
| 471 | + return UMF_RESULT_SUCCESS; |
| 472 | +} |
| 473 | + |
438 | 474 | static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
|
439 | 475 | const void *params, void **out_pool) {
|
440 | 476 | assert(provider);
|
441 | 477 | assert(out_pool);
|
442 | 478 |
|
| 479 | + // Verify if the memory provider supports the split() operation, |
| 480 | + // because jemalloc pool requires that. |
| 481 | + umf_result_t ret = verify_split(provider); |
| 482 | + if (ret != UMF_RESULT_SUCCESS) { |
| 483 | + return ret; |
| 484 | + } |
| 485 | + |
443 | 486 | extent_hooks_t *pHooks = &arena_extent_hooks;
|
444 | 487 | size_t unsigned_size = sizeof(unsigned);
|
445 | 488 | int n_arenas_set_from_params = 0;
|
|
0 commit comments