Skip to content

Commit 34f4893

Browse files
authored
Merge pull request #728 from ldorau/Move_common_functions_to_utils_common
Move common functions to utils common
2 parents 6464f5a + b1e1edb commit 34f4893

18 files changed

+636
-611
lines changed

include/umf/memory_provider.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@
1717
extern "C" {
1818
#endif
1919

20+
/// @brief Memory visibility mode
21+
typedef enum umf_memory_visibility_t {
22+
UMF_MEM_MAP_PRIVATE = 1, ///< private memory mapping
23+
UMF_MEM_MAP_SHARED, ///< shared memory mapping (supported on Linux only)
24+
} umf_memory_visibility_t;
25+
26+
/// @brief Protection of the memory allocations
27+
typedef enum umf_mem_protection_flags_t {
28+
UMF_PROTECTION_NONE = (1 << 0), ///< Memory allocations can not be accessed
29+
UMF_PROTECTION_READ = (1 << 1), ///< Memory allocations can be read.
30+
UMF_PROTECTION_WRITE = (1 << 2), ///< Memory allocations can be written.
31+
UMF_PROTECTION_EXEC = (1 << 3), ///< Memory allocations can be executed.
32+
/// @cond
33+
UMF_PROTECTION_MAX // must be the last one
34+
/// @endcond
35+
} umf_mem_protection_flags_t;
36+
2037
/// @brief A struct containing memory provider specific set of functions
2138
typedef struct umf_memory_provider_t *umf_memory_provider_handle_t;
2239

include/umf/providers/provider_os_memory.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,6 @@ extern "C" {
1818
#define UMF_OS_RESULTS_START_FROM 1000
1919
/// @endcond
2020

21-
/// @brief Protection of the memory allocations
22-
typedef enum umf_mem_protection_flags_t {
23-
UMF_PROTECTION_NONE = (1 << 0), ///< Memory allocations can not be accessed
24-
UMF_PROTECTION_READ = (1 << 1), ///< Memory allocations can be read.
25-
UMF_PROTECTION_WRITE = (1 << 2), ///< Memory allocations can be written.
26-
UMF_PROTECTION_EXEC = (1 << 3), ///< Memory allocations can be executed.
27-
/// @cond
28-
UMF_PROTECTION_MAX // must be the last one
29-
/// @endcond
30-
} umf_mem_protection_flags_t;
31-
32-
/// @brief Memory visibility mode
33-
typedef enum umf_memory_visibility_t {
34-
UMF_MEM_MAP_PRIVATE = 1, ///< private memory mapping
35-
UMF_MEM_MAP_SHARED, ///< shared memory mapping (supported on Linux only)
36-
} umf_memory_visibility_t;
37-
3821
/// @brief Memory binding mode
3922
/// Specifies how memory is bound to NUMA nodes on systems that support NUMA.
4023
/// Not every mode is supported on every system.

src/CMakeLists.txt

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ set(UMF_SOURCES_COMMON_LINUX_MACOSX
130130
provider/provider_devdax_memory.c
131131
provider/provider_file_memory.c
132132
provider/provider_os_memory.c
133-
provider/provider_os_memory_posix.c
134133
memtargets/memtarget_numa.c
135134
memspaces/memspace_numa.c
136135
memspaces/memspace_host_all.c
@@ -139,17 +138,14 @@ set(UMF_SOURCES_COMMON_LINUX_MACOSX
139138
memspaces/memspace_lowest_latency.c)
140139

141140
if(NOT UMF_DISABLE_HWLOC)
142-
set(UMF_SOURCES_LINUX
143-
${UMF_SOURCES_LINUX} ${UMF_SOURCES_COMMON_LINUX_MACOSX}
144-
provider/provider_os_memory_linux.c)
141+
set(UMF_SOURCES_LINUX ${UMF_SOURCES_LINUX}
142+
${UMF_SOURCES_COMMON_LINUX_MACOSX})
145143

146-
set(UMF_SOURCES_MACOSX
147-
${UMF_SOURCES_MACOSX} ${UMF_SOURCES_COMMON_LINUX_MACOSX}
148-
provider/provider_os_memory_macosx.c)
144+
set(UMF_SOURCES_MACOSX ${UMF_SOURCES_MACOSX}
145+
${UMF_SOURCES_COMMON_LINUX_MACOSX})
149146

150-
set(UMF_SOURCES_WINDOWS
151-
${UMF_SOURCES_WINDOWS} provider/provider_os_memory.c
152-
provider/provider_os_memory_windows.c)
147+
set(UMF_SOURCES_WINDOWS ${UMF_SOURCES_WINDOWS}
148+
provider/provider_os_memory.c)
153149

154150
set(UMF_LIBS ${UMF_LIBS} ${LIBHWLOC_LIBRARIES})
155151

@@ -180,7 +176,7 @@ set(UMF_PRIVATE_LIBRARY_DIRS ${UMF_PRIVATE_LIBRARY_DIRS}
180176

181177
if(LINUX)
182178
set(UMF_SOURCES ${UMF_SOURCES} ${UMF_SOURCES_LINUX})
183-
set(UMF_LIBS ${UMF_LIBS} dl rt) # librt for shm_open()
179+
set(UMF_LIBS ${UMF_LIBS} dl)
184180
elseif(WINDOWS)
185181
set(UMF_SOURCES ${UMF_SOURCES} ${UMF_SOURCES_WINDOWS})
186182

src/provider/provider_devdax_memory.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <string.h>
1515

1616
#include "base_alloc_global.h"
17-
#include "provider_os_memory_internal.h"
1817
#include "utils_common.h"
1918
#include "utils_concurrency.h"
2019
#include "utils_log.h"
@@ -76,8 +75,8 @@ devdax_translate_params(umf_devdax_memory_provider_params_t *in_params,
7675
devdax_memory_provider_t *provider) {
7776
umf_result_t result;
7877

79-
result = os_translate_mem_protection_flags(in_params->protection,
80-
&provider->protection);
78+
result = utils_translate_mem_protection_flags(in_params->protection,
79+
&provider->protection);
8180
if (result != UMF_RESULT_SUCCESS) {
8281
LOG_ERR("incorrect memory protection flags: %u", in_params->protection);
8382
return result;
@@ -124,15 +123,15 @@ static umf_result_t devdax_initialize(void *params, void **provider) {
124123
goto err_free_devdax_provider;
125124
}
126125

127-
int fd = os_devdax_open(in_params->path);
126+
int fd = utils_devdax_open(in_params->path);
128127
if (fd == -1) {
129128
LOG_ERR("cannot open the device DAX: %s", in_params->path);
130129
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT;
131130
goto err_free_devdax_provider;
132131
}
133132

134-
devdax_provider->base = os_devdax_mmap(NULL, devdax_provider->size,
135-
devdax_provider->protection, fd);
133+
devdax_provider->base = utils_devdax_mmap(NULL, devdax_provider->size,
134+
devdax_provider->protection, fd);
136135
utils_close_fd(fd);
137136
if (devdax_provider->base == NULL) {
138137
LOG_PDEBUG("devdax memory mapping failed (path=%s, size=%zu)",
@@ -155,7 +154,7 @@ static umf_result_t devdax_initialize(void *params, void **provider) {
155154
return UMF_RESULT_SUCCESS;
156155

157156
err_unmap_devdax:
158-
os_munmap(devdax_provider->base, devdax_provider->size);
157+
utils_munmap(devdax_provider->base, devdax_provider->size);
159158
err_free_devdax_provider:
160159
umf_ba_global_free(devdax_provider);
161160
return ret;
@@ -169,7 +168,7 @@ static void devdax_finalize(void *provider) {
169168

170169
devdax_memory_provider_t *devdax_provider = provider;
171170
util_mutex_destroy_not_free(&devdax_provider->lock);
172-
os_munmap(devdax_provider->base, devdax_provider->size);
171+
utils_munmap(devdax_provider->base, devdax_provider->size);
173172
umf_ba_global_free(devdax_provider);
174173
}
175174

@@ -281,8 +280,8 @@ static void devdax_get_last_native_error(void *provider, const char **ppMessage,
281280
memcpy(TLS_last_native_error.msg_buff + pos, msg, len + 1);
282281
pos += len;
283282

284-
os_strerror(TLS_last_native_error.errno_value,
285-
TLS_last_native_error.msg_buff + pos, TLS_MSG_BUF_LEN - pos);
283+
utils_strerror(TLS_last_native_error.errno_value,
284+
TLS_last_native_error.msg_buff + pos, TLS_MSG_BUF_LEN - pos);
286285

287286
*ppMessage = TLS_last_native_error.msg_buff;
288287
}
@@ -296,7 +295,7 @@ static umf_result_t devdax_get_recommended_page_size(void *provider,
296295
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
297296
}
298297

299-
*page_size = os_get_page_size();
298+
*page_size = util_get_page_size();
300299

301300
return UMF_RESULT_SUCCESS;
302301
}
@@ -324,7 +323,7 @@ static umf_result_t devdax_purge_force(void *provider, void *ptr, size_t size) {
324323
}
325324

326325
errno = 0;
327-
if (os_purge(ptr, size, UMF_PURGE_FORCE)) {
326+
if (utils_purge(ptr, size, UMF_PURGE_FORCE)) {
328327
devdax_store_last_native_error(
329328
UMF_DEVDAX_RESULT_ERROR_PURGE_FORCE_FAILED, errno);
330329
LOG_PERR("force purging failed");
@@ -453,14 +452,14 @@ static umf_result_t devdax_open_ipc_handle(void *provider,
453452
}
454453

455454
umf_result_t ret = UMF_RESULT_SUCCESS;
456-
int fd = os_devdax_open(devdax_provider->path);
455+
int fd = utils_devdax_open(devdax_provider->path);
457456
if (fd == -1) {
458457
LOG_PERR("opening a devdax (%s) failed", devdax_provider->path);
459458
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
460459
}
461460

462-
char *base = os_devdax_mmap(NULL, devdax_provider->size,
463-
devdax_provider->protection, fd);
461+
char *base = utils_devdax_mmap(NULL, devdax_provider->size,
462+
devdax_provider->protection, fd);
464463
if (base == NULL) {
465464
devdax_store_last_native_error(UMF_DEVDAX_RESULT_ERROR_ALLOC_FAILED,
466465
errno);
@@ -493,7 +492,7 @@ static umf_result_t devdax_close_ipc_handle(void *provider, void *ptr,
493492
(devdax_memory_provider_t *)provider;
494493

495494
errno = 0;
496-
int ret = os_munmap(devdax_provider->base, devdax_provider->size);
495+
int ret = utils_munmap(devdax_provider->base, devdax_provider->size);
497496
// ignore error when size == 0
498497
if (ret && (size > 0)) {
499498
devdax_store_last_native_error(UMF_DEVDAX_RESULT_ERROR_FREE_FAILED,

src/provider/provider_file_memory.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include "base_alloc_global.h"
1717
#include "critnib.h"
18-
#include "provider_os_memory_internal.h"
1918
#include "utils_common.h"
2019
#include "utils_concurrency.h"
2120
#include "utils_log.h"
@@ -88,15 +87,15 @@ file_translate_params(umf_file_memory_provider_params_t *in_params,
8887
file_memory_provider_t *provider) {
8988
umf_result_t result;
9089

91-
result = os_translate_mem_protection_flags(in_params->protection,
92-
&provider->protection);
90+
result = utils_translate_mem_protection_flags(in_params->protection,
91+
&provider->protection);
9392
if (result != UMF_RESULT_SUCCESS) {
9493
LOG_ERR("incorrect memory protection flags: %u", in_params->protection);
9594
return result;
9695
}
9796

98-
result = os_translate_mem_visibility_flag(in_params->visibility,
99-
&provider->visibility);
97+
result = utils_translate_mem_visibility_flag(in_params->visibility,
98+
&provider->visibility);
10099
if (result != UMF_RESULT_SUCCESS) {
101100
LOG_ERR("incorrect memory visibility flag: %u", in_params->visibility);
102101
return result;
@@ -115,7 +114,7 @@ static umf_result_t file_initialize(void *params, void **provider) {
115114
umf_file_memory_provider_params_t *in_params =
116115
(umf_file_memory_provider_params_t *)params;
117116

118-
size_t page_size = os_get_page_size();
117+
size_t page_size = util_get_page_size();
119118

120119
if (in_params->path == NULL) {
121120
LOG_ERR("file path is missing");
@@ -141,14 +140,14 @@ static umf_result_t file_initialize(void *params, void **provider) {
141140
goto err_free_file_provider;
142141
}
143142

144-
file_provider->fd = os_file_open_or_create(in_params->path);
143+
file_provider->fd = utils_file_open_or_create(in_params->path);
145144
if (file_provider->fd == -1) {
146145
LOG_ERR("cannot open the file: %s", in_params->path);
147146
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT;
148147
goto err_free_file_provider;
149148
}
150149

151-
if (os_set_file_size(file_provider->fd, page_size)) {
150+
if (utils_set_file_size(file_provider->fd, page_size)) {
152151
LOG_ERR("cannot set size of the file: %s", in_params->path);
153152
ret = UMF_RESULT_ERROR_UNKNOWN;
154153
goto err_close_fd;
@@ -207,7 +206,7 @@ static void file_finalize(void *provider) {
207206
void *rvalue = NULL;
208207
while (1 ==
209208
critnib_find(file_provider->mmaps, key, FIND_G, &rkey, &rvalue)) {
210-
os_munmap((void *)rkey, (size_t)rvalue);
209+
utils_munmap((void *)rkey, (size_t)rvalue);
211210
critnib_remove(file_provider->mmaps, rkey);
212211
key = rkey;
213212
}
@@ -248,7 +247,7 @@ static umf_result_t file_mmap_aligned(file_memory_provider_t *file_provider,
248247
}
249248

250249
if (offset_fd + extended_size > size_fd) {
251-
if (os_fallocate(fd, offset_fd, extended_size)) {
250+
if (utils_fallocate(fd, offset_fd, extended_size)) {
252251
LOG_ERR("cannot grow the file size from %zu to %zu", size_fd,
253252
offset_fd + extended_size);
254253
return UMF_RESULT_ERROR_UNKNOWN;
@@ -262,7 +261,7 @@ static umf_result_t file_mmap_aligned(file_memory_provider_t *file_provider,
262261
ASSERT_IS_ALIGNED(extended_size, page_size);
263262
ASSERT_IS_ALIGNED(offset_fd, page_size);
264263

265-
void *ptr = os_mmap(NULL, extended_size, prot, flag, fd, offset_fd);
264+
void *ptr = utils_mmap(NULL, extended_size, prot, flag, fd, offset_fd);
266265
if (ptr == NULL) {
267266
LOG_PERR("memory mapping failed");
268267
return UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC;
@@ -423,8 +422,8 @@ static void file_get_last_native_error(void *provider, const char **ppMessage,
423422
memcpy(TLS_last_native_error.msg_buff + pos, msg, len + 1);
424423
pos += len;
425424

426-
os_strerror(TLS_last_native_error.errno_value,
427-
TLS_last_native_error.msg_buff + pos, TLS_MSG_BUF_LEN - pos);
425+
utils_strerror(TLS_last_native_error.errno_value,
426+
TLS_last_native_error.msg_buff + pos, TLS_MSG_BUF_LEN - pos);
428427

429428
*ppMessage = TLS_last_native_error.msg_buff;
430429
}
@@ -437,7 +436,7 @@ static umf_result_t file_get_recommended_page_size(void *provider, size_t size,
437436
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
438437
}
439438

440-
*page_size = os_get_page_size();
439+
*page_size = util_get_page_size();
441440

442441
return UMF_RESULT_SUCCESS;
443442
}
@@ -465,7 +464,7 @@ static umf_result_t file_purge_force(void *provider, void *ptr, size_t size) {
465464
}
466465

467466
errno = 0;
468-
if (os_purge(ptr, size, UMF_PURGE_FORCE)) {
467+
if (utils_purge(ptr, size, UMF_PURGE_FORCE)) {
469468
file_store_last_native_error(UMF_FILE_RESULT_ERROR_PURGE_FORCE_FAILED,
470469
errno);
471470
LOG_PERR("force purging failed");
@@ -606,15 +605,15 @@ static umf_result_t file_open_ipc_handle(void *provider, void *providerIpcData,
606605
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
607606
}
608607

609-
fd = os_file_open(file_ipc_data->path);
608+
fd = utils_file_open(file_ipc_data->path);
610609
if (fd == -1) {
611610
LOG_PERR("opening the file to be mapped (%s) failed",
612611
file_ipc_data->path);
613612
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
614613
}
615614

616-
*ptr = os_mmap(NULL, file_ipc_data->size, file_provider->protection,
617-
file_provider->visibility, fd, file_ipc_data->offset_fd);
615+
*ptr = utils_mmap(NULL, file_ipc_data->size, file_provider->protection,
616+
file_provider->visibility, fd, file_ipc_data->offset_fd);
618617
(void)utils_close_fd(fd);
619618
if (*ptr == NULL) {
620619
file_store_last_native_error(UMF_FILE_RESULT_ERROR_ALLOC_FAILED, errno);
@@ -632,7 +631,7 @@ static umf_result_t file_close_ipc_handle(void *provider, void *ptr,
632631
}
633632

634633
errno = 0;
635-
int ret = os_munmap(ptr, size);
634+
int ret = utils_munmap(ptr, size);
636635
// ignore error when size == 0
637636
if (ret && (size > 0)) {
638637
file_store_last_native_error(UMF_FILE_RESULT_ERROR_FREE_FAILED, errno);

0 commit comments

Comments
 (0)