Skip to content

add set name to all pools and providers #1445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/umf/pools/pool_disjoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ umf_result_t umfDisjointPoolParamsSetSharedLimits(

/// @brief Set custom name of the disjoint pool to be used in the traces.
/// @param hParams handle to the parameters of the disjoint pool.
/// @param name custom name of the pool. Name longer than 64 characters will be truncated.
/// @param name custom name of the pool. Must not be NULL. Name longer than 63
/// characters will be truncated.
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
umf_result_t
umfDisjointPoolParamsSetName(umf_disjoint_pool_params_handle_t hParams,
Expand Down
9 changes: 9 additions & 0 deletions include/umf/pools/pool_jemalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ umf_result_t
umfJemallocPoolParamsSetNumArenas(umf_jemalloc_pool_params_handle_t hParams,
size_t numArenas);

/// @brief Set custom name of the jemalloc pool used in traces.
/// @param hParams handle to the parameters of the jemalloc pool.
/// @param name custom name. Must not be NULL. Name longer than 63 characters
/// will be truncated.
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
umf_result_t
umfJemallocPoolParamsSetName(umf_jemalloc_pool_params_handle_t hParams,
const char *name);

const umf_memory_pool_ops_t *umfJemallocPoolOps(void);

#ifdef __cplusplus
Expand Down
9 changes: 9 additions & 0 deletions include/umf/pools/pool_scalable.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ umf_result_t
umfScalablePoolParamsSetKeepAllMemory(umf_scalable_pool_params_handle_t hParams,
bool keepAllMemory);

/// @brief Set custom name of the scalable pool used in traces.
/// @param hParams handle to the parameters of the scalable pool.
/// @param name custom name. Must not be NULL. Name longer than 63 characters
/// will be truncated.
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
umf_result_t
umfScalablePoolParamsSetName(umf_scalable_pool_params_handle_t hParams,
const char *name);

/// @brief Return \p ops structure containing pointers to the scalable pool implementation.
/// @return pointer to the \p umf_memory_pool_ops_t struct.
const umf_memory_pool_ops_t *umfScalablePoolOps(void);
Expand Down
8 changes: 8 additions & 0 deletions include/umf/providers/provider_cuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ umf_result_t umfCUDAMemoryProviderParamsSetMemoryType(
umf_result_t umfCUDAMemoryProviderParamsSetAllocFlags(
umf_cuda_memory_provider_params_handle_t hParams, unsigned int flags);

/// @brief Set custom name of the CUDA Memory Provider.
/// @param hParams handle to the parameters of the CUDA Memory Provider.
/// @param name custom name. Must not be NULL. Name longer than 63 characters
/// will be truncated.
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
umf_result_t umfCUDAMemoryProviderParamsSetName(
umf_cuda_memory_provider_params_handle_t hParams, const char *name);

const umf_memory_provider_ops_t *umfCUDAMemoryProviderOps(void);

#ifdef __cplusplus
Expand Down
8 changes: 8 additions & 0 deletions include/umf/providers/provider_devdax_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ umf_result_t umfDevDaxMemoryProviderParamsSetDeviceDax(
umf_result_t umfDevDaxMemoryProviderParamsSetProtection(
umf_devdax_memory_provider_params_handle_t hParams, unsigned protection);

/// @brief Set custom name of the Devdax Memory Provider.
/// @param hParams [in] handle to the parameters of the Devdax Memory Provider.
/// @param name [in] custom name. Must not be NULL. Name longer than 63 characters
/// will be truncated.
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
umf_result_t umfDevDaxMemoryProviderParamsSetName(
umf_devdax_memory_provider_params_handle_t hParams, const char *name);

/// @brief Devdax Memory Provider operation results
typedef enum umf_devdax_memory_provider_native_error {
UMF_DEVDAX_RESULT_SUCCESS = UMF_DEVDAX_RESULTS_START_FROM, ///< Success
Expand Down
8 changes: 8 additions & 0 deletions include/umf/providers/provider_file_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ typedef enum umf_file_memory_provider_native_error {

const umf_memory_provider_ops_t *umfFileMemoryProviderOps(void);

/// @brief Set custom name of the File Memory Provider.
/// @param hParams handle to the parameters of the File Memory Provider.
/// @param name custom name. Must not be NULL. Name longer than 63 characters
/// will be truncated.
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
umf_result_t umfFileMemoryProviderParamsSetName(
umf_file_memory_provider_params_handle_t hParams, const char *name);

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 8 additions & 0 deletions include/umf/providers/provider_fixed_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ umf_result_t umfFixedMemoryProviderParamsDestroy(
/// @return Pointer to the umf_memory_provider_ops_t structure.
const umf_memory_provider_ops_t *umfFixedMemoryProviderOps(void);

/// @brief Set custom name of the Fixed Memory Provider.
/// @param hParams [in] handle to the parameters of the Fixed Memory Provider.
/// @param name [in] custom name. Must not be NULL. Name longer than 63 characters
/// will be truncated.
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
umf_result_t umfFixedMemoryProviderParamsSetName(
umf_fixed_memory_provider_params_handle_t hParams, const char *name);

/// @brief Fixed Memory Provider operation results
typedef enum umf_fixed_memory_provider_native_error {
UMF_FIXED_RESULT_SUCCESS = UMF_FIXED_RESULTS_START_FROM, ///< Success
Expand Down
8 changes: 8 additions & 0 deletions include/umf/providers/provider_level_zero.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ umf_result_t umfLevelZeroMemoryProviderParamsSetDeviceOrdinal(
umf_level_zero_memory_provider_params_handle_t hParams,
uint32_t deviceOrdinal);

/// @brief Set custom name of the Level Zero Memory Provider.
/// @param hParams handle to the parameters of the Level Zero Memory Provider.
/// @param name custom name. Must not be NULL. Name longer than 63 characters
/// will be truncated.
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
umf_result_t umfLevelZeroMemoryProviderParamsSetName(
umf_level_zero_memory_provider_params_handle_t hParams, const char *name);

const umf_memory_provider_ops_t *umfLevelZeroMemoryProviderOps(void);

#ifdef __cplusplus
Expand Down
9 changes: 9 additions & 0 deletions include/umf/providers/provider_os_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ umf_result_t umfOsMemoryProviderParamsSetPartitions(
umf_os_memory_provider_params_handle_t hParams,
umf_numa_split_partition_t *partitions, unsigned partitions_len);

/// @brief Set custom name of the OS memory provider.
/// @param hParams handle to the parameters of the OS memory provider.
/// @param name custom name. Must not be NULL. Name longer than 63 characters
/// will be truncated.
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
umf_result_t
umfOsMemoryProviderParamsSetName(umf_os_memory_provider_params_handle_t hParams,
const char *name);

/// @brief OS Memory Provider operation results
typedef enum umf_os_memory_provider_native_error {
UMF_OS_RESULT_SUCCESS = UMF_OS_RESULTS_START_FROM, ///< Success
Expand Down
9 changes: 9 additions & 0 deletions src/libumf.def
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,12 @@ EXPORTS
umfJemallocPoolParamsDestroy
umfJemallocPoolParamsSetNumArenas
umfPoolGetName
; Added in UMF_1.1
umfCUDAMemoryProviderParamsSetName
umfDevDaxMemoryProviderParamsSetName
umfFileMemoryProviderParamsSetName
umfFixedMemoryProviderParamsSetName
umfJemallocPoolParamsSetName
umfLevelZeroMemoryProviderParamsSetName
umfOsMemoryProviderParamsSetName
umfScalablePoolParamsSetName
11 changes: 11 additions & 0 deletions src/libumf.map
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,14 @@ UMF_1.0 {
local:
*;
};

UMF_1.1 {
umfCUDAMemoryProviderParamsSetName;
umfDevDaxMemoryProviderParamsSetName;
umfFileMemoryProviderParamsSetName;
umfFixedMemoryProviderParamsSetName;
umfJemallocPoolParamsSetName;
umfLevelZeroMemoryProviderParamsSetName;
umfOsMemoryProviderParamsSetName;
umfScalablePoolParamsSetName;
} UMF_1.0;
50 changes: 48 additions & 2 deletions src/pool/pool_jemalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,30 @@ umfJemallocPoolParamsSetNumArenas(umf_jemalloc_pool_params_handle_t hParams,
return UMF_RESULT_ERROR_NOT_SUPPORTED;
}

umf_result_t
umfJemallocPoolParamsSetName(umf_jemalloc_pool_params_handle_t hParams,
const char *name) {
(void)hParams; // unused
(void)name; // unused
return UMF_RESULT_ERROR_NOT_SUPPORTED;
}

#else

#include <jemalloc/jemalloc.h>

#define MALLOCX_ARENA_MAX (MALLCTL_ARENAS_ALL - 1)
#define DEFAULT_NAME "jemalloc"

typedef struct umf_jemalloc_pool_params_t {
size_t n_arenas;
char name[64];
} umf_jemalloc_pool_params_t;

typedef struct jemalloc_memory_pool_t {
umf_memory_provider_handle_t provider;
size_t n_arenas;
char name[64];
unsigned int arena_index[];
} jemalloc_memory_pool_t;

Expand Down Expand Up @@ -459,6 +470,13 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
if (!pool) {
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
memset(pool, 0, sizeof(*pool) + n_arenas * sizeof(*pool->arena_index));
const char *pool_name = DEFAULT_NAME;
if (jemalloc_params) {
pool_name = jemalloc_params->name;
}

snprintf(pool->name, sizeof(pool->name), "%s", pool_name);

pool->provider = provider;
pool->n_arenas = n_arenas;
Expand Down Expand Up @@ -558,8 +576,15 @@ static umf_result_t op_get_last_allocation_error(void *pool) {
}

static umf_result_t op_get_name(void *pool, const char **name) {
(void)pool;
*name = "jemalloc";
if (!name) {
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}
if (pool == NULL) {
*name = DEFAULT_NAME;
return UMF_RESULT_SUCCESS;
}
jemalloc_memory_pool_t *je_pool = (jemalloc_memory_pool_t *)pool;
*name = je_pool->name;
return UMF_RESULT_SUCCESS;
}

Expand Down Expand Up @@ -588,6 +613,8 @@ umfJemallocPoolParamsCreate(umf_jemalloc_pool_params_handle_t *hParams) {
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
memset(params, 0, sizeof(*params));
strncpy(params->name, DEFAULT_NAME, sizeof(params->name) - 1);
params->name[sizeof(params->name) - 1] = '\0';
*hParams = params;
return UMF_RESULT_SUCCESS;
}
Expand All @@ -609,4 +636,23 @@ umfJemallocPoolParamsSetNumArenas(umf_jemalloc_pool_params_handle_t hParams,
return UMF_RESULT_SUCCESS;
}

umf_result_t
umfJemallocPoolParamsSetName(umf_jemalloc_pool_params_handle_t hParams,
const char *name) {
if (!hParams) {
LOG_ERR("jemalloc pool params handle is NULL");
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

if (!name) {
LOG_ERR("name is NULL");
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

strncpy(hParams->name, name, sizeof(hParams->name) - 1);
hParams->name[sizeof(hParams->name) - 1] = '\0';

return UMF_RESULT_SUCCESS;
}

#endif /* UMF_POOL_JEMALLOC_ENABLED */
39 changes: 37 additions & 2 deletions src/pool/pool_scalable.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static __TLS umf_result_t TLS_last_allocation_error;
static __TLS umf_result_t TLS_last_free_error;

static const size_t DEFAULT_GRANULARITY = 2 * 1024 * 1024; // 2MB
static const char *DEFAULT_NAME = "scalable";

typedef struct tbb_mem_pool_policy_t {
raw_alloc_tbb_type pAlloc;
Expand All @@ -48,6 +49,7 @@ typedef struct tbb_mem_pool_policy_t {
typedef struct umf_scalable_pool_params_t {
size_t granularity;
bool keep_all_memory;
char name[64];
} umf_scalable_pool_params_t;

typedef struct tbb_callbacks_t {
Expand All @@ -70,6 +72,7 @@ typedef struct tbb_callbacks_t {
typedef struct tbb_memory_pool_t {
umf_memory_provider_handle_t mem_provider;
void *tbb_pool;
char name[64];
} tbb_memory_pool_t;

typedef enum tbb_enums_t {
Expand Down Expand Up @@ -216,6 +219,8 @@ umfScalablePoolParamsCreate(umf_scalable_pool_params_handle_t *hParams) {

params_data->granularity = DEFAULT_GRANULARITY;
params_data->keep_all_memory = false;
strncpy(params_data->name, DEFAULT_NAME, sizeof(params_data->name) - 1);
params_data->name[sizeof(params_data->name) - 1] = '\0';

*hParams = (umf_scalable_pool_params_handle_t)params_data;

Expand Down Expand Up @@ -265,6 +270,25 @@ umfScalablePoolParamsSetKeepAllMemory(umf_scalable_pool_params_handle_t hParams,
return UMF_RESULT_SUCCESS;
}

umf_result_t
umfScalablePoolParamsSetName(umf_scalable_pool_params_handle_t hParams,
const char *name) {
if (!hParams) {
LOG_ERR("scalable pool params handle is NULL");
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

if (!name) {
LOG_ERR("name is NULL");
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

strncpy(hParams->name, name, sizeof(hParams->name) - 1);
hParams->name[sizeof(hParams->name) - 1] = '\0';

return UMF_RESULT_SUCCESS;
}

static umf_result_t tbb_pool_initialize(umf_memory_provider_handle_t provider,
const void *params, void **pool) {
tbb_mem_pool_policy_t policy = {.pAlloc = tbb_raw_alloc_wrapper,
Expand All @@ -275,11 +299,13 @@ static umf_result_t tbb_pool_initialize(umf_memory_provider_handle_t provider,
.keep_all_memory = false,
.reserved = 0};

const char *pool_name = DEFAULT_NAME;
// If params is provided, override defaults
if (params) {
const umf_scalable_pool_params_t *scalable_params = params;
policy.granularity = scalable_params->granularity;
policy.keep_all_memory = scalable_params->keep_all_memory;
pool_name = scalable_params->name;
}

tbb_memory_pool_t *pool_data =
Expand All @@ -288,6 +314,8 @@ static umf_result_t tbb_pool_initialize(umf_memory_provider_handle_t provider,
LOG_ERR("cannot allocate memory for metadata");
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
memset(pool_data, 0, sizeof(*pool_data));
snprintf(pool_data->name, sizeof(pool_data->name), "%s", pool_name);

umf_result_t res = UMF_RESULT_SUCCESS;
int ret = init_tbb_callbacks();
Expand Down Expand Up @@ -433,8 +461,15 @@ static umf_result_t pool_ctl(void *hPool, umf_ctl_query_source_t operationType,
}

static umf_result_t scalable_get_name(void *pool, const char **name) {
(void)pool; // unused
*name = "scalable";
if (!name) {
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}
if (pool == NULL) {
*name = DEFAULT_NAME;
return UMF_RESULT_SUCCESS;
}
tbb_memory_pool_t *pool_data = (tbb_memory_pool_t *)pool;
*name = pool_data->name;
return UMF_RESULT_SUCCESS;
}

Expand Down
Loading