Skip to content

Commit d6d3337

Browse files
committed
Remove fixed provider from Coarse provider
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 2ac56a1 commit d6d3337

File tree

4 files changed

+120
-427
lines changed

4 files changed

+120
-427
lines changed

include/umf/providers/provider_coarse.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,6 @@ typedef struct coarse_memory_provider_params_t {
5151
/// See coarse_memory_provider_strategy_t for details.
5252
coarse_memory_provider_strategy_t allocation_strategy;
5353

54-
/// A pre-allocated buffer that will be the only memory that
55-
/// the coarse provider can provide (the fixed-size memory provider option).
56-
/// If it is non-NULL, `init_buffer_size ` has to contain its size.
57-
/// It has to be NULL if upstream_memory_provider is set
58-
/// (exactly one of them has to be non-NULL).
59-
void *init_buffer;
60-
61-
/// Size of the initial buffer:
62-
/// 1) `init_buffer` if it is non-NULL xor
63-
/// 2) that will be allocated from the upstream_memory_provider
64-
/// (if it is non-NULL) in the `.initialize` operation.
65-
size_t init_buffer_size;
66-
67-
/// When it is true and the upstream_memory_provider is given,
68-
/// the init buffer (of `init_buffer_size` bytes) would be pre-allocated
69-
/// during creation time using the `upstream_memory_provider`.
70-
/// If upstream_memory_provider is not given,
71-
/// the init_buffer is always used instead
72-
/// (regardless of the value of this parameter).
73-
bool immediate_init_from_upstream;
74-
7554
/// Destroy upstream_memory_provider in finalize().
7655
bool destroy_upstream_memory_provider;
7756
} coarse_memory_provider_params_t;

src/provider/provider_coarse.c

