Skip to content

Commit 64456b7

Browse files
authored
Merge pull request #878 from ldorau/Enable_IPC_API_for_FSDAX
Enable IPC API for FSDAX
2 parents 23d69ff + ff40db8 commit 64456b7

File tree

5 files changed

+126
-19
lines changed

5 files changed

+126
-19
lines changed

src/provider/provider_devdax_memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ static umf_result_t devdax_open_ipc_handle(void *provider,
493493
LOG_DEBUG("devdax mapped (path: %s, size: %zu, protection: %i, fd: %i, "
494494
"offset: %zu) to address %p",
495495
devdax_ipc_data->path, length_aligned,
496-
devdax_ipc_data->protection, fd, offset_aligned, addr);
496+
devdax_ipc_data->protection, fd, offset_aligned, (void *)addr);
497497

498498
*ptr = addr;
499499

src/provider/provider_file_memory.c

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ umf_memory_provider_ops_t *umfFileMemoryProviderOps(void) {
3333
#include "utils_concurrency.h"
3434
#include "utils_log.h"
3535

36+
#define FSDAX_PAGE_SIZE_2MB ((size_t)(2 * 1024 * 1024)) // == 2 MB
37+
3638
#define TLS_MSG_BUF_LEN 1024
3739

3840
typedef struct file_memory_provider_t {
3941
utils_mutex_t lock; // lock for file parameters (size and offsets)
4042

4143
char path[PATH_MAX]; // a path to the file
44+
bool is_fsdax; // true if file is located on FSDAX
4245
int fd; // file descriptor for memory mapping
4346
size_t size_fd; // size of the file used for memory mappings
4447
size_t offset_fd; // offset in the file used for memory mappings
@@ -130,8 +133,6 @@ static umf_result_t file_initialize(void *params, void **provider) {
130133
umf_file_memory_provider_params_t *in_params =
131134
(umf_file_memory_provider_params_t *)params;
132135

133-
size_t page_size = utils_get_page_size();
134-
135136
if (in_params->path == NULL) {
136137
LOG_ERR("file path is missing");
137138
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
@@ -145,8 +146,6 @@ static umf_result_t file_initialize(void *params, void **provider) {
145146

146147
memset(file_provider, 0, sizeof(*file_provider));
147148

148-
file_provider->page_size = page_size;
149-
150149
ret = file_translate_params(in_params, file_provider);
151150
if (ret != UMF_RESULT_SUCCESS) {
152151
goto err_free_file_provider;
@@ -163,17 +162,34 @@ static umf_result_t file_initialize(void *params, void **provider) {
163162
goto err_free_file_provider;
164163
}
165164

166-
if (utils_set_file_size(file_provider->fd, page_size)) {
165+
if (utils_set_file_size(file_provider->fd, FSDAX_PAGE_SIZE_2MB)) {
167166
LOG_ERR("cannot set size of the file: %s", in_params->path);
168167
ret = UMF_RESULT_ERROR_UNKNOWN;
169168
goto err_close_fd;
170169
}
171170

172-
file_provider->size_fd = page_size;
171+
file_provider->size_fd = FSDAX_PAGE_SIZE_2MB;
173172

174173
LOG_DEBUG("size of the file %s is: %zu", in_params->path,
175174
file_provider->size_fd);
176175

176+
if (!(in_params->visibility & UMF_MEM_MAP_PRIVATE)) {
177+
// check if file is located on FSDAX
178+
void *addr = utils_mmap_file(
179+
NULL, file_provider->size_fd, file_provider->protection,
180+
file_provider->visibility, file_provider->fd, 0,
181+
&file_provider->is_fsdax);
182+
if (addr) {
183+
utils_munmap(addr, file_provider->size_fd);
184+
}
185+
}
186+
187+
if (file_provider->is_fsdax) {
188+
file_provider->page_size = FSDAX_PAGE_SIZE_2MB;
189+
} else {
190+
file_provider->page_size = utils_get_page_size();
191+
}
192+
177193
if (utils_mutex_init(&file_provider->lock) == NULL) {
178194
LOG_ERR("lock init failed");
179195
ret = UMF_RESULT_ERROR_UNKNOWN;
@@ -480,7 +496,8 @@ static umf_result_t file_get_recommended_page_size(void *provider, size_t size,
480496
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
481497
}
482498

483-
*page_size = utils_get_page_size();
499+
file_memory_provider_t *file_provider = (file_memory_provider_t *)provider;
500+
*page_size = file_provider->page_size;
484501

485502
return UMF_RESULT_SUCCESS;
486503
}
@@ -669,30 +686,41 @@ static umf_result_t file_open_ipc_handle(void *provider, void *providerIpcData,
669686
umf_result_t ret = UMF_RESULT_SUCCESS;
670687
int fd;
671688

689+
size_t offset_aligned = file_ipc_data->offset_fd;
690+
size_t size_aligned = file_ipc_data->size;
691+
692+
if (file_provider->is_fsdax) {
693+
// It is just a workaround for case when
694+
// file_alloc() was called with the size argument
695+
// that is not a multiplier of FSDAX_PAGE_SIZE_2MB.
696+
utils_align_ptr_down_size_up((void **)&offset_aligned, &size_aligned,
697+
FSDAX_PAGE_SIZE_2MB);
698+
}
699+
672700
fd = utils_file_open(file_ipc_data->path);
673701
if (fd == -1) {
674702
LOG_PERR("opening the file to be mapped (%s) failed",
675703
file_ipc_data->path);
676704
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
677705
}
678706

679-
char *addr = utils_mmap_file(
680-
NULL, file_ipc_data->size, file_ipc_data->protection,
681-
file_ipc_data->visibility, fd, file_ipc_data->offset_fd, NULL);
707+
char *addr =
708+
utils_mmap_file(NULL, size_aligned, file_ipc_data->protection,
709+
file_ipc_data->visibility, fd, offset_aligned, NULL);
682710
(void)utils_close_fd(fd);
683711
if (addr == NULL) {
684712
file_store_last_native_error(UMF_FILE_RESULT_ERROR_ALLOC_FAILED, errno);
685-
LOG_PERR("file mapping failed (path: %s, size: %zu, protection: %i, "
686-
"fd: %i, offset: %zu)",
687-
file_ipc_data->path, file_ipc_data->size,
688-
file_ipc_data->protection, fd, file_ipc_data->offset_fd);
713+
LOG_PERR("file mapping failed (path: %s, size: %zu, protection: %u, "
714+
"visibility: %u, fd: %i, offset: %zu)",
715+
file_ipc_data->path, size_aligned, file_ipc_data->protection,
716+
file_ipc_data->visibility, fd, offset_aligned);
689717
return UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC;
690718
}
691719

692-
LOG_DEBUG("file mapped (path: %s, size: %zu, protection: %i, fd: %i, "
693-
"offset: %zu) at address %p",
694-
file_ipc_data->path, file_ipc_data->size,
695-
file_ipc_data->protection, fd, file_ipc_data->offset_fd, addr);
720+
LOG_DEBUG("file mapped (path: %s, size: %zu, protection: %u, visibility: "
721+
"%u, fd: %i, offset: %zu) at address %p",
722+
file_ipc_data->path, size_aligned, file_ipc_data->protection,
723+
file_ipc_data->visibility, fd, offset_aligned, (void *)addr);
696724

697725
*ptr = addr;
698726

@@ -711,6 +739,13 @@ static umf_result_t file_close_ipc_handle(void *provider, void *ptr,
711739
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
712740
}
713741

742+
if (file_provider->is_fsdax) {
743+
// It is just a workaround for case when
744+
// file_alloc() was called with the size argument
745+
// that is not a multiplier of FSDAX_PAGE_SIZE_2MB.
746+
utils_align_ptr_down_size_up(&ptr, &size, FSDAX_PAGE_SIZE_2MB);
747+
}
748+
714749
errno = 0;
715750
int ret = utils_munmap(ptr, size);
716751
// ignore error when size == 0

test/provider_file_memory_ipc.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ umf_file_memory_provider_params_t get_file_params_shared(char *path) {
2727
umf_file_memory_provider_params_t file_params_shared =
2828
get_file_params_shared(FILE_PATH);
2929

30+
umf_file_memory_provider_params_t get_file_params_fsdax(char *path) {
31+
umf_file_memory_provider_params_t file_params =
32+
umfFileMemoryProviderParamsDefault(path);
33+
file_params.visibility = UMF_MEM_MAP_SHARED;
34+
return file_params;
35+
}
36+
37+
umf_file_memory_provider_params_t file_params_fsdax =
38+
get_file_params_fsdax(getenv("UMF_TESTS_FSDAX_PATH"));
39+
3040
HostMemoryAccessor hostAccessor;
3141

3242
static std::vector<ipcTestParams> ipcManyPoolsTestParamsList = {
@@ -43,7 +53,36 @@ static std::vector<ipcTestParams> ipcManyPoolsTestParamsList = {
4353
#endif
4454
};
4555

56+
static std::vector<ipcTestParams> getIpcFsDaxTestParamsList(void) {
57+
std::vector<ipcTestParams> ipcFsDaxTestParamsList = {};
58+
59+
char *path = getenv("UMF_TESTS_FSDAX_PATH");
60+
if (path == nullptr || path[0] == 0) {
61+
// skipping the test, UMF_TESTS_FSDAX_PATH is not set
62+
return ipcFsDaxTestParamsList;
63+
}
64+
65+
ipcFsDaxTestParamsList = {
66+
// TODO: enable it when sizes of allocations in ipcFixtures.hpp are fixed
67+
// {umfProxyPoolOps(), nullptr, umfFileMemoryProviderOps(),
68+
// &file_params_fsdax, &hostAccessor, true},
69+
#ifdef UMF_POOL_JEMALLOC_ENABLED
70+
{umfJemallocPoolOps(), nullptr, umfFileMemoryProviderOps(),
71+
&file_params_fsdax, &hostAccessor, false},
72+
#endif
73+
#ifdef UMF_POOL_SCALABLE_ENABLED
74+
{umfScalablePoolOps(), nullptr, umfFileMemoryProviderOps(),
75+
&file_params_fsdax, &hostAccessor, false},
76+
#endif
77+
};
78+
79+
return ipcFsDaxTestParamsList;
80+
}
81+
4682
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(umfIpcTest);
4783

4884
INSTANTIATE_TEST_SUITE_P(FileProviderDifferentPoolsTest, umfIpcTest,
4985
::testing::ValuesIn(ipcManyPoolsTestParamsList));
86+
87+
INSTANTIATE_TEST_SUITE_P(FileProviderDifferentPoolsFSDAXTest, umfIpcTest,
88+
::testing::ValuesIn(getIpcFsDaxTestParamsList()));

test/supp/helgrind-umf_test-ipc.supp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
False-positive race in critnib_insert (lack of instrumentation)
3+
Helgrind:Race
4+
fun:store
5+
fun:critnib_insert
6+
...
7+
}
8+
9+
{
10+
False-positive race in critnib_find (lack of instrumentation)
11+
Helgrind:Race
12+
fun:find_predecessor
13+
fun:find_le
14+
fun:critnib_find
15+
...
16+
}

test/supp/helgrind-umf_test-provider_file_memory_ipc.supp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,20 @@
66
fun:umfOpenIPCHandle
77
...
88
}
9+
10+
{
11+
False-positive race in critnib_insert (lack of instrumentation)
12+
Helgrind:Race
13+
fun:store
14+
fun:critnib_insert
15+
...
16+
}
17+
18+
{
19+
False-positive race in critnib_find (lack of instrumentation)
20+
Helgrind:Race
21+
fun:find_predecessor
22+
fun:find_le
23+
fun:critnib_find
24+
...
25+
}

0 commit comments

Comments
 (0)