7
7
*
8
8
*/
9
9
10
- #include "provider_tracking.h"
10
+ #include <assert.h>
11
+ #include <errno.h>
12
+ #include <stdio.h>
13
+ #include <stdlib.h>
14
+ #include <string.h>
15
+
16
+ #include <umf/memory_pool.h>
17
+ #include <umf/memory_provider.h>
18
+ #include <umf/memory_provider_ops.h>
19
+
11
20
#include "base_alloc_global.h"
12
21
#include "critnib.h"
13
22
#include "ipc_internal.h"
23
+ #include "libumf.h"
24
+ #include "memory_pool_internal.h"
25
+ #include "provider_tracking.h"
14
26
#include "utils_common.h"
15
27
#include "utils_concurrency.h"
16
28
#include "utils_log.h"
17
29
18
- #include <umf/memory_pool.h>
19
- #include <umf/memory_provider.h>
20
- #include <umf/memory_provider_ops.h>
21
-
22
- #include <assert.h>
23
- #include <errno.h>
24
- #include <stdio.h>
25
- #include <stdlib.h>
26
- #include <string.h>
27
-
28
30
typedef struct tracker_value_t {
29
31
umf_memory_pool_handle_t pool ;
30
32
size_t size ;
@@ -82,9 +84,8 @@ static umf_result_t umfMemoryTrackerRemove(umf_memory_tracker_handle_t hTracker,
82
84
}
83
85
84
86
tracker_value_t * v = value ;
85
-
86
- LOG_DEBUG ("memory region removed: tracker=%p, ptr=%p, size=%zu" ,
87
- (void * )hTracker , ptr , v -> size );
87
+ LOG_DEBUG ("memory region removed: tracker=%p, ptr=%p, pool=%p, size=%zu" ,
88
+ (void * )hTracker , ptr , (void * )v -> pool , v -> size );
88
89
89
90
umf_ba_free (hTracker -> tracker_allocator , value );
90
91
@@ -167,23 +168,26 @@ static umf_result_t trackingAlloc(void *hProvider, size_t size,
167
168
return ret ;
168
169
}
169
170
171
+ LOG_DEBUG ("allocated %p, provider: %p, size: %zu" , * ptr ,
172
+ (void * )p -> hUpstream , size );
173
+
170
174
// check if the allocation was already added to the tracker
171
175
// (in case of using ProxyLib)
172
176
tracker_value_t * value =
173
177
(tracker_value_t * )critnib_get (p -> hTracker -> map , * (uintptr_t * )ptr );
174
178
if (value ) {
175
179
assert (value -> pool != p -> pool );
180
+ LOG_ERR ("ptr already exists in the tracker ptr=%p, old size=%zu, new "
181
+ "size=%zu, old pool %p, new pool %p, tracker %p" ,
182
+ * ptr , value -> size , size , (void * )value -> pool , (void * )p -> pool ,
183
+ (void * )p -> hTracker );
176
184
177
- LOG_DEBUG ("ptr already exists in the tracker (added by Proxy Lib) - "
178
- "updating value, ptr=%p, size=%zu, old pool: %p, new pool %p" ,
179
- * ptr , size , (void * )value -> pool , (void * )p -> pool );
180
-
181
- // the allocation was made by the ProxyLib so we only update the tracker
182
185
value -> pool = p -> pool ;
186
+ value -> size = size ;
183
187
int crit_ret = critnib_insert (p -> hTracker -> map , * (uintptr_t * )ptr ,
184
188
value , 1 /* update */ );
185
189
186
- // this cannot fail since we know the element exists and there is
190
+ // this cannot fail since we know the element exists and there is
187
191
// nothing to allocate
188
192
assert (crit_ret == 0 );
189
193
(void )crit_ret ;
@@ -222,6 +226,12 @@ static umf_result_t trackingAllocationSplit(void *hProvider, void *ptr,
222
226
goto err_lock ;
223
227
}
224
228
229
+ void * highPtr = (void * )(((uintptr_t )ptr ) + firstSize );
230
+ size_t secondSize = totalSize - firstSize ;
231
+
232
+ LOG_DEBUG ("trying to split (%p, %zu) to (%p, %zu) and (%p, %zu)" , ptr ,
233
+ totalSize , ptr , firstSize , highPtr , secondSize );
234
+
225
235
tracker_value_t * value =
226
236
(tracker_value_t * )critnib_get (provider -> hTracker -> map , (uintptr_t )ptr );
227
237
if (!value ) {
@@ -243,9 +253,6 @@ static umf_result_t trackingAllocationSplit(void *hProvider, void *ptr,
243
253
goto err ;
244
254
}
245
255
246
- void * highPtr = (void * )(((uintptr_t )ptr ) + firstSize );
247
- size_t secondSize = totalSize - firstSize ;
248
-
249
256
// We'll have a duplicate entry for the range [highPtr, highValue->size] but this is fine,
250
257
// the value is the same anyway and we forbid removing that range concurrently
251
258
ret = umfMemoryTrackerAdd (provider -> hTracker , provider -> pool , highPtr ,
@@ -260,6 +267,9 @@ static umf_result_t trackingAllocationSplit(void *hProvider, void *ptr,
260
267
goto err ;
261
268
}
262
269
270
+ LOG_DEBUG ("update split region ptr=%p, pool=%p size=%zu" , ptr ,
271
+ (void * )splitValue -> pool , splitValue -> size );
272
+
263
273
int cret = critnib_insert (provider -> hTracker -> map , (uintptr_t )ptr ,
264
274
(void * )splitValue , 1 /* update */ );
265
275
// this cannot fail since we know the element exists (nothing to allocate)
@@ -303,22 +313,26 @@ static umf_result_t trackingAllocationMerge(void *hProvider, void *lowPtr,
303
313
tracker_value_t * lowValue = (tracker_value_t * )critnib_get (
304
314
provider -> hTracker -> map , (uintptr_t )lowPtr );
305
315
if (!lowValue ) {
306
- LOG_ERR ("no left value" );
316
+ LOG_ERR ("no left value (%p) found in tracker!" , lowPtr );
307
317
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT ;
308
318
goto err ;
309
319
}
320
+
310
321
tracker_value_t * highValue = (tracker_value_t * )critnib_get (
311
322
provider -> hTracker -> map , (uintptr_t )highPtr );
312
323
if (!highValue ) {
313
- LOG_ERR ("no right value" );
324
+ LOG_ERR ("no right value (%p) found in tracker!" , highPtr );
314
325
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT ;
315
326
goto err ;
316
327
}
328
+
317
329
if (lowValue -> pool != highValue -> pool ) {
318
- LOG_ERR ("pool mismatch" );
330
+ LOG_ERR ("pool mismatch: %p vs %p" , (void * )lowValue -> pool ,
331
+ (void * )highValue -> pool );
319
332
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT ;
320
333
goto err ;
321
334
}
335
+
322
336
if (lowValue -> size + highValue -> size != totalSize ) {
323
337
LOG_ERR ("lowValue->size + highValue->size != totalSize" );
324
338
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT ;
@@ -355,6 +369,8 @@ static umf_result_t trackingAllocationMerge(void *hProvider, void *lowPtr,
355
369
356
370
err :
357
371
utils_mutex_unlock (& provider -> hTracker -> splitMergeMutex );
372
+ assert (0 );
373
+
358
374
err_lock :
359
375
umf_ba_free (provider -> hTracker -> tracker_allocator , mergedValue );
360
376
return ret ;
@@ -376,7 +392,7 @@ static umf_result_t trackingFree(void *hProvider, void *ptr, size_t size) {
376
392
// DO NOT return an error here, because the tracking provider
377
393
// cannot change behaviour of the upstream provider.
378
394
LOG_ERR ("failed to remove the region from the tracker, ptr=%p, "
379
- "size=%zu, ret = %d" ,
395
+ "size=%zu, ret= %d" ,
380
396
ptr , size , ret_remove );
381
397
}
382
398
}
0 commit comments