@@ -201,6 +201,19 @@ static umf_result_t umfMemoryTrackerAdd(umf_memory_tracker_handle_t hTracker,
201
201
202
202
utils_atomic_load_acquire_u64 ((uint64_t * )& rvalue -> size , & rsize );
203
203
204
+ // size == 0 means that the entry was removed
205
+ if (rsize == 0 ) {
206
+ // restart the search
207
+ parent_value = NULL ;
208
+ rvalue = NULL ;
209
+ parent_key = 0 ;
210
+ rkey = 0 ;
211
+ rsize = 0 ;
212
+ level = 0 ;
213
+ found = 0 ;
214
+ continue ;
215
+ }
216
+
204
217
if ((uintptr_t )ptr < rkey + rsize ) {
205
218
if (level == MAX_LEVELS_OF_ALLOC_SEGMENT_MAP - 1 ) {
206
219
// TODO: we need to support an arbitrary amount of layers in the future
@@ -254,14 +267,17 @@ static umf_result_t umfMemoryTrackerRemove(umf_memory_tracker_handle_t hTracker,
254
267
return UMF_RESULT_ERROR_UNKNOWN ;
255
268
}
256
269
257
- assert (level < MAX_LEVELS_OF_ALLOC_SEGMENT_MAP );
258
- value = critnib_remove (hTracker -> alloc_segments_map [level ], (uintptr_t )ptr );
259
- assert (value );
260
-
261
270
LOG_DEBUG ("memory region removed: tracker=%p, level=%i, pool=%p, ptr=%p, "
262
271
"size=%zu" ,
263
272
(void * )hTracker , level , (void * )value -> pool , ptr , value -> size );
264
273
274
+ // size == 0 means that the entry was removed
275
+ utils_atomic_store_release_u64 ((uint64_t * )& value -> size , 0 );
276
+
277
+ assert (level < MAX_LEVELS_OF_ALLOC_SEGMENT_MAP );
278
+ value = critnib_remove (hTracker -> alloc_segments_map [level ], (uintptr_t )ptr );
279
+ assert (value );
280
+
265
281
if (parent_value ) {
266
282
LOG_DEBUG (
267
283
"child #%zu removed from memory region: tracker=%p, level=%i, "
@@ -271,8 +287,6 @@ static umf_result_t umfMemoryTrackerRemove(umf_memory_tracker_handle_t hTracker,
271
287
parent_value -> n_children -- ;
272
288
}
273
289
274
- umf_ba_free (hTracker -> alloc_info_allocator , value );
275
-
276
290
return UMF_RESULT_SUCCESS ;
277
291
}
278
292
@@ -652,6 +666,9 @@ static umf_result_t trackingAllocationMerge(void *hProvider, void *lowPtr,
652
666
// we only need to update the size of the first part
653
667
utils_atomic_store_release_u64 ((uint64_t * )& lowValue -> size , totalSize );
654
668
669
+ // size == 0 means that the entry was removed
670
+ utils_atomic_store_release_u64 ((uint64_t * )& highValue -> size , 0 );
671
+
655
672
void * erasedhighValue = critnib_remove (
656
673
provider -> hTracker -> alloc_segments_map [highLevel ], (uintptr_t )highPtr );
657
674
assert (erasedhighValue == highValue );
@@ -664,8 +681,6 @@ static umf_result_t trackingAllocationMerge(void *hProvider, void *lowPtr,
664
681
lowLevel , lowPtr , lowValue -> n_children , highPtr ,
665
682
highValue -> n_children , totalSize );
666
683
667
- umf_ba_free (provider -> hTracker -> alloc_info_allocator , highValue );
668
-
669
684
return UMF_RESULT_SUCCESS ;
670
685
671
686
err_fatal :
@@ -1128,7 +1143,7 @@ umf_result_t umfTrackingMemoryProviderCreate(
1128
1143
return UMF_RESULT_ERROR_UNKNOWN ;
1129
1144
}
1130
1145
params .pool = hPool ;
1131
- params .ipcCache = critnib_new ();
1146
+ params .ipcCache = critnib_new (NULL , NULL );
1132
1147
if (!params .ipcCache ) {
1133
1148
LOG_ERR ("failed to create IPC cache" );
1134
1149
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
@@ -1156,6 +1171,12 @@ void umfTrackingMemoryProviderGetUpstreamProvider(
1156
1171
* hUpstream = p -> hUpstream ;
1157
1172
}
1158
1173
1174
+ static void free_leaf (void * leaf_allocator , void * ptr ) {
1175
+ if (ptr ) {
1176
+ umf_ba_free (leaf_allocator , ptr );
1177
+ }
1178
+ }
1179
+
1159
1180
umf_memory_tracker_handle_t umfMemoryTrackerCreate (void ) {
1160
1181
umf_memory_tracker_handle_t handle =
1161
1182
umf_ba_global_alloc (sizeof (struct umf_memory_tracker_t ));
@@ -1180,7 +1201,8 @@ umf_memory_tracker_handle_t umfMemoryTrackerCreate(void) {
1180
1201
1181
1202
int i ;
1182
1203
for (i = 0 ; i < MAX_LEVELS_OF_ALLOC_SEGMENT_MAP ; i ++ ) {
1183
- handle -> alloc_segments_map [i ] = critnib_new ();
1204
+ handle -> alloc_segments_map [i ] =
1205
+ critnib_new (alloc_info_allocator , free_leaf );
1184
1206
if (!handle -> alloc_segments_map [i ]) {
1185
1207
goto err_destroy_alloc_segments_map ;
1186
1208
}
@@ -1192,7 +1214,7 @@ umf_memory_tracker_handle_t umfMemoryTrackerCreate(void) {
1192
1214
goto err_destroy_alloc_segments_map ;
1193
1215
}
1194
1216
1195
- handle -> ipc_segments_map = critnib_new ();
1217
+ handle -> ipc_segments_map = critnib_new (NULL , NULL );
1196
1218
if (!handle -> ipc_segments_map ) {
1197
1219
goto err_destroy_ipc_info_allocator ;
1198
1220
}
0 commit comments