Skip to content

add Coarse Memory Provider #378

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

Closed
Closed
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
2 changes: 1 addition & 1 deletion include/umf/memory_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ umf_result_t umfFree(void *ptr);
///
/// * The implementation of this function *should* be lock-free.
/// @param hPool specified memory pool handle for which the last allocation error is returned
/// @return Error code desciribng the failure of the last failed allocation operation.
/// @return Error code describing the failure of the last failed allocation operation.
/// The value is undefined if the previous allocation was successful.
///
umf_result_t umfPoolGetLastAllocationError(umf_memory_pool_handle_t hPool);
Expand Down
4 changes: 2 additions & 2 deletions include/umf/memory_pool_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extern "C" {
/// calls. Each memory pool implementation should initialize all function
/// pointers.
///
typedef struct umf_memory_pool_ops_t {
struct umf_memory_pool_ops_t {
/// Version of the ops structure.
/// Should be initialized using UMF_VERSION_CURRENT.
uint32_t version;
Expand Down Expand Up @@ -120,7 +120,7 @@ typedef struct umf_memory_pool_ops_t {
/// The value is undefined if the previous allocation was successful.
///
umf_result_t (*get_last_allocation_error)(void *pool);
} umf_memory_pool_ops_t;
};

#ifdef __cplusplus
}
Expand Down
73 changes: 73 additions & 0 deletions include/umf/providers/provider_coarse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (C) 2023-2024 Intel Corporation
// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#ifndef UMF_COARSE_PROVIDER_H
#define UMF_COARSE_PROVIDER_H

#include <stdbool.h>
#include <umf/memory_provider.h>

#if defined(__cplusplus)
extern "C" {
#endif

/// @brief Coarse Memory Provider settings struct.
typedef struct coarse_memory_provider_params_t {
/// Handle to the upstream memory provider, could be NULL.
umf_memory_provider_handle_t upstream_memory_provider;

/// When set, the init buffer would be pre-allocated (with
/// `init_buffer_size` bytes) during creation time. The memory used to
/// pre-allocate it would be taken either from the `init_buffer` or from
/// the `upstream_memory_provider`, so either one of them has to be set.
bool immediate_init;

/// Init buffer used to pre-allocate memory at the creation time, could be
/// NULL.
void *init_buffer;

/// Size of the pre-allocated buffer. If the `init_buffer` is set, the
/// `init_buffer_size` should be the size of this buffer.
size_t init_buffer_size;

/// Enable extra tracing (TODO - move to CTL)
bool trace;

/// If this flag is set, the Coarse Provider wouldn't ask the upstream
/// memory provider to free the memory during destruction.
bool WA_do_not_free_upstream;
} coarse_memory_provider_params_t;

/// @brief Coarse Memory Provider stats (TODO move to CTL)
typedef struct coarse_memory_provider_stats_t {
/// Total allocation size.
size_t alloc_size;

/// Size of used memory.
size_t used_size;

/// Number of memory blocks allocated from the upstream provider.
size_t upstream_blocks_num;

/// Total number of allocated memory blocks.
size_t blocks_num;

/// Number of free memory blocks.
size_t free_blocks_num;
} coarse_memory_provider_stats_t;

umf_memory_provider_ops_t *umfCoarseMemoryProviderOps(void);

// TODO use CTL
coarse_memory_provider_stats_t
umfCoarseMemoryProviderGetStats(umf_memory_provider_handle_t provider);

umf_memory_provider_handle_t umfCoarseMemoryProviderGetUpstreamProvider(
umf_memory_provider_handle_t provider);

#ifdef __cplusplus
}
#endif

#endif // UMF_COARSE_PROVIDER_H
9 changes: 9 additions & 0 deletions scripts/docs_config/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ and operate on the provider.
.. doxygenfile:: memory_provider.h
:sections: define enum typedef func var

Coarse Provider
------------------------------------------

A memory provider that should be used as a "cache" for pre-allocated buffer or
with additional upstream provider (e.g. OS Memory Provider).

.. doxygenfile:: provider_coarse.h
:sections: define enum typedef func var

OS Memory Provider
------------------------------------------

Expand Down
11 changes: 7 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@ set(BA_SOURCES
set(UMF_SOURCES
${BA_SOURCES}
ipc.c
critnib/critnib.c
memory_pool.c
memory_provider.c
memory_provider_get_last_failed.c
memory_target.c
memspace.c
provider/provider_tracking.c
critnib/critnib.c
pool/pool_proxy.c
provider/provider_coarse.c
provider/provider_os_memory.c
provider/provider_tracking.c
ravl/ravl.c
topology.c)

set(UMF_SOURCES_LINUX libumf_linux.c)
Expand All @@ -75,14 +78,13 @@ set(UMF_PRIVATE_COMPILE_DEFINITIONS "")

set(UMF_SOURCES_LINUX
${UMF_SOURCES_LINUX}
provider/provider_os_memory.c
provider/provider_os_memory_linux.c
memory_targets/memory_target_numa.c
memspaces/memspace_numa.c
memspaces/memspace_host_all.c
memspaces/memspace_highest_capacity.c)

set(UMF_SOURCES_WINDOWS ${UMF_SOURCES_WINDOWS} provider/provider_os_memory.c
set(UMF_SOURCES_WINDOWS ${UMF_SOURCES_WINDOWS}
provider/provider_os_memory_windows.c)

set(UMF_LIBS ${UMF_LIBS} ${LIBHWLOC_LIBRARIES})
Expand Down Expand Up @@ -157,6 +159,7 @@ target_include_directories(
umf
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/ravl>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/critnib>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/provider>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/memspaces>
Expand Down
2 changes: 1 addition & 1 deletion src/critnib/critnib.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ static struct critnib_leaf *alloc_leaf(struct critnib *__restrict c) {
}

/*
* crinib_insert -- write a key:value pair to the critnib structure
* critnib_insert -- write a key:value pair to the critnib structure
*
* Returns:
* • 0 on success
Expand Down
3 changes: 3 additions & 0 deletions src/libumf.def
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ VERSION 1.0
EXPORTS
DllMain
umfCloseIPCHandle
umfCoarseMemoryProviderGetStats
umfCoarseMemoryProviderGetUpstreamProvider
umfCoarseMemoryProviderOps
umfFree
umfGetIPCHandle
umfGetLastFailedMemoryProvider
Expand Down
3 changes: 3 additions & 0 deletions src/libumf.map
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
UMF_1.0 {
global:
umfCloseIPCHandle;
umfCoarseMemoryProviderGetStats;
umfCoarseMemoryProviderGetUpstreamProvider;
umfCoarseMemoryProviderOps;
umfFree;
umfGetIPCHandle;
umfGetLastFailedMemoryProvider;
Expand Down
8 changes: 3 additions & 5 deletions src/memory_target.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@

#include <umf/base.h>

#include "base_alloc.h"
#include "memory_target_ops.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "base_alloc.h"

struct umf_memory_target_ops_t;
typedef struct umf_memory_target_ops_t umf_memory_target_ops_t;

typedef struct umf_memory_target_t {
const umf_memory_target_ops_t *ops;
void *priv;
Expand Down
2 changes: 0 additions & 2 deletions src/memory_target_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
extern "C" {
#endif

typedef struct umf_memory_target_t *umf_memory_target_handle_t;

typedef struct umf_memory_target_ops_t {
/// Version of the ops structure.
/// Should be initialized using UMF_VERSION_CURRENT
Expand Down
Loading