13
13
14
14
#include <jemalloc/jemalloc.h>
15
15
16
+ #include "base_alloc_global.h"
16
17
#include "utils_common.h"
17
18
#include <umf/memory_pool.h>
18
19
#include <umf/memory_pool_ops.h>
23
24
typedef struct jemalloc_memory_pool_t {
24
25
umf_memory_provider_handle_t provider ;
25
26
unsigned int arena_index ; // index of jemalloc arena
27
+
28
+ // saved pointer to the global base allocator
29
+ umf_ba_pool_t * base_allocator ;
26
30
} jemalloc_memory_pool_t ;
27
31
28
32
static __TLS umf_result_t TLS_last_allocation_error ;
@@ -357,11 +361,18 @@ static umf_result_t je_initialize(umf_memory_provider_handle_t provider,
357
361
size_t unsigned_size = sizeof (unsigned );
358
362
int err ;
359
363
360
- jemalloc_memory_pool_t * pool = malloc (sizeof (jemalloc_memory_pool_t ));
364
+ umf_ba_pool_t * base_allocator =
365
+ umf_ba_get_pool (sizeof (jemalloc_memory_pool_t ));
366
+ if (!base_allocator ) {
367
+ return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
368
+ }
369
+
370
+ jemalloc_memory_pool_t * pool = umf_ba_alloc (base_allocator );
361
371
if (!pool ) {
362
372
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
363
373
}
364
374
375
+ pool -> base_allocator = base_allocator ;
365
376
pool -> provider = provider ;
366
377
367
378
unsigned arena_index ;
@@ -392,7 +403,7 @@ static umf_result_t je_initialize(umf_memory_provider_handle_t provider,
392
403
return UMF_RESULT_SUCCESS ;
393
404
394
405
err_free_pool :
395
- free ( pool );
406
+ umf_ba_free ( base_allocator , pool );
396
407
return UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC ;
397
408
}
398
409
@@ -403,7 +414,7 @@ static void je_finalize(void *pool) {
403
414
snprintf (cmd , sizeof (cmd ), "arena.%u.destroy" , je_pool -> arena_index );
404
415
mallctl (cmd , NULL , 0 , NULL , 0 );
405
416
pool_by_arena_index [je_pool -> arena_index ] = NULL ;
406
- free ( je_pool );
417
+ umf_ba_free ( je_pool -> base_allocator , je_pool );
407
418
}
408
419
409
420
static size_t je_malloc_usable_size (void * pool , void * ptr ) {
0 commit comments