Skip to content

Commit dd22268

Browse files
committed
improve debug messages
1 parent 6925fbc commit dd22268

File tree

1 file changed

+45
-29
lines changed

1 file changed

+45
-29
lines changed

src/provider/provider_tracking.c

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,26 @@
77
*
88
*/
99

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+
1120
#include "base_alloc_global.h"
1221
#include "critnib.h"
1322
#include "ipc_internal.h"
23+
#include "libumf.h"
24+
#include "memory_pool_internal.h"
25+
#include "provider_tracking.h"
1426
#include "utils_common.h"
1527
#include "utils_concurrency.h"
1628
#include "utils_log.h"
1729

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-
2830
typedef struct tracker_value_t {
2931
umf_memory_pool_handle_t pool;
3032
size_t size;
@@ -82,9 +84,8 @@ static umf_result_t umfMemoryTrackerRemove(umf_memory_tracker_handle_t hTracker,
8284
}
8385

8486
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);
8889

8990
umf_ba_free(hTracker->tracker_allocator, value);
9091

@@ -167,23 +168,26 @@ static umf_result_t trackingAlloc(void *hProvider, size_t size,
167168
return ret;
168169
}
169170

171+
LOG_DEBUG("allocated %p, provider: %p, size: %zu", *ptr,
172+
(void *)p->hUpstream, size);
173+
170174
// check if the allocation was already added to the tracker
171175
// (in case of using ProxyLib)
172176
tracker_value_t *value =
173177
(tracker_value_t *)critnib_get(p->hTracker->map, *(uintptr_t *)ptr);
174178
if (value) {
175179
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);
176184

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
182185
value->pool = p->pool;
186+
value->size = size;
183187
int crit_ret = critnib_insert(p->hTracker->map, *(uintptr_t *)ptr,
184188
value, 1 /* update */);
185189

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
187191
// nothing to allocate
188192
assert(crit_ret == 0);
189193
(void)crit_ret;
@@ -222,8 +226,14 @@ static umf_result_t trackingAllocationSplit(void *hProvider, void *ptr,
222226
goto err_lock;
223227
}
224228

225-
tracker_value_t *value =
226-
(tracker_value_t *)critnib_get(provider->hTracker->map, (uintptr_t)ptr);
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+
235+
tracker_value_t *value = (tracker_value_t *)critnib_get(
236+
provider->hTracker->map, (uintptr_t)ptr);
227237
if (!value) {
228238
LOG_ERR("region for split is not found in the tracker");
229239
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT;
@@ -243,9 +253,6 @@ static umf_result_t trackingAllocationSplit(void *hProvider, void *ptr,
243253
goto err;
244254
}
245255

246-
void *highPtr = (void *)(((uintptr_t)ptr) + firstSize);
247-
size_t secondSize = totalSize - firstSize;
248-
249256
// We'll have a duplicate entry for the range [highPtr, highValue->size] but this is fine,
250257
// the value is the same anyway and we forbid removing that range concurrently
251258
ret = umfMemoryTrackerAdd(provider->hTracker, provider->pool, highPtr,
@@ -260,6 +267,9 @@ static umf_result_t trackingAllocationSplit(void *hProvider, void *ptr,
260267
goto err;
261268
}
262269

270+
LOG_DEBUG("update split region ptr=%p, pool=%p size=%zu", ptr,
271+
(void *)splitValue->pool, splitValue->size);
272+
263273
int cret = critnib_insert(provider->hTracker->map, (uintptr_t)ptr,
264274
(void *)splitValue, 1 /* update */);
265275
// 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,
303313
tracker_value_t *lowValue = (tracker_value_t *)critnib_get(
304314
provider->hTracker->map, (uintptr_t)lowPtr);
305315
if (!lowValue) {
306-
LOG_ERR("no left value");
316+
LOG_ERR("no left value (%p) found in tracker!", lowPtr);
307317
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT;
308318
goto err;
309319
}
320+
310321
tracker_value_t *highValue = (tracker_value_t *)critnib_get(
311322
provider->hTracker->map, (uintptr_t)highPtr);
312323
if (!highValue) {
313-
LOG_ERR("no right value");
324+
LOG_ERR("no right value (%p) found in tracker!", highPtr);
314325
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT;
315326
goto err;
316327
}
328+
317329
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);
319332
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT;
320333
goto err;
321334
}
335+
322336
if (lowValue->size + highValue->size != totalSize) {
323337
LOG_ERR("lowValue->size + highValue->size != totalSize");
324338
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT;
@@ -355,6 +369,8 @@ static umf_result_t trackingAllocationMerge(void *hProvider, void *lowPtr,
355369

356370
err:
357371
utils_mutex_unlock(&provider->hTracker->splitMergeMutex);
372+
assert(0);
373+
358374
err_lock:
359375
umf_ba_free(provider->hTracker->tracker_allocator, mergedValue);
360376
return ret;
@@ -376,7 +392,7 @@ static umf_result_t trackingFree(void *hProvider, void *ptr, size_t size) {
376392
// DO NOT return an error here, because the tracking provider
377393
// cannot change behaviour of the upstream provider.
378394
LOG_ERR("failed to remove the region from the tracker, ptr=%p, "
379-
"size=%zu, ret = %d",
395+
"size=%zu, ret=%d",
380396
ptr, size, ret_remove);
381397
}
382398
}

0 commit comments

Comments
 (0)