Skip to content

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

Merged
merged 5 commits into from
Oct 31, 2024

Conversation

ldorau
Copy link
Contributor

@ldorau ldorau commented Oct 24, 2024

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

  • Code compiles without errors locally
  • All tests pass locally
  • CI workflows execute properly

@ldorau ldorau requested a review from a team as a code owner October 24, 2024 20:45
@ldorau ldorau force-pushed the Fix_devdax_open_ipc_handle branch 2 times, most recently from 5ce9442 to 7b2a4ba Compare October 24, 2024 20:51
@ldorau ldorau requested review from vinser52 and bratpiorka October 25, 2024 06:51
@ldorau ldorau force-pushed the Fix_devdax_open_ipc_handle branch from 7b2a4ba to 45950bb Compare October 25, 2024 08:17
@ldorau ldorau requested a review from bratpiorka October 25, 2024 08:18
// 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,
Copy link
Contributor

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.

Copy link
Contributor Author

@ldorau ldorau Oct 25, 2024

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.

Copy link
Contributor

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?

Copy link
Contributor Author

@ldorau ldorau Oct 25, 2024

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

@ldorau ldorau Oct 30, 2024

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)

Copy link
Contributor Author

@ldorau ldorau Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vinser52 Done.

@ldorau ldorau force-pushed the Fix_devdax_open_ipc_handle branch 5 times, most recently from 18dee99 to a4f1c8b Compare October 28, 2024 09:39
@ldorau ldorau requested a review from vinser52 October 28, 2024 09:39
@ldorau ldorau force-pushed the Fix_devdax_open_ipc_handle branch from a4f1c8b to 3129474 Compare October 28, 2024 16:23
@ldorau ldorau requested a review from pbalcer October 28, 2024 16:26
@ldorau ldorau force-pushed the Fix_devdax_open_ipc_handle branch from 3129474 to a4f1c8b Compare October 28, 2024 16:56
@ldorau ldorau force-pushed the Fix_devdax_open_ipc_handle branch 7 times, most recently from e0262fc to cd6e0be Compare October 30, 2024 09:00
@ldorau ldorau force-pushed the Fix_devdax_open_ipc_handle branch from 8c3735a to 903c467 Compare October 30, 2024 11:56
@ldorau ldorau marked this pull request as ready for review October 30, 2024 11:57
@ldorau
Copy link
Contributor Author

ldorau commented Oct 30, 2024

Fixes: #846

@ldorau ldorau marked this pull request as draft October 30, 2024 13:47
@ldorau ldorau force-pushed the Fix_devdax_open_ipc_handle branch 2 times, most recently from 641be78 to ccd1784 Compare October 30, 2024 14:58
@ldorau ldorau marked this pull request as ready for review October 30, 2024 14:59
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]>
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]>
@ldorau ldorau force-pushed the Fix_devdax_open_ipc_handle branch from 1a2ce63 to 52fd361 Compare October 31, 2024 13:15
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]>
@ldorau ldorau force-pushed the Fix_devdax_open_ipc_handle branch from 52fd361 to 74b91bb Compare October 31, 2024 13:19
@ldorau ldorau requested a review from vinser52 October 31, 2024 13:20
Comment on lines +231 to +237
// 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);
Copy link
Contributor

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?

Copy link
Contributor Author

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

@vinser52 vinser52 requested a review from bratpiorka October 31, 2024 13:45
@bratpiorka bratpiorka merged commit 77ef32a into oneapi-src:main Oct 31, 2024
74 checks passed
@ldorau ldorau deleted the Fix_devdax_open_ipc_handle branch October 31, 2024 15:14
ldorau added a commit to ldorau/unified-memory-framework that referenced this pull request Nov 5, 2024
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]>
ldorau added a commit to ldorau/unified-memory-framework that referenced this pull request Nov 5, 2024
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]>
ldorau added a commit to ldorau/unified-memory-framework that referenced this pull request Nov 5, 2024
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]>
ldorau added a commit to ldorau/unified-memory-framework that referenced this pull request Nov 5, 2024
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]>
ldorau added a commit to ldorau/unified-memory-framework that referenced this pull request Nov 6, 2024
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IPC API of the devdax provider does not work (IPC tests segfault)
4 participants