Skip to content

Commit 0cf6cd4

Browse files
committed
enable tracker in ProxyLib by default
1 parent 2f790a0 commit 0cf6cd4

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

.github/workflows/proxy_lib.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858

5959
- name: Run "ctest --output-on-failure" with proxy library
6060
working-directory: ${{env.BUILD_DIR}}
61-
run: LD_PRELOAD=./lib/libumf_proxy.so ctest --output-on-failure
61+
run: LD_PRELOAD=./lib/libumf_proxy.so ctest --output-on-failure -E "proxy_lib_memoryPool"
6262

6363
- name: Run "./test/umf_test-memoryPool" with proxy library
6464
working-directory: ${{env.BUILD_DIR}}

src/provider/provider_tracking.c

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ static umf_result_t umfMemoryTrackerAdd(umf_memory_tracker_handle_t hTracker,
4848
int ret = critnib_insert(hTracker->map, (uintptr_t)ptr, value, 0);
4949

5050
if (ret == 0) {
51-
LOG_DEBUG("memory region is added, tracker=%p, ptr=%p, size=%zu",
52-
(void *)hTracker, ptr, size);
51+
LOG_DEBUG(
52+
"memory region is added, tracker=%p, ptr=%p, pool=%p, size=%zu",
53+
(void *)hTracker, ptr, (void *)pool, size);
5354
return UMF_RESULT_SUCCESS;
5455
}
5556

56-
LOG_ERR("failed to insert tracker value, ret=%d, ptr=%p, size=%zu", ret,
57-
ptr, size);
57+
LOG_ERR("failed to insert tracker value, ret=%d, ptr=%p, pool=%p, size=%zu",
58+
ret, ptr, (void *)pool, size);
5859

5960
umf_ba_free(hTracker->tracker_allocator, value);
6061

@@ -161,11 +162,35 @@ static umf_result_t trackingAlloc(void *hProvider, size_t size,
161162
return ret;
162163
}
163164

164-
umf_result_t ret2 = umfMemoryTrackerAdd(p->hTracker, p->pool, *ptr, size);
165-
if (ret2 != UMF_RESULT_SUCCESS) {
166-
LOG_ERR("failed to add allocated region to the tracker, ptr = %p, size "
165+
// check if the allocation was already added to the tracker
166+
// (in case of using ProxyLib)
167+
tracker_value_t *value =
168+
(tracker_value_t *)critnib_get(p->hTracker->map, *(uintptr_t *)ptr);
169+
if (value) {
170+
assert(value->pool != p->pool);
171+
172+
LOG_DEBUG("ptr already exists in the tracker (added by Proxy Lib) - "
173+
"updating value, ptr=%p, size=%zu, old pool: %p, new pool %p",
174+
*ptr, size, (void *)value->pool, (void *)p->pool);
175+
176+
// the allocation was made by the ProxyLib so we only update the tracker
177+
value->pool = p->pool;
178+
int crit_ret = critnib_insert(p->hTracker->map, *(uintptr_t *)ptr,
179+
value, 1 /* update */);
180+
181+
// this cannot fail since we know the element exists and there is
182+
// nothing to allocate
183+
assert(crit_ret == 0);
184+
(void)crit_ret;
185+
} else {
186+
umf_result_t ret2 =
187+
umfMemoryTrackerAdd(p->hTracker, p->pool, *ptr, size);
188+
if (ret2 != UMF_RESULT_SUCCESS) {
189+
LOG_ERR(
190+
"failed to add allocated region to the tracker, ptr = %p, size "
167191
"= %zu, ret = %d",
168192
*ptr, size, ret2);
193+
}
169194
}
170195

171196
return ret;

src/proxy_lib/proxy_lib.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ void proxy_lib_create_common(void) {
124124

125125
} else if (utils_env_var_has_str("UMF_PROXY",
126126
"page.disposition=shared-shm")) {
127-
LOG_DEBUG("proxy_lib: using the MAP_SHARED visibility mode with the "
128-
"named shared memory");
129127
os_params.visibility = UMF_MEM_MAP_SHARED;
130128

131129
memset(shm_name, 0, NAME_MAX);
@@ -145,9 +143,8 @@ void proxy_lib_create_common(void) {
145143
exit(-1);
146144
}
147145

148-
umf_result =
149-
umfPoolCreate(umfPoolManagerOps(), OS_memory_provider, NULL,
150-
UMF_POOL_CREATE_FLAG_DISABLE_TRACKING, &Proxy_pool);
146+
umf_result = umfPoolCreate(umfPoolManagerOps(), OS_memory_provider, NULL, 0,
147+
&Proxy_pool);
151148
if (umf_result != UMF_RESULT_SUCCESS) {
152149
LOG_ERR("creating UMF pool manager failed");
153150
exit(-1);

0 commit comments

Comments
 (0)