@@ -33,12 +33,15 @@ umf_memory_provider_ops_t *umfFileMemoryProviderOps(void) {
33
33
#include "utils_concurrency.h"
34
34
#include "utils_log.h"
35
35
36
+ #define FSDAX_PAGE_SIZE_2MB ((size_t)(2 * 1024 * 1024)) // == 2 MB
37
+
36
38
#define TLS_MSG_BUF_LEN 1024
37
39
38
40
typedef struct file_memory_provider_t {
39
41
utils_mutex_t lock ; // lock for file parameters (size and offsets)
40
42
41
43
char path [PATH_MAX ]; // a path to the file
44
+ bool is_fsdax ; // true if file is located on FSDAX
42
45
int fd ; // file descriptor for memory mapping
43
46
size_t size_fd ; // size of the file used for memory mappings
44
47
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) {
130
133
umf_file_memory_provider_params_t * in_params =
131
134
(umf_file_memory_provider_params_t * )params ;
132
135
133
- size_t page_size = utils_get_page_size ();
134
-
135
136
if (in_params -> path == NULL ) {
136
137
LOG_ERR ("file path is missing" );
137
138
return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
@@ -145,8 +146,6 @@ static umf_result_t file_initialize(void *params, void **provider) {
145
146
146
147
memset (file_provider , 0 , sizeof (* file_provider ));
147
148
148
- file_provider -> page_size = page_size ;
149
-
150
149
ret = file_translate_params (in_params , file_provider );
151
150
if (ret != UMF_RESULT_SUCCESS ) {
152
151
goto err_free_file_provider ;
@@ -163,17 +162,34 @@ static umf_result_t file_initialize(void *params, void **provider) {
163
162
goto err_free_file_provider ;
164
163
}
165
164
166
- if (utils_set_file_size (file_provider -> fd , page_size )) {
165
+ if (utils_set_file_size (file_provider -> fd , FSDAX_PAGE_SIZE_2MB )) {
167
166
LOG_ERR ("cannot set size of the file: %s" , in_params -> path );
168
167
ret = UMF_RESULT_ERROR_UNKNOWN ;
169
168
goto err_close_fd ;
170
169
}
171
170
172
- file_provider -> size_fd = page_size ;
171
+ file_provider -> size_fd = FSDAX_PAGE_SIZE_2MB ;
173
172
174
173
LOG_DEBUG ("size of the file %s is: %zu" , in_params -> path ,
175
174
file_provider -> size_fd );
176
175
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
+
177
193
if (utils_mutex_init (& file_provider -> lock ) == NULL ) {
178
194
LOG_ERR ("lock init failed" );
179
195
ret = UMF_RESULT_ERROR_UNKNOWN ;
@@ -480,7 +496,8 @@ static umf_result_t file_get_recommended_page_size(void *provider, size_t size,
480
496
return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
481
497
}
482
498
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 ;
484
501
485
502
return UMF_RESULT_SUCCESS ;
486
503
}
@@ -669,30 +686,41 @@ static umf_result_t file_open_ipc_handle(void *provider, void *providerIpcData,
669
686
umf_result_t ret = UMF_RESULT_SUCCESS ;
670
687
int fd ;
671
688
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
+
672
700
fd = utils_file_open (file_ipc_data -> path );
673
701
if (fd == -1 ) {
674
702
LOG_PERR ("opening the file to be mapped (%s) failed" ,
675
703
file_ipc_data -> path );
676
704
return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
677
705
}
678
706
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 );
682
710
(void )utils_close_fd (fd );
683
711
if (addr == NULL ) {
684
712
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 );
689
717
return UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC ;
690
718
}
691
719
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 );
696
724
697
725
* ptr = addr ;
698
726
@@ -711,6 +739,13 @@ static umf_result_t file_close_ipc_handle(void *provider, void *ptr,
711
739
return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
712
740
}
713
741
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
+
714
749
errno = 0 ;
715
750
int ret = utils_munmap (ptr , size );
716
751
// ignore error when size == 0
0 commit comments