Skip to content

Commit 2d814df

Browse files
committed
improve debug messages
1 parent 4e1e2e0 commit 2d814df

File tree

1 file changed

+43
-27
lines changed

1 file changed

+43
-27
lines changed

src/provider/provider_tracking.c

Lines changed: 43 additions & 27 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,22 +168,25 @@ 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
tracker_value_t *value =
172176
(tracker_value_t *)critnib_get(p->hTracker->map, *(uintptr_t *)ptr);
173177
if (value) {
174178
assert(value->pool != p->pool);
179+
LOG_ERR("ptr already exists in the tracker ptr=%p, old size=%zu, new "
180+
"size=%zu, old pool %p, new pool %p, tracker %p",
181+
*ptr, value->size, size, (void *)value->pool, (void *)p->pool,
182+
(void *)p->hTracker);
175183

176-
LOG_DEBUG("ptr already exists in the tracker (added by Proxy Lib) - "
177-
"updating value, ptr=%p, size=%zu, old pool: %p, new pool %p",
178-
*ptr, size, (void *)value->pool, (void *)p->pool);
179-
180-
// the allocation was made by the ProxyLib so we only update the tracker
181184
value->pool = p->pool;
185+
value->size = size;
182186
int crit_ret = critnib_insert(p->hTracker->map, *(uintptr_t *)ptr,
183187
value, 1 /* update */);
184188

185-
// this cannot fail since we know the element exists and there is
189+
// this cannot fail since we know the element exists and there is
186190
// nothing to allocate
187191
assert(crit_ret == 0);
188192
(void)crit_ret;
@@ -221,6 +225,12 @@ static umf_result_t trackingAllocationSplit(void *hProvider, void *ptr,
221225
goto err_lock;
222226
}
223227

228+
void *highPtr = (void *)(((uintptr_t)ptr) + firstSize);
229+
size_t secondSize = totalSize - firstSize;
230+
231+
LOG_DEBUG("trying to split (%p, %zu) to (%p, %zu) and (%p, %zu)", ptr,
232+
totalSize, ptr, firstSize, highPtr, secondSize);
233+
224234
tracker_value_t *value =
225235
(tracker_value_t *)critnib_get(provider->hTracker->map, (uintptr_t)ptr);
226236
if (!value) {
@@ -242,9 +252,6 @@ static umf_result_t trackingAllocationSplit(void *hProvider, void *ptr,
242252
goto err;
243253
}
244254

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

269+
LOG_DEBUG("update split region ptr=%p, pool=%p size=%zu", ptr,
270+
(void *)splitValue->pool, splitValue->size);
271+
262272
int cret = critnib_insert(provider->hTracker->map, (uintptr_t)ptr,
263273
(void *)splitValue, 1 /* update */);
264274
// this cannot fail since we know the element exists (nothing to allocate)
@@ -302,22 +312,26 @@ static umf_result_t trackingAllocationMerge(void *hProvider, void *lowPtr,
302312
tracker_value_t *lowValue = (tracker_value_t *)critnib_get(
303313
provider->hTracker->map, (uintptr_t)lowPtr);
304314
if (!lowValue) {
305-
LOG_ERR("no left value");
315+
LOG_ERR("no left value (%p) found in tracker!", lowPtr);
306316
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT;
307317
goto err;
308318
}
319+
309320
tracker_value_t *highValue = (tracker_value_t *)critnib_get(
310321
provider->hTracker->map, (uintptr_t)highPtr);
311322
if (!highValue) {
312-
LOG_ERR("no right value");
323+
LOG_ERR("no right value (%p) found in tracker!", highPtr);
313324
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT;
314325
goto err;
315326
}
327+
316328
if (lowValue->pool != highValue->pool) {
317-
LOG_ERR("pool mismatch");
329+
LOG_ERR("pool mismatch: %p vs %p", (void *)lowValue->pool,
330+
(void *)highValue->pool);
318331
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT;
319332
goto err;
320333
}
334+
321335
if (lowValue->size + highValue->size != totalSize) {
322336
LOG_ERR("lowValue->size + highValue->size != totalSize");
323337
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT;
@@ -354,6 +368,8 @@ static umf_result_t trackingAllocationMerge(void *hProvider, void *lowPtr,
354368

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

0 commit comments

Comments
 (0)