Skip to content

Commit ff7bfa8

Browse files
committed
add separate tracker for Proxy Lib
1 parent 0fc104b commit ff7bfa8

File tree

17 files changed

+478
-251
lines changed

17 files changed

+478
-251
lines changed

include/umf/memory_pool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ typedef enum umf_pool_create_flag_t {
3737
<< 0), ///< Pool will own the specified provider and destroy it in umfPoolDestroy
3838
UMF_POOL_CREATE_FLAG_DISABLE_TRACKING =
3939
(1 << 1), ///< Pool will not track memory allocations
40+
UMF_POOL_CREATE_FLAG_PROXY_POOL = (1 << 2), ///< Reserved for UMF Proxy Pool
4041
/// @cond
4142
UMF_POOL_CREATE_FLAG_FORCE_UINT32 = 0x7fffffff
4243
/// @endcond

src/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ set(UMF_SOURCES
117117
critnib/critnib.c
118118
ravl/ravl.c
119119
pool/pool_proxy.c
120-
pool/pool_scalable.c)
120+
pool/pool_scalable.c
121+
tracker.c)
121122

122123
if(NOT UMF_DISABLE_HWLOC)
123124
set(UMF_SOURCES ${UMF_SOURCES} ${HWLOC_DEPENDENT_SOURCES}

src/libumf.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@
1010
#include <stddef.h>
1111

1212
#include "base_alloc_global.h"
13+
#include "libumf.h"
1314
#include "memspace_internal.h"
14-
#include "provider_tracking.h"
1515
#include "utils_log.h"
1616
#if !defined(UMF_NO_HWLOC)
1717
#include "topology.h"
1818
#endif
1919

2020
umf_memory_tracker_handle_t TRACKER = NULL;
21+
umf_memory_tracker_handle_t umfMemoryTrackerGet() {
22+
// return UMF tracker
23+
return TRACKER;
24+
}
2125

2226
static unsigned long long umfRefCount = 0;
2327

src/libumf.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ EXPORTS
4242
umfMemoryProviderPurgeLazy
4343
umfMemoryProviderPutIPCHandle
4444
umfMemoryTrackerGetAllocInfo
45+
umfMemoryTrackerGetAllocInfoTracker
4546
umfMempolicyCreate
4647
umfMempolicyDestroy
4748
umfMempolicySetCustomSplitPartitions

src/libumf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*
88
*/
99

10+
#include "tracker.h"
11+
1012
#ifndef UMF_LIBUMF_H
1113
#define UMF_LIBUMF_H 1
1214

@@ -17,6 +19,8 @@ extern "C" {
1719
// initializes runtime state needed by the library (needed mostly for static libraries on Windows)
1820
void libumfInit(void);
1921

22+
umf_memory_tracker_handle_t umfMemoryTrackerGet();
23+
2024
#ifdef __cplusplus
2125
}
2226
#endif

src/libumf.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ UMF_1.0 {
3636
umfMemoryProviderPurgeLazy;
3737
umfMemoryProviderPutIPCHandle;
3838
umfMemoryTrackerGetAllocInfo;
39+
umfMemoryTrackerGetAllocInfoTracker;
3940
umfMempolicyCreate;
4041
umfMempolicyDestroy;
4142
umfMempolicySetCustomSplitPartitions;

src/memory_pool.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
3131
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
3232
}
3333

34+
if ((flags & UMF_POOL_CREATE_FLAG_DISABLE_TRACKING) &&
35+
(flags & UMF_POOL_CREATE_FLAG_PROXY_POOL)) {
36+
// setting both flags is invalid
37+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
38+
}
39+
40+
if (flags == UMF_POOL_CREATE_FLAG_PROXY_POOL && params == NULL) {
41+
// if UMF_POOL_CREATE_FLAG_PROXY_POOL flag is set the valid tracker
42+
// should be passed in params
43+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
44+
}
45+
3446
umf_result_t ret = UMF_RESULT_SUCCESS;
3547
umf_memory_pool_handle_t pool =
3648
umf_ba_global_alloc(sizeof(umf_memory_pool_t));
@@ -40,12 +52,25 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
4052

4153
assert(ops->version == UMF_VERSION_CURRENT);
4254

55+
umf_memory_tracker_handle_t tracker = NULL;
56+
if (flags == UMF_POOL_CREATE_FLAG_PROXY_POOL) {
57+
// if UMF_POOL_CREATE_FLAG_PROXY_POOL is set use the tracker from
58+
// params
59+
tracker = params;
60+
}
61+
4362
if (!(flags & UMF_POOL_CREATE_FLAG_DISABLE_TRACKING)) {
44-
// Wrap provider with memory tracking provider.
63+
// Wrap provider with memory tracking provider
64+
if (tracker == NULL) {
65+
// if UMF_POOL_CREATE_FLAG_PROXY_POOL is disabled use the default
66+
// tracker
67+
tracker = umfMemoryTrackerGet();
68+
}
69+
4570
// Check if the provider supports the free() operation.
4671
bool upstreamDoesNotFree = umfIsFreeOpDefault(provider);
4772
ret = umfTrackingMemoryProviderCreate(provider, pool, &pool->provider,
48-
upstreamDoesNotFree);
73+
tracker, upstreamDoesNotFree);
4974
if (ret != UMF_RESULT_SUCCESS) {
5075
goto err_provider_create;
5176
}

0 commit comments

Comments
 (0)