Skip to content

Commit 0123fe2

Browse files
committed
Enable IPC API for FSDAX
FSDAX requires 2 MB page size. Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 5d9aeff commit 0123fe2

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/provider/provider_file_memory.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -690,30 +690,41 @@ static umf_result_t file_open_ipc_handle(void *provider, void *providerIpcData,
690690
umf_result_t ret = UMF_RESULT_SUCCESS;
691691
int fd;
692692

693+
size_t offset_aligned = file_ipc_data->offset_fd;
694+
size_t size_aligned = file_ipc_data->size;
695+
696+
if (file_provider->is_fsdax) {
697+
// It is just a workaround for case when
698+
// file_alloc() was called with the size argument
699+
// that is not a multiplier of FSDAX_PAGE_SIZE_2MB.
700+
utils_align_ptr_down_size_up((void **)&offset_aligned, &size_aligned,
701+
FSDAX_PAGE_SIZE_2MB);
702+
}
703+
693704
fd = utils_file_open(file_ipc_data->path);
694705
if (fd == -1) {
695706
LOG_PERR("opening the file to be mapped (%s) failed",
696707
file_ipc_data->path);
697708
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
698709
}
699710

700-
char *addr = utils_mmap_file(
701-
NULL, file_ipc_data->size, file_ipc_data->protection,
702-
file_ipc_data->visibility, fd, file_ipc_data->offset_fd, NULL);
711+
char *addr =
712+
utils_mmap_file(NULL, size_aligned, file_ipc_data->protection,
713+
file_ipc_data->visibility, fd, offset_aligned, NULL);
703714
(void)utils_close_fd(fd);
704715
if (addr == NULL) {
705716
file_store_last_native_error(UMF_FILE_RESULT_ERROR_ALLOC_FAILED, errno);
706717
LOG_PERR("file mapping failed (path: %s, size: %zu, protection: %i, "
707718
"fd: %i, offset: %zu)",
708-
file_ipc_data->path, file_ipc_data->size,
709-
file_ipc_data->protection, fd, file_ipc_data->offset_fd);
719+
file_ipc_data->path, size_aligned, file_ipc_data->protection,
720+
fd, offset_aligned);
710721
return UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC;
711722
}
712723

713724
LOG_DEBUG("file mapped (path: %s, size: %zu, protection: %i, fd: %i, "
714725
"offset: %zu) at address %p",
715-
file_ipc_data->path, file_ipc_data->size,
716-
file_ipc_data->protection, fd, file_ipc_data->offset_fd, addr);
726+
file_ipc_data->path, size_aligned, file_ipc_data->protection, fd,
727+
offset_aligned, addr);
717728

718729
*ptr = addr;
719730

@@ -733,6 +744,13 @@ static umf_result_t file_close_ipc_handle(void *provider, void *ptr,
733744
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
734745
}
735746

747+
if (file_provider->is_fsdax) {
748+
// It is just a workaround for case when
749+
// file_alloc() was called with the size argument
750+
// that is not a multiplier of FSDAX_PAGE_SIZE_2MB.
751+
utils_align_ptr_down_size_up(&ptr, &size, FSDAX_PAGE_SIZE_2MB);
752+
}
753+
736754
errno = 0;
737755
int ret = utils_munmap(ptr, size);
738756
// ignore error when size == 0

0 commit comments

Comments
 (0)