Skip to content

Commit f02e4d0

Browse files
committed
Add file memory provider
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 4f57234 commit f02e4d0

13 files changed

+1099
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,20 @@ Additionally, required for tests:
172172
5) Required packages:
173173
- liblevel-zero-dev (Linux) or level-zero-sdk (Windows)
174174

175+
#### File memory provider (Linux only yet)
176+
177+
A memory provider that provides memory by mapping a regular, extendable file.
178+
179+
The file memory provider does not support the free operation
180+
(`umfMemoryProviderFree()` always returns `UMF_RESULT_ERROR_NOT_SUPPORTED`),
181+
so it should be used with a pool manager that will take over
182+
the managing of the provided memory - for example the jemalloc pool
183+
with the `disable_provider_free` parameter set to true.
184+
185+
##### Requirements
186+
187+
1) Linux OS
188+
175189
### Memory pool managers
176190

177191
#### Proxy pool (part of libumf)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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_FILE_MEMORY_PROVIDER_H
9+
#define UMF_FILE_MEMORY_PROVIDER_H
10+
11+
#include "umf/memory_provider.h"
12+
#include <umf/providers/provider_os_memory.h>
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
/// @cond
19+
#define UMF_FILE_RESULTS_START_FROM 2000
20+
/// @endcond
21+
22+
/// @brief Memory provider settings struct
23+
typedef struct umf_file_memory_provider_params_t {
24+
/// a path to the file
25+
char *path;
26+
/// combination of 'umf_mem_protection_flags_t' flags
27+
unsigned protection;
28+
/// memory visibility mode
29+
umf_memory_visibility_t visibility;
30+
} umf_file_memory_provider_params_t;
31+
32+
/// @brief File Memory Provider operation results
33+
typedef enum umf_file_memory_provider_native_error {
34+
UMF_FILE_RESULT_SUCCESS = UMF_FILE_RESULTS_START_FROM, ///< Success
35+
UMF_FILE_RESULT_ERROR_ALLOC_FAILED, ///< Memory allocation failed
36+
UMF_FILE_RESULT_ERROR_ADDRESS_NOT_ALIGNED, ///< Allocated address is not aligned
37+
UMF_FILE_RESULT_ERROR_FREE_FAILED, ///< Memory deallocation failed
38+
UMF_FILE_RESULT_ERROR_PURGE_LAZY_FAILED, ///< Lazy purging failed
39+
UMF_FILE_RESULT_ERROR_PURGE_FORCE_FAILED, ///< Force purging failed
40+
} umf_file_memory_provider_native_error_t;
41+
42+
umf_memory_provider_ops_t *umfFileMemoryProviderOps(void);
43+
44+
/// @brief Create default params for os memory provider
45+
static inline umf_file_memory_provider_params_t
46+
umfFileMemoryProviderParamsDefault(char *path) {
47+
umf_file_memory_provider_params_t params = {
48+
path, /* a path to the file */
49+
UMF_PROTECTION_READ | UMF_PROTECTION_WRITE, /* protection */
50+
UMF_MEM_MAP_PRIVATE, /* visibility mode */
51+
};
52+
53+
return params;
54+
}
55+
56+
#ifdef __cplusplus
57+
}
58+
#endif
59+
60+
#endif /* UMF_FILE_MEMORY_PROVIDER_H */

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ set(UMF_SOURCES_MACOSX libumf_linux.c)
8989
set(UMF_SOURCES_WINDOWS libumf_windows.c)
9090

9191
set(UMF_SOURCES_COMMON_LINUX_MACOSX
92+
provider/provider_file_memory.c
9293
provider/provider_os_memory.c
9394
provider/provider_os_memory_posix.c
9495
memtargets/memtarget_numa.c

src/libumf.map.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ UMF_1.0 {
5656
umfProxyPoolOps;
5757
umfPutIPCHandle;
5858
umfScalablePoolOps;
59+
umfFileMemoryProviderOps;
5960
@UMF_OPTIONAL_SYMBOLS_LINUX@
6061
local:
6162
*;

0 commit comments

Comments
 (0)