Lines changed: 35 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ typedef struct coarse_memory_provider_t {
3232
// memory allocation strategy
3333
coarse_memory_provider_strategy_t allocation_strategy;
3434

35-
void *init_buffer;
36-
3735
size_t used_size;
3836
size_t alloc_size;
3937

@@ -461,17 +459,15 @@ static umf_result_t user_block_merge(coarse_memory_provider_t *coarse_provider,
461459
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
462460
}
463461

464-
if (coarse_provider->upstream_memory_provider) {
465-
// check if blocks can be merged by the upstream provider
466-
umf_result_t umf_result = umfMemoryProviderAllocationMerge(
467-
coarse_provider->upstream_memory_provider, block1->data,
468-
block2->data, block1->size + block2->size);
469-
if (umf_result != UMF_RESULT_SUCCESS) {
470-
LOG_ERR("umfMemoryProviderAllocationMerge(lowPtr=%p, highPtr=%p, "
471-
"totalSize=%zu) failed",
472-
block1->data, block2->data, block1->size + block2->size);
473-
return umf_result;
474-
}
462+
// check if blocks can be merged by the upstream provider
463+
umf_result_t umf_result = umfMemoryProviderAllocationMerge(
464+
coarse_provider->upstream_memory_provider, block1->data, block2->data,
465+
block1->size + block2->size);
466+
if (umf_result != UMF_RESULT_SUCCESS) {
467+
LOG_ERR("umfMemoryProviderAllocationMerge(lowPtr=%p, highPtr=%p, "
468+
"totalSize=%zu) failed",
469+
block1->data, block2->data, block1->size + block2->size);
470+
return umf_result;
475471
}
476472

477473
if (block1->free_list_ptr) {
@@ -643,12 +639,6 @@ coarse_add_new_block(coarse_memory_provider_t *coarse_provider, void *addr,
643639

644640
static umf_result_t
645641
coarse_memory_provider_set_name(coarse_memory_provider_t *coarse_provider) {
646-
if (coarse_provider->upstream_memory_provider == NULL) {
647-
// COARSE_BASE_NAME will be used
648-
coarse_provider->name = NULL;
649-
return UMF_RESULT_SUCCESS;
650-
}
651-
652642
const char *up_name =
653643
umfMemoryProviderGetName(coarse_provider->upstream_memory_provider);
654644
if (!up_name) {
@@ -690,33 +680,8 @@ static umf_result_t coarse_memory_provider_initialize(void *params,
690680
(coarse_memory_provider_params_t *)params;
691681

692682
// check params
693-
if (!coarse_params->upstream_memory_provider ==
694-
!coarse_params->init_buffer) {
695-
LOG_ERR("either upstream provider or init buffer has to be provided in "
696-
"the parameters (exactly one of them)");
697-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
698-
}
699-
700-
if (coarse_params->init_buffer_size == 0 &&
701-
(coarse_params->immediate_init_from_upstream ||
702-
coarse_params->init_buffer != NULL)) {
703-
LOG_ERR("init_buffer_size has to be greater than 0 if "
704-
"immediate_init_from_upstream or init_buffer is set");
705-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
706-
}
707-
708-
if (coarse_params->init_buffer_size != 0 &&
709-
(!coarse_params->immediate_init_from_upstream &&
710-
coarse_params->init_buffer == NULL)) {
711-
LOG_ERR("init_buffer_size is greater than 0 but none of "
712-
"immediate_init_from_upstream nor init_buffer is set");
713-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
714-
}
715-
716-
if (coarse_params->destroy_upstream_memory_provider &&
717-
!coarse_params->upstream_memory_provider) {
718-
LOG_ERR("destroy_upstream_memory_provider is true, but an upstream "
719-
"provider is not provided");
683+
if (!coarse_params->upstream_memory_provider) {
684+
LOG_ERR("upstream provider has to be provided in the parameters");
720685
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
721686
}
722687

@@ -734,14 +699,8 @@ static umf_result_t coarse_memory_provider_initialize(void *params,
734699
coarse_provider->destroy_upstream_memory_provider =
735700
coarse_params->destroy_upstream_memory_provider;
736701
coarse_provider->allocation_strategy = coarse_params->allocation_strategy;
737-
coarse_provider->init_buffer = coarse_params->init_buffer;
738-
739-
if (coarse_provider->upstream_memory_provider) {
740-
coarse_provider->disable_upstream_provider_free =
741-
umfIsFreeOpDefault(coarse_provider->upstream_memory_provider);
742-
} else {
743-
coarse_provider->disable_upstream_provider_free = false;
744-
}
702+
coarse_provider->disable_upstream_provider_free =
703+
umfIsFreeOpDefault(coarse_provider->upstream_memory_provider);
745704

746705
umf_result_t umf_result = coarse_memory_provider_set_name(coarse_provider);
747706
if (umf_result != UMF_RESULT_SUCCESS) {
@@ -775,6 +734,7 @@ static umf_result_t coarse_memory_provider_initialize(void *params,
775734
goto err_delete_ravl_all_blocks;
776735
}
777736

737+
/*
778738
if (coarse_params->upstream_memory_provider &&
779739
coarse_params->immediate_init_from_upstream) {
780740
// allocate and immediately deallocate memory using the upstream provider
@@ -804,17 +764,16 @@ static umf_result_t coarse_memory_provider_initialize(void *params,
804764
coarse_provider->init_buffer,
805765
coarse_params->init_buffer_size);
806766
}
767+
*/
807768

808769
assert(coarse_provider->used_size == 0);
809-
assert(coarse_provider->alloc_size == coarse_params->init_buffer_size);
770+
assert(coarse_provider->alloc_size == 0);
810771
assert(debug_check(coarse_provider));
811772

812773
*provider = coarse_provider;
813774

814775
return UMF_RESULT_SUCCESS;
815776

816-
err_destroy_mutex:
817-
utils_mutex_destroy_not_free(&coarse_provider->lock);
818777
err_delete_ravl_all_blocks:
819778
ravl_delete(coarse_provider->all_blocks);
820779
err_delete_ravl_free_blocks:
@@ -836,8 +795,7 @@ static void coarse_ravl_cb_rm_all_blocks_node(void *data, void *arg) {
836795
block_t *block = node_data->value;
837796
assert(block);
838797

839-
if (coarse_provider->upstream_memory_provider &&
840-
!coarse_provider->disable_upstream_provider_free) {
798+
if (!coarse_provider->disable_upstream_provider_free) {
841799
// we continue to deallocate blocks even if the upstream provider doesn't return success
842800
umfMemoryProviderFree(coarse_provider->upstream_memory_provider,
843801
block->data, block->size);
@@ -874,8 +832,7 @@ static void coarse_memory_provider_finalize(void *provider) {
874832

875833
umf_ba_global_free(coarse_provider->name);
876834

877-
if (coarse_provider->destroy_upstream_memory_provider &&
878-
coarse_provider->upstream_memory_provider) {
835+
if (coarse_provider->destroy_upstream_memory_provider) {
879836
umfMemoryProviderDestroy(coarse_provider->upstream_memory_provider);
880837
}
881838

@@ -910,14 +867,12 @@ create_aligned_block(coarse_memory_provider_t *coarse_provider,
910867
uintptr_t aligned_data = ALIGN_UP(orig_data, alignment);
911868
size_t padding = aligned_data - orig_data;
912869
if (alignment > 0 && padding > 0) {
913-
if (coarse_provider->upstream_memory_provider) {
914-
// check if block can be split by the upstream provider
915-
umf_result_t umf_result =
916-
can_upstream_split(coarse_provider->upstream_memory_provider,
917-
curr->data, curr->size, padding);
918-
if (umf_result != UMF_RESULT_SUCCESS) {
919-
return umf_result;
920-
}
870+
// check if block can be split by the upstream provider
871+
umf_result_t umf_result =
872+
can_upstream_split(coarse_provider->upstream_memory_provider,
873+
curr->data, curr->size, padding);
874+
if (umf_result != UMF_RESULT_SUCCESS) {
875+
return umf_result;
921876
}
922877

923878
block_t *aligned_block = coarse_ravl_add_new(
@@ -948,14 +903,12 @@ static umf_result_t
948903
split_current_block(coarse_memory_provider_t *coarse_provider, block_t *curr,
949904
size_t size) {
950905

951-
if (coarse_provider->upstream_memory_provider) {
952-
// check if block can be split by the upstream provider
953-
umf_result_t umf_result =
954-
can_upstream_split(coarse_provider->upstream_memory_provider,
955-
curr->data, curr->size, size);
956-
if (umf_result != UMF_RESULT_SUCCESS) {
957-
return umf_result;
958-
}
906+
// check if block can be split by the upstream provider
907+
umf_result_t umf_result =
908+
can_upstream_split(coarse_provider->upstream_memory_provider,
909+
curr->data, curr->size, size);
910+
if (umf_result != UMF_RESULT_SUCCESS) {
911+
return umf_result;
959912
}
960913

961914
ravl_node_t *new_node = NULL;
@@ -1120,11 +1073,6 @@ static umf_result_t coarse_memory_provider_alloc(void *provider, size_t size,
11201073
// no suitable block found - try to get more memory from the upstream provider
11211074
umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
11221075

1123-
if (coarse_provider->upstream_memory_provider == NULL) {
1124-
LOG_ERR("out of memory - no upstream memory provider given");
1125-
goto err_unlock;
1126-
}
1127-
11281076
umfMemoryProviderAlloc(coarse_provider->upstream_memory_provider, size,
11291077
alignment, resultPtr);
11301078
if (*resultPtr == NULL) {
@@ -1236,11 +1184,6 @@ static umf_result_t coarse_memory_provider_get_min_page_size(void *provider,
12361184
coarse_memory_provider_t *coarse_provider =
12371185
(struct coarse_memory_provider_t *)provider;
12381186

1239-
if (!coarse_provider->upstream_memory_provider) {
1240-
*pageSize = utils_get_page_size();
1241-
return UMF_RESULT_SUCCESS;
1242-
}
1243-
12441187
return umfMemoryProviderGetMinPageSize(
12451188
coarse_provider->upstream_memory_provider, ptr, pageSize);
12461189
}
@@ -1251,11 +1194,6 @@ coarse_memory_provider_get_recommended_page_size(void *provider, size_t size,
12511194
coarse_memory_provider_t *coarse_provider =
12521195
(struct coarse_memory_provider_t *)provider;
12531196

1254-
if (!coarse_provider->upstream_memory_provider) {
1255-
*pageSize = utils_get_page_size();
1256-
return UMF_RESULT_SUCCESS;
1257-
}
1258-
12591197
return umfMemoryProviderGetRecommendedPageSize(
12601198
coarse_provider->upstream_memory_provider, size, pageSize);
12611199
}
@@ -1322,10 +1260,6 @@ static umf_result_t coarse_memory_provider_purge_lazy(void *provider, void *ptr,
13221260
size_t size) {
13231261
coarse_memory_provider_t *coarse_provider =
13241262
(struct coarse_memory_provider_t *)provider;
1325-
if (coarse_provider->upstream_memory_provider == NULL) {
1326-
LOG_ERR("no upstream memory provider given");
1327-
return UMF_RESULT_ERROR_NOT_SUPPORTED;
1328-
}
13291263

13301264
return umfMemoryProviderPurgeLazy(coarse_provider->upstream_memory_provider,
13311265
ptr, size);
@@ -1335,10 +1269,6 @@ static umf_result_t coarse_memory_provider_purge_force(void *provider,
13351269
void *ptr, size_t size) {
13361270
coarse_memory_provider_t *coarse_provider =
13371271
(struct coarse_memory_provider_t *)provider;
1338-
if (coarse_provider->upstream_memory_provider == NULL) {
1339-
LOG_ERR("no upstream memory provider given");
1340-
return UMF_RESULT_ERROR_NOT_SUPPORTED;
1341-
}
13421272

13431273
return umfMemoryProviderPurgeForce(
13441274
coarse_provider->upstream_memory_provider, ptr, size);
@@ -1360,14 +1290,11 @@ static umf_result_t coarse_memory_provider_allocation_split(void *provider,
13601290

13611291
assert(debug_check(coarse_provider));
13621292

1363-
if (coarse_provider->upstream_memory_provider) {
1364-
// check if block can be split by the upstream provider
1365-
umf_result =
1366-
can_upstream_split(coarse_provider->upstream_memory_provider, ptr,
1367-
totalSize, firstSize);
1368-
if (umf_result != UMF_RESULT_SUCCESS) {
1369-
return umf_result;
1370-
}
1293+
// check if block can be split by the upstream provider
1294+
umf_result = can_upstream_split(coarse_provider->upstream_memory_provider,
1295+
ptr, totalSize, firstSize);
1296+
if (umf_result != UMF_RESULT_SUCCESS) {
1297+
return umf_result;
13711298
}
13721299

13731300
ravl_node_t *node = coarse_ravl_find_node(coarse_provider->all_blocks, ptr);
@@ -1511,10 +1438,6 @@ static umf_result_t coarse_memory_provider_get_ipc_handle_size(void *provider,
15111438

15121439
coarse_memory_provider_t *coarse_provider =
15131440
(struct coarse_memory_provider_t *)provider;
1514-
if (!coarse_provider->upstream_memory_provider) {
1515-
LOG_ERR("missing upstream memory provider");
1516-
return UMF_RESULT_ERROR_NOT_SUPPORTED;
1517-
}
15181441

15191442
return umfMemoryProviderGetIPCHandleSize(
15201443
coarse_provider->upstream_memory_provider, size);
@@ -1529,10 +1452,6 @@ coarse_memory_provider_get_ipc_handle(void *provider, const void *ptr,
15291452

15301453
coarse_memory_provider_t *coarse_provider =
15311454
(struct coarse_memory_provider_t *)provider;
1532-
if (!coarse_provider->upstream_memory_provider) {
1533-
LOG_ERR("missing upstream memory provider");
1534-
return UMF_RESULT_ERROR_NOT_SUPPORTED;
1535-
}
15361455

15371456
return umfMemoryProviderGetIPCHandle(
15381457
coarse_provider->upstream_memory_provider, ptr, size, providerIpcData);
@@ -1545,10 +1464,6 @@ coarse_memory_provider_put_ipc_handle(void *provider, void *providerIpcData) {
15451464

15461465
coarse_memory_provider_t *coarse_provider =
15471466
(struct coarse_memory_provider_t *)provider;
1548-
if (!coarse_provider->upstream_memory_provider) {
1549-
LOG_ERR("missing upstream memory provider");
1550-
return UMF_RESULT_ERROR_NOT_SUPPORTED;
1551-
}
15521467

15531468
return umfMemoryProviderPutIPCHandle(
15541469
coarse_provider->upstream_memory_provider, providerIpcData);
@@ -1563,10 +1478,6 @@ coarse_memory_provider_open_ipc_handle(void *provider, void *providerIpcData,
15631478

15641479
coarse_memory_provider_t *coarse_provider =
15651480
(struct coarse_memory_provider_t *)provider;
1566-
if (!coarse_provider->upstream_memory_provider) {
1567-
LOG_ERR("missing upstream memory provider");
1568-
return UMF_RESULT_ERROR_NOT_SUPPORTED;
1569-
}
15701481

15711482
return umfMemoryProviderOpenIPCHandle(
15721483
coarse_provider->upstream_memory_provider, providerIpcData, ptr);
@@ -1580,10 +1491,6 @@ static umf_result_t coarse_memory_provider_close_ipc_handle(void *provider,
15801491

15811492
coarse_memory_provider_t *coarse_provider =
15821493
(struct coarse_memory_provider_t *)provider;
1583-
if (!coarse_provider->upstream_memory_provider) {
1584-
LOG_ERR("missing upstream memory provider");
1585-
return UMF_RESULT_ERROR_NOT_SUPPORTED;
1586-
}
15871494

15881495
return umfMemoryProviderCloseIPCHandle(
15891496
coarse_provider->upstream_memory_provider, ptr, size);

0 commit comments

Comments
 (0)