Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
madsbk committed Aug 18, 2023
1 parent b34b801 commit 6ed6212
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions cpp/src/interop/detail/arrow_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,25 @@ namespace detail {
/*
Enable Transparent Huge Pages (THP) for large (>4MB) allocations.
`buf` is returned untouched.
Enabling THP can improve performance of device-host memory transfers
significantly, see <https://github.com/rapidsai/cudf/pull/13914>.
*/
template <typename T>
T enable_hugepage(T buf)
{
if (buf->size() < (1u << 22u)) { // Smaller than 4 MB
return buf;
}
if(std::getenv("ENABLE_HUGEPAGEPATH") == nullptr) {
return buf;
}

#ifdef MADV_HUGEPAGE
const auto pagesize = sysconf(_SC_PAGESIZE);
void* addr = const_cast<uint8_t*>(buf->data());
if (addr == nullptr) { return buf; }
std::size_t length{static_cast<std::size_t>(buf->size())};
if (std::align(pagesize, pagesize, addr, length)) {
std::cout << "enable_hugepage() - length: " << length << std::endl;
// Intentionally not checking for errors that may be returned by older kernel versions;
// optimistically tries enabling huge pages.
madvise(addr, length, MADV_HUGEPAGE);
} else {
std::cout << "cannot align - length: " << length << ", addr: " << addr << std::endl;
}
#endif
return buf;
Expand Down

0 comments on commit 6ed6212

Please sign in to comment.