Skip to content

Commit 90b2547

Browse files
committed
coarse provider
1 parent c6d317b commit 90b2547

19 files changed

+2760
-21
lines changed

include/umf/memory_pool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ umf_result_t umfFree(void *ptr);
145145
///
146146
/// * The implementation of this function *should* be lock-free.
147147
/// @param hPool specified memory pool handle for which the last allocation error is returned
148-
/// @return Error code desciribng the failure of the last failed allocation operation.
148+
/// @return Error code describing the failure of the last failed allocation operation.
149149
/// The value is undefined if the previous allocation was successful.
150150
///
151151
umf_result_t umfPoolGetLastAllocationError(umf_memory_pool_handle_t hPool);

include/umf/memory_pool_ops.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extern "C" {
2222
/// calls. Each memory pool implementation should initialize all function
2323
/// pointers.
2424
///
25-
typedef struct umf_memory_pool_ops_t {
25+
struct umf_memory_pool_ops_t {
2626
/// Version of the ops structure.
2727
/// Should be initialized using UMF_VERSION_CURRENT.
2828
uint32_t version;
@@ -120,7 +120,7 @@ typedef struct umf_memory_pool_ops_t {
120120
/// The value is undefined if the previous allocation was successful.
121121
///
122122
umf_result_t (*get_last_allocation_error)(void *pool);
123-
} umf_memory_pool_ops_t;
123+
};
124124

125125
#ifdef __cplusplus
126126
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright (C) 2023-2024 Intel Corporation
2+
// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
3+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
#ifndef UMF_COARSE_PROVIDER_H
6+
#define UMF_COARSE_PROVIDER_H
7+
8+
#include <stdbool.h>
9+
#include <umf/memory_provider.h>
10+
11+
#if defined(__cplusplus)
12+
extern "C" {
13+
#endif
14+
15+
/// @brief Coarse Memory Provider settings struct.
16+
typedef struct coarse_memory_provider_params_t {
17+
/// Handle to the upstream memory provider, could be NULL.
18+
umf_memory_provider_handle_t upstream_memory_provider;
19+
20+
/// When set, the init buffer would be pre-allocated (with
21+
/// `init_buffer_size` bytes) during creation time. The memory used to
22+
/// pre-allocate it would be taken either from the `init_buffer` or from
23+
/// the `upstream_memory_provider`, so either one of them has to be set.
24+
bool immediate_init;
25+
26+
/// Init buffer used to pre-allocate memory at the creation time, could be
27+
/// NULL.
28+
void *init_buffer;
29+
30+
/// Size of the pre-allocated buffer. If the `init_buffer` is set, the
31+
/// `init_buffer_size` should be the size of this buffer.
32+
size_t init_buffer_size;
33+
34+
/// Enable extra tracing (TODO - move to CTL)
35+
bool trace;
36+
37+
/// If this flag is set, the Coarse Provider wouldn't ask the upstream
38+
/// memory provider to free the memory during destruction.
39+
bool WA_do_not_free_upstream;
40+
} coarse_memory_provider_params_t;
41+
42+
/// @brief Coarse Memory Provider stats (TODO move to CTL)
43+
typedef struct coarse_memory_provider_stats_t {
44+
/// Total allocation size.
45+
size_t alloc_size;
46+
47+
/// Size of used memory.
48+
size_t used_size;
49+
50+
/// Number of memory blocks allocated from the upstream provider.
51+
size_t upstream_blocks_num;
52+
53+
/// Total number of allocated memory blocks.
54+
size_t blocks_num;
55+
56+
/// Number of free memory blocks.
57+
size_t free_blocks_num;
58+
} coarse_memory_provider_stats_t;
59+
60+
umf_memory_provider_ops_t *umfCoarseMemoryProviderOps(void);
61+
62+
// TODO use CTL
63+
coarse_memory_provider_stats_t
64+
umfCoarseMemoryProviderGetStats(umf_memory_provider_handle_t provider);
65+
66+
umf_memory_provider_handle_t umfCoarseMemoryProviderGetUpstreamProvider(
67+
umf_memory_provider_handle_t provider);
68+
69+
#ifdef __cplusplus
70+
}
71+
#endif
72+
73+
#endif // UMF_COARSE_PROVIDER_H

scripts/docs_config/api.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ and operate on the provider.
7878
.. doxygenfile:: memory_provider.h
7979
:sections: define enum typedef func var
8080

81+
Coarse Provider
82+
------------------------------------------
83+
84+
A memory provider that should be used as a "cache" for pre-allocated buffer or
85+
with additional upstream provider (e.g. OS Memory Provider).
86+
87+
.. doxygenfile:: provider_coarse.h
88+
:sections: define enum typedef func var
89+
8190
OS Memory Provider
8291
------------------------------------------
8392

src/CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,17 @@ set(BA_SOURCES
5353

5454
set(UMF_SOURCES
5555
${BA_SOURCES}
56+
critnib/critnib.c
5657
memory_pool.c
5758
memory_provider.c
5859
memory_provider_get_last_failed.c
5960
memory_target.c
6061
memspace.c
61-
provider/provider_tracking.c
62-
critnib/critnib.c
6362
pool/pool_proxy.c
63+
provider/provider_coarse.c
64+
provider/provider_os_memory.c
65+
provider/provider_tracking.c
66+
ravl/ravl.c
6467
topology.c)
6568

6669
set(UMF_SOURCES_LINUX libumf_linux.c)
@@ -74,14 +77,13 @@ set(UMF_PUBLIC_COMPILE_DEFINITIONS "")
7477

7578
set(UMF_SOURCES_LINUX
7679
${UMF_SOURCES_LINUX}
77-
provider/provider_os_memory.c
7880
provider/provider_os_memory_linux.c
7981
memory_targets/memory_target_numa.c
8082
memspaces/memspace_numa.c
8183
memspaces/memspace_host_all.c
8284
memspaces/memspace_highest_capacity.c)
8385

84-
set(UMF_SOURCES_WINDOWS ${UMF_SOURCES_WINDOWS} provider/provider_os_memory.c
86+
set(UMF_SOURCES_WINDOWS ${UMF_SOURCES_WINDOWS}
8587
provider/provider_os_memory_windows.c)
8688

8789
set(UMF_LIBS ${UMF_LIBS} ${LIBHWLOC_LIBRARIES})
@@ -157,6 +159,7 @@ target_include_directories(
157159
umf
158160
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
159161
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
162+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/ravl>
160163
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/critnib>
161164
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/provider>
162165
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/memspaces>

src/critnib/critnib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ static struct critnib_leaf *alloc_leaf(struct critnib *__restrict c) {
315315
}
316316

317317
/*
318-
* crinib_insert -- write a key:value pair to the critnib structure
318+
* critnib_insert -- write a key:value pair to the critnib structure
319319
*
320320
* Returns:
321321
* • 0 on success

src/libumf.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ VERSION 1.0
1010

1111
EXPORTS
1212
DllMain
13+
umfCoarseMemoryProviderGetStats
14+
umfCoarseMemoryProviderGetUpstreamProvider
15+
umfCoarseMemoryProviderOps
1316
umfFree
1417
umfGetLastFailedMemoryProvider
1518
umfMemoryProviderAlloc

src/libumf.map

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
UMF_1.0 {
66
global:
7+
umfCoarseMemoryProviderGetStats;
8+
umfCoarseMemoryProviderGetUpstreamProvider;
9+
umfCoarseMemoryProviderOps;
710
umfFree;
811
umfGetLastFailedMemoryProvider;
912
umfLevelZeroMemoryProviderOps;

src/memory_pool_tracking.c

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

10-
#include <assert.h>
11-
#include <stdlib.h>
12-
1310
#include <umf/memory_pool.h>
1411

1512
#include "base_alloc_global.h"

src/memory_target.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212

1313
#include <umf/base.h>
1414

15+
#include "base_alloc.h"
16+
#include "memory_target_ops.h"
17+
1518
#ifdef __cplusplus
1619
extern "C" {
1720
#endif
1821

19-
#include "base_alloc.h"
20-
21-
struct umf_memory_target_ops_t;
22-
typedef struct umf_memory_target_ops_t umf_memory_target_ops_t;
23-
2422
typedef struct umf_memory_target_t {
2523
const umf_memory_target_ops_t *ops;
2624
void *priv;

0 commit comments

Comments
 (0)