diff --git a/src/ml_flashpoint/checkpoint_object_manager/buffer_object/buffer_helper.cpp b/src/ml_flashpoint/checkpoint_object_manager/buffer_object/buffer_helper.cpp index 4e54154..39862b7 100644 --- a/src/ml_flashpoint/checkpoint_object_manager/buffer_object/buffer_helper.cpp +++ b/src/ml_flashpoint/checkpoint_object_manager/buffer_object/buffer_helper.cpp @@ -108,6 +108,13 @@ absl::Status create_file_and_mmap(const std::string& object_id, size_t size, return ErrnoToStatus("mmap() failed for file: " + object_id); } + // On success, set kernel memory hints: + // MADV_WILLNEED: expect access in the near future, so can prefetch + // pages into memory in the background. + // MADV_HUGEPAGE: use huge pages when possible, to minimize TLB misses and + // improve read/write throughput. + madvise(ptr, size, MADV_WILLNEED | MADV_HUGEPAGE); + // On success, set all the output parameters. out_fd = fd; out_data_size = size; @@ -173,6 +180,13 @@ absl::Status open_file_and_mmap_ro(const std::string& object_id, int& out_fd, return ErrnoToStatus("mmap() failed for file: " + object_id); } + // On success, set kernel memory hints: + // MADV_WILLNEED: expect access in the near future, so can prefetch + // pages into memory in the background. + // MADV_HUGEPAGE: use huge pages when possible, to minimize TLB misses and + // improve read throughput. + madvise(ptr, size, MADV_WILLNEED | MADV_HUGEPAGE); + // On success, set all the output parameters. out_fd = fd; out_data_size = size; @@ -271,4 +285,4 @@ absl::Status unmap_and_close(int fd, void* data_ptr, size_t data_size, } } // namespace - // ml_flashpoint::checkpoint_object_manager::buffer_object::internal \ No newline at end of file + // ml_flashpoint::checkpoint_object_manager::buffer_object::internal