Skip to content

Commit c95bfef

Browse files
committed
Check if file is located on FSDAX
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 2cce8b1 commit c95bfef

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/provider/provider_file_memory.c

Lines changed: 16 additions & 2 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
@@ -164,17 +167,28 @@ static umf_result_t file_initialize(void *params, void **provider) {
164167
goto err_free_file_provider;
165168
}
166169

167-
if (utils_set_file_size(file_provider->fd, page_size)) {
170+
if (utils_set_file_size(file_provider->fd, FSDAX_PAGE_SIZE_2MB)) {
168171
LOG_ERR("cannot set size of the file: %s", in_params->path);
169172
ret = UMF_RESULT_ERROR_UNKNOWN;
170173
goto err_close_fd;
171174
}
172175

173-
file_provider->size_fd = page_size;
176+
file_provider->size_fd = FSDAX_PAGE_SIZE_2MB;
174177

175178
LOG_DEBUG("size of the file %s is: %zu", in_params->path,
176179
file_provider->size_fd);
177180

181+
// check if file is located on FSDAX
182+
if (in_params->visibility == UMF_MEM_MAP_SYNC) {
183+
void *addr = utils_mmap_file(
184+
NULL, file_provider->size_fd, file_provider->protection,
185+
file_provider->visibility, file_provider->fd, 0,
186+
&file_provider->is_fsdax);
187+
if (addr) {
188+
utils_munmap(addr, file_provider->size_fd);
189+
}
190+
}
191+
178192
if (utils_mutex_init(&file_provider->lock) == NULL) {
179193
LOG_ERR("lock init failed");
180194
ret = UMF_RESULT_ERROR_UNKNOWN;

0 commit comments

Comments
 (0)