Skip to content

Commit cbe3b9f

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

18 files changed

+1219
-3
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@ endif()
419419

420420
if(NOT UMF_DISABLE_HWLOC)
421421
add_optional_symbol(umfOsMemoryProviderOps)
422+
if(LINUX)
423+
add_optional_symbol(umfFileMemoryProviderOps)
424+
endif()
422425
endif()
423426

424427
add_subdirectory(src)

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,21 @@ 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+
2) A length of a path of a file to be mapped can be `PATH_MAX` (4096) characters at most.
189+
175190
### Memory pool managers
176191

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

scripts/docs_config/api.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ A memory provider that provides memory from L0 device.
9696
.. doxygenfile:: provider_level_zero.h
9797
:sections: define enum typedef func var
9898

99+
File Memory Provider
100+
------------------------------------------
101+
102+
A memory provider that provides memory by mapping a regular, extendable file.
103+
104+
.. doxygenfile:: provider_file_memory.h
105+
:sections: define enum typedef func var
106+
99107
Memspace
100108
==========================================
101109

src/CMakeLists.txt

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

103103
set(UMF_SOURCES_COMMON_LINUX_MACOSX
104+
provider/provider_file_memory.c
104105
provider/provider_os_memory.c
105106
provider/provider_os_memory_posix.c
106107
memtargets/memtarget_numa.c

0 commit comments

Comments
 (0)