Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/rabitqlib/index/hnsw/hnsw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ inline HierarchicalNSW::HierarchicalNSW(
offsetExData_ + size_ex_data_; // (# of edges + edges) + (cluster_id) + (external
// label) + (BinData) + (ExData)
data_level0_memory_ =
reinterpret_cast<char*>(malloc(max_elements_ * size_data_per_element_));
memory::huge_page_allocate<char>(max_elements_ * size_data_per_element_);
if (data_level0_memory_ == nullptr) {
throw std::runtime_error("Not enough memory");
}
Expand Down Expand Up @@ -549,7 +549,7 @@ inline void HierarchicalNSW::load(const char* filename) {
input.read(reinterpret_cast<char*>(&ef_construction_), sizeof(size_t));

const size_t centroids_bytes = num_cluster_ * padded_dim_ * sizeof(float);
centroids_memory_ = reinterpret_cast<char*>(malloc(centroids_bytes));
centroids_memory_ = memory::huge_page_allocate<char>(centroids_bytes);
if (centroids_memory_ == nullptr) {
throw std::runtime_error("Not enough memory: loadIndex failed to allocate centroids"
);
Expand All @@ -561,7 +561,7 @@ inline void HierarchicalNSW::load(const char* filename) {
);

data_level0_memory_ =
reinterpret_cast<char*>(malloc(max_elements_ * size_data_per_element_));
memory::huge_page_allocate<char>(max_elements_ * size_data_per_element_);

input.read(
data_level0_memory_,
Expand Down
8 changes: 8 additions & 0 deletions include/rabitqlib/utils/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ inline T* align_allocate(size_t nbytes) {
return static_cast<T*>(ptr);
}

inline constexpr size_t kHugePageSize = 2UL << 20;

// Allocate a large buffer backed by transparent huge pages.
template <typename T>
inline T* huge_page_allocate(size_t nbytes) {
return align_allocate<kHugePageSize, T, true>(nbytes);
}

static inline void prefetch_l1(const void* addr) {
#if defined(__SSE2__)
_mm_prefetch(addr, _MM_HINT_T0);
Expand Down
Loading