@@ -108,6 +108,13 @@ absl::Status create_file_and_mmap(const std::string& object_id, size_t size,
108108 return ErrnoToStatus (" mmap() failed for file: " + object_id);
109109 }
110110
111+ // On success, set kernel memory hints:
112+ // MADV_WILLNEED: expect access in the near future, so can prefetch
113+ // pages into memory in the background.
114+ // MADV_HUGEPAGE: use huge pages when possible, to minimize TLB misses and
115+ // improve read/write throughput.
116+ madvise (ptr, size, MADV_WILLNEED | MADV_HUGEPAGE);
117+
111118 // On success, set all the output parameters.
112119 out_fd = fd;
113120 out_data_size = size;
@@ -173,6 +180,13 @@ absl::Status open_file_and_mmap_ro(const std::string& object_id, int& out_fd,
173180 return ErrnoToStatus (" mmap() failed for file: " + object_id);
174181 }
175182
183+ // On success, set kernel memory hints:
184+ // MADV_WILLNEED: expect access in the near future, so can prefetch
185+ // pages into memory in the background.
186+ // MADV_HUGEPAGE: use huge pages when possible, to minimize TLB misses and
187+ // improve read throughput.
188+ madvise (ptr, size, MADV_WILLNEED | MADV_HUGEPAGE);
189+
176190 // On success, set all the output parameters.
177191 out_fd = fd;
178192 out_data_size = size;
@@ -271,4 +285,4 @@ absl::Status unmap_and_close(int fd, void* data_ptr, size_t data_size,
271285}
272286
273287} // namespace
274- // ml_flashpoint::checkpoint_object_manager::buffer_object::internal
288+ // ml_flashpoint::checkpoint_object_manager::buffer_object::internal
0 commit comments