@@ -506,16 +506,6 @@ static umf_result_t trackingAllocationSplit(void *hProvider, void *ptr,
506
506
tracker_alloc_info_t * parent_value = NULL ;
507
507
uintptr_t parent_key = 0 ;
508
508
509
- tracker_alloc_info_t * splitValue =
510
- umf_ba_alloc (provider -> hTracker -> alloc_info_allocator );
511
- if (!splitValue ) {
512
- return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
513
- }
514
-
515
- splitValue -> pool = provider -> pool ;
516
- splitValue -> size = firstSize ;
517
- splitValue -> n_children = 0 ;
518
-
519
509
int r = utils_mutex_lock (& provider -> hTracker -> splitMergeMutex );
520
510
if (r ) {
521
511
goto err_lock ;
@@ -547,17 +537,11 @@ static umf_result_t trackingAllocationSplit(void *hProvider, void *ptr,
547
537
goto err ;
548
538
}
549
539
550
- assert (level < MAX_LEVELS_OF_ALLOC_SEGMENT_MAP );
551
- int cret =
552
- critnib_insert (provider -> hTracker -> alloc_segments_map [level ],
553
- (uintptr_t )ptr , (void * )splitValue , 1 /* update */ );
554
- // this cannot fail since we know the element exists (nothing to allocate)
555
- assert (cret == 0 );
556
- (void )cret ;
557
-
558
540
void * highPtr = (void * )(((uintptr_t )ptr ) + firstSize );
559
541
size_t secondSize = totalSize - firstSize ;
560
542
543
+ assert (level < MAX_LEVELS_OF_ALLOC_SEGMENT_MAP );
544
+
561
545
// We'll have a duplicate entry for the range [highPtr, highValue->size] but this is fine,
562
546
// the value is the same anyway and we forbid removing that range concurrently
563
547
ret = umfMemoryTrackerAddAtLevel (provider -> hTracker , level , provider -> pool ,
@@ -567,21 +551,20 @@ static umf_result_t trackingAllocationSplit(void *hProvider, void *ptr,
567
551
LOG_ERR ("failed to add the split region to the tracker, ptr=%p, "
568
552
"size=%zu, ret=%d" ,
569
553
highPtr , secondSize , ret );
554
+
570
555
// revert the split
571
- assert (level < MAX_LEVELS_OF_ALLOC_SEGMENT_MAP );
572
- cret = critnib_insert (provider -> hTracker -> alloc_segments_map [level ],
573
- (uintptr_t )ptr , (void * )value , 1 /* update */ );
574
- // this cannot fail since we know the element exists (nothing to allocate)
575
- assert (cret == 0 );
576
- (void )cret ;
556
+ (void )umfMemoryProviderAllocationMerge (provider -> hUpstream , ptr ,
557
+ highPtr , totalSize );
558
+
577
559
// TODO: what now? should we rollback the split? This can only happen due to ENOMEM
578
560
// so it's unlikely but probably the best solution would be to try to preallocate everything
579
561
// (value and critnib nodes) before calling umfMemoryProviderAllocationSplit.
580
562
goto err ;
581
563
}
582
564
583
- // free the original value
584
- umf_ba_free (provider -> hTracker -> alloc_info_allocator , value );
565
+ // update the size of the first part
566
+ utils_atomic_store_release_u64 ((uint64_t * )& value -> size , firstSize );
567
+
585
568
utils_mutex_unlock (& provider -> hTracker -> splitMergeMutex );
586
569
587
570
LOG_DEBUG (
@@ -592,9 +575,8 @@ static umf_result_t trackingAllocationSplit(void *hProvider, void *ptr,
592
575
593
576
err :
594
577
utils_mutex_unlock (& provider -> hTracker -> splitMergeMutex );
595
- err_lock :
596
- umf_ba_free (provider -> hTracker -> alloc_info_allocator , splitValue );
597
578
579
+ err_lock :
598
580
LOG_ERR (
599
581
"failed to split memory region: ptr=%p, totalSize=%zu, firstSize=%zu" ,
600
582
ptr , totalSize , firstSize );
0 commit comments