Skip to content

Commit 85b1d6f

Browse files
authored
Merge pull request #680 from ldorau/Add_file_memory_provider
Add file memory provider
2 parents e6356a7 + 4603b7e commit 85b1d6f

21 files changed

+1318
-7
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ if(NOT UMF_DISABLE_HWLOC)
421421
add_optional_symbol(umfOsMemoryProviderOps)
422422
if(LINUX)
423423
add_optional_symbol(umfDevDaxMemoryProviderOps)
424+
add_optional_symbol(umfFileMemoryProviderOps)
424425
endif()
425426
endif()
426427

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,21 @@ with the `disable_provider_free` parameter set to true.
188188
1) Linux OS
189189
2) A character device file /dev/daxX.Y created in the OS.
190190

191+
#### File memory provider (Linux only yet)
192+
193+
A memory provider that provides memory by mapping a regular, extendable file.
194+
195+
The file memory provider does not support the free operation
196+
(`umfMemoryProviderFree()` always returns `UMF_RESULT_ERROR_NOT_SUPPORTED`),
197+
so it should be used with a pool manager that will take over
198+
the managing of the provided memory - for example the jemalloc pool
199+
with the `disable_provider_free` parameter set to true.
200+
201+
##### Requirements
202+
203+
1) Linux OS
204+
2) A length of a path of a file to be mapped can be `PATH_MAX` (4096) characters at most.
205+
191206
### Memory pool managers
192207

193208
#### Proxy pool (part of libumf)
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 (of maximum length PATH_MAX characters)
24+
const 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(const 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

+8
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ A memory provider that provides memory from a device DAX (a character device fil
104104
.. doxygenfile:: provider_devdax_memory.h
105105
:sections: define enum typedef func var
106106

107+
File Memory Provider
108+
------------------------------------------
109+
110+
A memory provider that provides memory by mapping a regular, extendable file.
111+
112+
.. doxygenfile:: provider_file_memory.h
113+
:sections: define enum typedef func var
114+
107115
Memspace
108116
==========================================
109117

src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ set(UMF_SOURCES_WINDOWS libumf_windows.c)
102102

103103
set(UMF_SOURCES_COMMON_LINUX_MACOSX
104104
provider/provider_devdax_memory.c
105+
provider/provider_file_memory.c
105106
provider/provider_os_memory.c
106107
provider/provider_os_memory_posix.c
107108
memtargets/memtarget_numa.c

0 commit comments

Comments
 (0)