Skip to content

Commit 381d45b

Browse files
committed
add separate tracker for Proxy Lib
1 parent 39d44fa commit 381d45b

16 files changed

+448
-239
lines changed

include/umf/memory_pool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ typedef enum umf_pool_create_flag_t {
3838
UMF_POOL_CREATE_FLAG_DISABLE_TRACKING =
3939
(1 << 1), ///< Pool will not track memory allocations
4040
/// @cond
41+
UMF_POOL_CREATE_FLAG_RESERVED = (1 << 20), ///< Reserved
4142
UMF_POOL_CREATE_FLAG_FORCE_UINT32 = 0x7fffffff
4243
/// @endcond
4344

src/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ set(UMF_SOURCES
125125
critnib/critnib.c
126126
ravl/ravl.c
127127
pool/pool_proxy.c
128-
pool/pool_scalable.c)
128+
pool/pool_scalable.c
129+
tracker.c)
129130

130131
if(NOT UMF_DISABLE_HWLOC)
131132
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 the 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: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
3131
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
3232
}
3333

34+
// NOTE: UMF_POOL_CREATE_FLAG_RESERVED is used when we want to create a
35+
// pool with non-default tracker (passed in params)
36+
37+
if ((flags & UMF_POOL_CREATE_FLAG_DISABLE_TRACKING) &&
38+
(flags & UMF_POOL_CREATE_FLAG_RESERVED)) {
39+
// setting both flags is invalid
40+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
41+
}
42+
43+
if (flags == UMF_POOL_CREATE_FLAG_RESERVED && params == NULL) {
44+
// if UMF_POOL_CREATE_FLAG_RESERVED flag is set the valid tracker
45+
// should be passed in params
46+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
47+
}
48+
3449
umf_result_t ret = UMF_RESULT_SUCCESS;
3550
umf_memory_pool_handle_t pool =
3651
umf_ba_global_alloc(sizeof(umf_memory_pool_t));
@@ -40,12 +55,24 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
4055

4156
assert(ops->version == UMF_VERSION_CURRENT);
4257

58+
umf_memory_tracker_handle_t tracker = NULL;
59+
if (flags == UMF_POOL_CREATE_FLAG_RESERVED) {
60+
// if UMF_POOL_CREATE_FLAG_RESERVED is set use the tracker from params
61+
tracker = params;
62+
}
63+
4364
if (!(flags & UMF_POOL_CREATE_FLAG_DISABLE_TRACKING)) {
44-
// Wrap provider with memory tracking provider.
65+
// Wrap provider with memory tracking provider
66+
if (tracker == NULL) {
67+
// if UMF_POOL_CREATE_FLAG_PROXY_POOL is disabled use the default
68+
// tracker
69+
tracker = umfMemoryTrackerGet();
70+
}
71+
4572
// Check if the provider supports the free() operation.
4673
bool upstreamDoesNotFree = umfIsFreeOpDefault(provider);
4774
ret = umfTrackingMemoryProviderCreate(provider, pool, &pool->provider,
48-
upstreamDoesNotFree);
75+
tracker, upstreamDoesNotFree);
4976
if (ret != UMF_RESULT_SUCCESS) {
5077
goto err_provider_create;
5178
}

0 commit comments

Comments
 (0)