-
Notifications
You must be signed in to change notification settings - Fork 35
Fix devdax_open_ipc_handle() and devdax_close_ipc_handle() #838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix devdax_open_ipc_handle() and devdax_close_ipc_handle() #838
Conversation
5ce9442
to
7b2a4ba
Compare
7b2a4ba
to
45950bb
Compare
// length and offset passed to mmap() have to be page-aligned | ||
size_t offset_aligned = devdax_ipc_data->offset; | ||
size_t length_aligned = devdax_ipc_data->length; | ||
utils_align_ptr_down_size_up((void **)&offset_aligned, &length_aligned, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this call to the utils_align_ptr_down_size_up
function? Offset and length should be aligned during the allocation? I mean that IPC handle represents allocation that is done by this memory provider and it already should be page-aligned. Probably here and in the devdax_open_ipc_handle
we need to check that offset and length are page-aligned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is needed. alloc()
aligns pointer's address to the alignment given as the alloc()
's parameter, not to the page size, but mmap()
requires the page size alignment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I got it. In case of arbitrary alignment such logic makes sense, but does arbitrary alignment in case of any memory provider (not only devdax) makes sense. I can assume that alignment always is a multiply of the page size. Did I miss something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
User-requested alignment (given as alloc(size, alignment)
) "must be a power of two and a multiple of sizeof(void *)." as POSIX_MEMALIGN(3) states, so it does not have to be a multiply of the page size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but the memory provider API is closer to the mmap
.
The umfPoolMalloc()
is similar to regular malloc
, but memory providers are responsible for a coarse-grain allocations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the main issue is that we cannot require the size (in alloc()
) to be a multiple of 2MB - we cannot force jemalloc or any other pool manager or a user of a memory provider to call alloc()
only with size being a multiple of 2MB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think with alloc function everything is easy, we can support 4KB allocations because we just update the offset and do actual mapping at the init phase. The question is about ope_ip_handle how should we implement it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vinser52 please review the new version - there is no up-alignment in open/close_IPC_handle any more
(The devdax CI jobs pass: https://github.com/oneapi-src/unified-memory-framework/actions/runs/11595816096)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new IPC tests (#845) pass too: https://github.com/oneapi-src/unified-memory-framework/actions/runs/11596112796/job/32286377438
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vinser52 Done.
18dee99
to
a4f1c8b
Compare
a4f1c8b
to
3129474
Compare
3129474
to
a4f1c8b
Compare
e0262fc
to
cd6e0be
Compare
8c3735a
to
903c467
Compare
Fixes: #846 |
641be78
to
ccd1784
Compare
ccd1784
to
1a2ce63
Compare
Signed-off-by: Lukasz Dorau <[email protected]>
Add utils_align_ptr_down_size_up() to align a pointer down and a size up (for mmap()/munmap()). Signed-off-by: Lukasz Dorau <[email protected]>
Signed-off-by: Lukasz Dorau <[email protected]>
Fix handling arguments of devdax_alloc(): - alignment has to be a power of 2 and a divider or a multiple of the page size (2MB), Signed-off-by: Lukasz Dorau <[email protected]>
1a2ce63
to
52fd361
Compare
devdax_open_ipc_handle() has to use the path of the remote /dev/dax got from the IPC handle, not the local one. devdax_open_ipc_handle() has to use also the memory protection got from the IPC handle, so let's add the memory protection to the IPC handle. devdax_open_ipc_handle() should mmap only the required range of memory, not the whole /dev/dax device, so let's add the length of the allocation to the IPC handle. devdax_close_ipc_handle() should unmap only the required range of memory, not the whole /dev/dax device. Fixes: oneapi-src#846 Signed-off-by: Lukasz Dorau <[email protected]>
52fd361
to
74b91bb
Compare
// alignment must be a power of two and a multiple or a divider of the page size | ||
if (alignment && ((alignment & (alignment - 1)) || | ||
((alignment % DEVDAX_PAGE_SIZE_2MB) && | ||
(DEVDAX_PAGE_SIZE_2MB % alignment)))) { | ||
LOG_ERR("wrong alignment: %zu (not a power of 2 or a multiple or a " | ||
"divider of the page size (%zu))", | ||
alignment, DEVDAX_PAGE_SIZE_2MB); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure I understand it correctly, will 4 KB also pass this check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, 4kB is a divider of 2MB
Alignment passed to `file_alloc()` must be a power of two and a multiple or a divider of the page size. Align up the alignment in `file_alloc()` to the page size. file_open_ipc_handle() has to use the memory protection and visibility got from the IPC handle, so let's add the memory protection and visibility to the IPC handle. A length and an offset passed to mmap() in `file_open_ipc_handle()` and `file_close_ipc_handle()` have to be aligned to the page size. Ref: oneapi-src#838 Fixes: oneapi-src#848 Signed-off-by: Lukasz Dorau <[email protected]>
Alignment passed to `file_alloc()` must be a power of two and a multiple or a divider of the page size. Align up the alignment in `file_alloc()` to the page size. file_open_ipc_handle() has to use the memory protection and visibility got from the IPC handle, so let's add the memory protection and visibility to the IPC handle. A length and an offset passed to mmap() in `file_open_ipc_handle()` and `file_close_ipc_handle()` have to be aligned to the page size. Ref: oneapi-src#838 Fixes: oneapi-src#848 Signed-off-by: Lukasz Dorau <[email protected]>
Alignment passed to `file_alloc()` must be a power of two and a multiple or a divider of the page size. Align up the alignment in `file_alloc()` to the page size. file_open_ipc_handle() has to use the memory protection and visibility got from the IPC handle, so let's add the memory protection and visibility to the IPC handle. A length and an offset passed to mmap() in `file_open_ipc_handle()` and `file_close_ipc_handle()` have to be aligned to the page size. Ref: oneapi-src#838 Fixes: oneapi-src#848 Signed-off-by: Lukasz Dorau <[email protected]>
Alignment passed to `file_alloc()` must be a power of two and a multiple or a divider of the page size. Align up the alignment in `file_alloc()` to the page size. file_open_ipc_handle() has to use the memory protection and visibility got from the IPC handle, so let's add the memory protection and visibility to the IPC handle. Ref: oneapi-src#838 Fixes: oneapi-src#848 Signed-off-by: Lukasz Dorau <[email protected]>
Alignment passed to `file_alloc()` must be a power of two and a multiple or a divider of the page size. Align up the alignment in `file_alloc()` to the page size. file_open_ipc_handle() has to use the memory protection and visibility got from the IPC handle, so let's add the memory protection and visibility to the IPC handle. Ref: oneapi-src#838 Fixes: oneapi-src#848 Signed-off-by: Lukasz Dorau <[email protected]>
Description
Fix devdax_open_ipc_handle() and devdax_close_ipc_handle()
devdax_open_ipc_handle() has to use the path of the remote
/dev/dax got from the IPC handle, not the local one.
devdax_open_ipc_handle() has to use also the memory protection
got from the IPC handle, so let's add the memory protection
to the IPC handle.
devdax_open_ipc_handle() should mmap only the required range of memory,
not the whole /dev/dax device, so let's add the length of the allocation
to the IPC handle.
devdax_close_ipc_handle() should unmap only the required range of memory,
not the whole /dev/dax device.
Fixes: #846
Checklist