-
Notifications
You must be signed in to change notification settings - Fork 22
[bugfix] fix direct io bad address #174
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,12 +9,7 @@ | |
| #include <sys/mman.h> | ||
|
|
||
| uintptr_t alloc_pinned_ptr(std::size_t size, unsigned int flags) { | ||
| void *ptr = nullptr; | ||
| // no flags | ||
| aclError err = aclrtMallocHost(&ptr, size); | ||
| if (err != ACL_SUCCESS) { | ||
| throw std::runtime_error("aclrtMallocHost failed: " + std::to_string(err)); | ||
| } | ||
| void *ptr = alloc_mem(size); | ||
|
|
||
| const char *socVersion = aclrtGetSocName(); | ||
|
|
||
|
|
@@ -26,7 +21,7 @@ uintptr_t alloc_pinned_ptr(std::size_t size, unsigned int flags) { | |
| // not 310p | ||
| auto devPtr = register_ptr(ptr, size); | ||
| if (devPtr == nullptr) { | ||
| free_pinned_ptr(reinterpret_cast<uintptr_t>(ptr)); | ||
| free_mem(ptr); | ||
| throw std::runtime_error("register ptr failed"); | ||
| } | ||
| } | ||
|
|
@@ -35,11 +30,9 @@ uintptr_t alloc_pinned_ptr(std::size_t size, unsigned int flags) { | |
| } | ||
|
|
||
| void free_pinned_ptr(uintptr_t ptr) { | ||
| unregister_ptr(reinterpret_cast<void *>(ptr)); | ||
| aclError err = aclrtFreeHost(reinterpret_cast<void *>(ptr)); | ||
| if (err != ACL_SUCCESS) { | ||
| throw std::runtime_error("aclrtFreeHost failed: " + std::to_string(err)); | ||
| } | ||
| void *vptr = reinterpret_cast<void *>(ptr); | ||
| unregister_ptr(vptr); | ||
| free_mem(vptr); | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -49,7 +42,8 @@ uintptr_t alloc_pinned_numa_ptr(std::size_t size, int node) { | |
| void *ptr = mmap(nullptr, size, PROT_READ | PROT_WRITE, | ||
| MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | ||
| if (ptr == MAP_FAILED) { | ||
| throw std::runtime_error(std::string("mmap failed: ") + strerror(errno)); | ||
| throw std::runtime_error( | ||
| std::string("[alloc_pinned_numa_ptr] mmap failed: ") + strerror(errno)); | ||
| } | ||
|
|
||
| // Maximum of 64 numa nodes | ||
|
|
@@ -59,7 +53,17 @@ uintptr_t alloc_pinned_numa_ptr(std::size_t size, int node) { | |
| MPOL_MF_MOVE | MPOL_MF_STRICT); | ||
| if (err != 0) { | ||
| munmap(ptr, size); | ||
| throw std::runtime_error(std::string("mbind failed: ") + strerror(errno)); | ||
| throw std::runtime_error( | ||
| std::string("[alloc_pinned_numa_ptr] mbind failed: ") + | ||
| strerror(errno)); | ||
| } | ||
|
|
||
| // In kernels 5.10 and earlier, the aclrtHostRegister requires pinned memory | ||
| if (mlock(ptr, size) != 0) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should after memset.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. @chloroethylene |
||
| munmap(ptr, size); | ||
| throw std::runtime_error( | ||
| std::string("[alloc_pinned_numa_ptr] mlock failed: ") + | ||
| strerror(errno)); | ||
| } | ||
|
|
||
| memset(ptr, 0, size); | ||
|
|
@@ -86,8 +90,12 @@ uintptr_t alloc_pinned_numa_ptr(std::size_t size, int node) { | |
| void free_pinned_numa_ptr(uintptr_t p, std::size_t size) { | ||
| void *ptr = reinterpret_cast<void *>(p); | ||
|
|
||
| // Unregister the pointer | ||
| auto unRegErr = unregister_ptr(ptr); | ||
|
|
||
| // Unmap the memory | ||
| auto unMapErr = munmap(ptr, size); | ||
|
|
||
| if (unRegErr) { | ||
| throw std::runtime_error("unregister_ptr failed: " + | ||
| std::to_string(unRegErr)); | ||
|
Comment on lines
94
to
101
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In |
||
|
|
||
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.
fall through while failed. because unit test always get this error, maybe due to CAP_IPC_LOCK or other reason. we get
ENOMEMwhen exec mlock:RuntimeError: [allocMem] mlock failed: Cannot allocate memoryThere 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 ulimit of lock memory may change