Skip to content

Commit

Permalink
make mmap and stuff configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
vuule committed Oct 4, 2024
1 parent efaa0b5 commit 87549d1
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion cpp/src/io/utilities/datasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#include "file_io_utilities.hpp"
#include "getenv_or.hpp"

#include <cudf/detail/utilities/logger.hpp>
#include <cudf/detail/utilities/vector_factories.hpp>
Expand Down Expand Up @@ -227,14 +228,27 @@ class memory_mapped_source : public file_source {
}

private:
[[nodiscard]] bool should_register_mmap_buffer()
{
if (_map_addr == nullptr) { return false; }

auto const policy = getenv_or("LIBCUDF_MMAP_REGISTER_ENABLED", std::string{"AUTO"});

if (policy == "ALWAYS") { return true; }
if (policy == "AUTO") { return pageableMemoryAccessUsesHostPageTables(); }
if (policy == "OFF") { return false; }

CUDF_FAIL("Invalid LIBCUDF_MMAP_REGISTER_POLICY value: " + policy);
}

/**
* @brief Page-locks (registers) the memory range of the mapped file.
*
* Fixes nvbugs/4215160
*/
void register_mmap_buffer(size_t offset, size_t size)
{
if (_map_addr == nullptr or not pageableMemoryAccessUsesHostPageTables()) { return; }
if (not should_register_mmap_buffer()) { return; }

// Registered region must be within the mapped region
_reg_offset = std::max(offset, _map_offset);
Expand Down Expand Up @@ -267,8 +281,20 @@ class memory_mapped_source : public file_source {
}
}

[[nodiscard]] bool should_memory_map()
{
auto const policy = getenv_or("LIBCUDF_MMAP_ENABLED", std::string{"ON"});

if (policy == "ON") { return true; }
if (policy == "OFF") { return false; }

CUDF_FAIL("Invalid LIBCUDF_MMAP_ENABLED value: " + policy);
}

void map(int fd, size_t offset, size_t size)
{
if (not should_memory_map()) { return; }

CUDF_EXPECTS(offset < _file.size(), "Offset is past end of file", std::overflow_error);

// Offset for `mmap()` must be page aligned
Expand Down

0 comments on commit 87549d1

Please sign in to comment.