Skip to content

Commit 1962179

Browse files
committed
add fixed provider
1 parent 9bf1316 commit 1962179

File tree

8 files changed

+744
-5
lines changed

8 files changed

+744
-5
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (C) 2024 Intel Corporation
3+
*
4+
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*/
7+
8+
#ifndef UMF_FIXED_MEMORY_PROVIDER_H
9+
#define UMF_FIXED_MEMORY_PROVIDER_H
10+
11+
#include <umf/providers/provider_os_memory.h>
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
/// @cond
18+
#define UMF_FIXED_RESULTS_START_FROM 4000
19+
/// @endcond
20+
21+
struct umf_fixed_memory_provider_params_t;
22+
23+
typedef struct umf_fixed_memory_provider_params_t
24+
*umf_fixed_memory_provider_params_handle_t;
25+
26+
/// @brief Create a struct to store parameters of the Fixed Memory Provider.
27+
/// @param hParams [out] handle to the newly created parameters struct.
28+
/// @param ptr [in] pointer to the memory region.
29+
/// @param size [in] size of the memory region in bytes.
30+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
31+
umf_result_t umfFixedMemoryProviderParamsCreate(
32+
umf_fixed_memory_provider_params_handle_t *hParams, void *ptr, size_t size);
33+
34+
/// @brief Destroy parameters struct.
35+
/// @param hParams [in] handle to the parameters of the Fixed Memory Provider.
36+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
37+
umf_result_t umfFixedMemoryProviderParamsDestroy(
38+
umf_fixed_memory_provider_params_handle_t hParams);
39+
40+
/// @brief Retrieve the operations structure for the Fixed Memory Provider.
41+
/// @return Pointer to the umf_memory_provider_ops_t structure.
42+
umf_memory_provider_ops_t *umfFixedMemoryProviderOps(void);
43+
44+
/// @brief Fixed Memory Provider operation results
45+
typedef enum umf_fixed_memory_provider_native_error {
46+
UMF_FIXED_RESULT_SUCCESS = UMF_FIXED_RESULTS_START_FROM, ///< Success
47+
UMF_FIXED_RESULT_ERROR_PURGE_FORCE_FAILED, ///< Force purging failed
48+
} umf_fixed_memory_provider_native_error_t;
49+
50+
#ifdef __cplusplus
51+
}
52+
#endif
53+
54+
#endif /* UMF_FIXED_MEMORY_PROVIDER_H */

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ set(UMF_SOURCES
6262
provider/provider_cuda.c
6363
provider/provider_devdax_memory.c
6464
provider/provider_file_memory.c
65+
provider/provider_fixed_memory.c
6566
provider/provider_level_zero.c
6667
provider/provider_os_memory.c
6768
provider/provider_tracking.c

src/coarse/coarse.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,11 @@ umf_result_t coarse_alloc(coarse_t *coarse, size_t size, size_t alignment,
10301030
alignment = ALIGN_UP(alignment, coarse->page_size);
10311031
}
10321032

1033+
if (size + alignment < size) {
1034+
LOG_ERR("size + alignment overflow");
1035+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
1036+
}
1037+
10331038
if (utils_mutex_lock(&coarse->lock) != 0) {
10341039
LOG_ERR("locking the lock failed");
10351040
return UMF_RESULT_ERROR_UNKNOWN;

src/libumf.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ EXPORTS
2525
umfDevDaxMemoryProviderParamsDestroy
2626
umfDevDaxMemoryProviderParamsSetDeviceDax
2727
umfDevDaxMemoryProviderParamsSetProtection
28-
umfFree
2928
umfFileMemoryProviderOps
3029
umfFileMemoryProviderParamsCreate
3130
umfFileMemoryProviderParamsDestroy
3231
umfFileMemoryProviderParamsSetPath
3332
umfFileMemoryProviderParamsSetProtection
3433
umfFileMemoryProviderParamsSetVisibility
34+
umfFixedMemoryProviderOps
35+
umfFixedMemoryProviderParamsCreate
36+
umfFixedMemoryProviderParamsDestroy
37+
umfFree
3538
umfGetIPCHandle
3639
umfGetLastFailedMemoryProvider
3740
umfJemallocPoolOps

src/libumf.map

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ UMF_1.0 {
1919
umfDevDaxMemoryProviderParamsDestroy;
2020
umfDevDaxMemoryProviderParamsSetDeviceDax;
2121
umfDevDaxMemoryProviderParamsSetProtection;
22-
umfFree;
2322
umfFileMemoryProviderOps;
2423
umfFileMemoryProviderParamsCreate;
2524
umfFileMemoryProviderParamsDestroy;
2625
umfFileMemoryProviderParamsSetPath;
2726
umfFileMemoryProviderParamsSetProtection;
2827
umfFileMemoryProviderParamsSetVisibility;
28+
umfFixedMemoryProviderOps;
29+
umfFixedMemoryProviderParamsCreate;
30+
umfFixedMemoryProviderParamsDestroy;
31+
umfFree;
2932
umfGetIPCHandle;
3033
umfGetLastFailedMemoryProvider;
3134
umfJemallocPoolOps;
@@ -81,13 +84,13 @@ UMF_1.0 {
8184
umfOsMemoryProviderOps;
8285
umfOsMemoryProviderParamsCreate;
8386
umfOsMemoryProviderParamsDestroy;
84-
umfOsMemoryProviderParamsSetProtection;
85-
umfOsMemoryProviderParamsSetVisibility;
86-
umfOsMemoryProviderParamsSetShmName;
8787
umfOsMemoryProviderParamsSetNumaList;
8888
umfOsMemoryProviderParamsSetNumaMode;
8989
umfOsMemoryProviderParamsSetPartSize;
9090
umfOsMemoryProviderParamsSetPartitions;
91+
umfOsMemoryProviderParamsSetProtection;
92+
umfOsMemoryProviderParamsSetShmName;
93+
umfOsMemoryProviderParamsSetVisibility;
9194
umfPoolAlignedMalloc;
9295
umfPoolByPtr;
9396
umfPoolCalloc;

0 commit comments

Comments
 (0)