Skip to content

Commit 955ac33

Browse files
committed
Add is_fsdax to file provider's parameters
`is_fsdax` should be set to true if the file is located on FSDAX. It is needed, because FSDAX requires 2 MB page size. Signed-off-by: Lukasz Dorau <[email protected]>
1 parent dc4e581 commit 955ac33

File tree

6 files changed

+44
-5
lines changed

6 files changed

+44
-5
lines changed

examples/dram_and_fsdax/dram_and_fsdax.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static umf_memory_pool_handle_t create_fsdax_pool(const char *path) {
5151
umf_file_memory_provider_params_t params_fsdax =
5252
umfFileMemoryProviderParamsDefault(path);
5353
// FSDAX requires mapping the UMF_MEM_MAP_SYNC flag
54+
params_fsdax.is_fsdax = true;
5455
params_fsdax.visibility = UMF_MEM_MAP_SYNC;
5556

5657
umf_result = umfMemoryProviderCreate(umfFileMemoryProviderOps(),

include/umf/providers/provider_file_memory.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#ifndef UMF_FILE_MEMORY_PROVIDER_H
99
#define UMF_FILE_MEMORY_PROVIDER_H
1010

11+
#include <stdbool.h>
12+
1113
#include <umf/providers/provider_os_memory.h>
1214

1315
#ifdef __cplusplus
@@ -22,6 +24,8 @@ extern "C" {
2224
typedef struct umf_file_memory_provider_params_t {
2325
/// a path to the file (of maximum length PATH_MAX characters)
2426
const char *path;
27+
/// true if the file is located on FSDAX
28+
bool is_fsdax;
2529
/// combination of 'umf_mem_protection_flags_t' flags
2630
unsigned protection;
2731
/// memory visibility mode
@@ -43,6 +47,7 @@ static inline umf_file_memory_provider_params_t
4347
umfFileMemoryProviderParamsDefault(const char *path) {
4448
umf_file_memory_provider_params_t params = {
4549
path, /* a path to the file */
50+
false, /* is FSDAX */
4651
UMF_PROTECTION_READ | UMF_PROTECTION_WRITE, /* protection */
4752
UMF_MEM_MAP_PRIVATE, /* visibility mode */
4853
};

src/provider/provider_file_memory.c

Lines changed: 18 additions & 5 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 the 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
@@ -131,7 +134,11 @@ static umf_result_t file_initialize(void *params, void **provider) {
131134
umf_file_memory_provider_params_t *in_params =
132135
(umf_file_memory_provider_params_t *)params;
133136

134-
size_t page_size = utils_get_page_size();
137+
if (in_params->is_fsdax && in_params->visibility != UMF_MEM_MAP_SYNC) {
138+
LOG_ERR("memory visibility has to be set to UMF_MEM_MAP_SYNC in case "
139+
"of FSDAX");
140+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
141+
}
135142

136143
if (in_params->path == NULL) {
137144
LOG_ERR("file path is missing");
@@ -146,7 +153,12 @@ static umf_result_t file_initialize(void *params, void **provider) {
146153

147154
memset(file_provider, 0, sizeof(*file_provider));
148155

149-
file_provider->page_size = page_size;
156+
file_provider->is_fsdax = in_params->is_fsdax;
157+
if (file_provider->is_fsdax) {
158+
file_provider->page_size = FSDAX_PAGE_SIZE_2MB;
159+
} else {
160+
file_provider->page_size = utils_get_page_size();
161+
}
150162

151163
ret = file_translate_params(in_params, file_provider);
152164
if (ret != UMF_RESULT_SUCCESS) {
@@ -164,13 +176,13 @@ static umf_result_t file_initialize(void *params, void **provider) {
164176
goto err_free_file_provider;
165177
}
166178

167-
if (utils_set_file_size(file_provider->fd, page_size)) {
179+
if (utils_set_file_size(file_provider->fd, file_provider->page_size)) {
168180
LOG_ERR("cannot set size of the file: %s", in_params->path);
169181
ret = UMF_RESULT_ERROR_UNKNOWN;
170182
goto err_close_fd;
171183
}
172184

173-
file_provider->size_fd = page_size;
185+
file_provider->size_fd = file_provider->page_size;
174186

175187
LOG_DEBUG("size of the file %s is: %zu", in_params->path,
176188
file_provider->size_fd);
@@ -481,7 +493,8 @@ static umf_result_t file_get_recommended_page_size(void *provider, size_t size,
481493
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
482494
}
483495

484-
*page_size = utils_get_page_size();
496+
file_memory_provider_t *file_provider = (file_memory_provider_t *)provider;
497+
*page_size = file_provider->page_size;
485498

486499
return UMF_RESULT_SUCCESS;
487500
}

test/ipc_file_prov_consumer.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ int main(int argc, char *argv[]) {
3838

3939
file_params = umfFileMemoryProviderParamsDefault(file_name);
4040
if (is_fsdax) {
41+
file_params.is_fsdax = true;
4142
file_params.visibility = UMF_MEM_MAP_SYNC;
4243
} else {
44+
file_params.is_fsdax = false;
4345
file_params.visibility = UMF_MEM_MAP_SHARED;
4446
}
4547

test/ipc_file_prov_producer.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ int main(int argc, char *argv[]) {
3838

3939
file_params = umfFileMemoryProviderParamsDefault(file_name);
4040
if (is_fsdax) {
41+
file_params.is_fsdax = true;
4142
file_params.visibility = UMF_MEM_MAP_SYNC;
4243
} else {
44+
file_params.is_fsdax = false;
4345
file_params.visibility = UMF_MEM_MAP_SHARED;
4446
}
4547

test/provider_file_memory.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ TEST_F(test, test_if_mapped_with_MAP_SYNC) {
137137
}
138138

139139
auto params = umfFileMemoryProviderParamsDefault(path);
140+
params.is_fsdax = true;
140141
params.visibility = UMF_MEM_MAP_SYNC;
141142

142143
umf_result = umfMemoryProviderCreate(umfFileMemoryProviderOps(), &params,
@@ -161,6 +162,21 @@ TEST_F(test, test_if_mapped_with_MAP_SYNC) {
161162
ASSERT_EQ(flag_found, true);
162163
}
163164

165+
// Negative test checking if FSDAX is to be mapped with the MAP_SYNC flag
166+
TEST_F(test, test_if_fsdax_visibility_is_MAP_SYNC) {
167+
umf_memory_provider_handle_t hProvider = nullptr;
168+
umf_result_t umf_result;
169+
170+
auto params = umfFileMemoryProviderParamsDefault(FILE_PATH);
171+
params.is_fsdax = true;
172+
params.visibility = UMF_MEM_MAP_SHARED;
173+
174+
umf_result = umfMemoryProviderCreate(umfFileMemoryProviderOps(), &params,
175+
&hProvider);
176+
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_INVALID_ARGUMENT);
177+
ASSERT_EQ(hProvider, nullptr);
178+
}
179+
164180
// positive tests using test_alloc_free_success
165181

166182
umf_file_memory_provider_params_t file_params_default =

0 commit comments

Comments
 (0)