Pre-fetch a range of pages into the page cache. Uses `madvise(MADV_WILLNEED)` which is non-blocking — the kernel initiates readahead I/O and returns immediately. The TPC core continues processing other work while pages load asynchronously. # Safety `ptr` must point to a valid mmap'd region of at least `len` bytes.
(ptr: *const u8, len: usize)
| 34 | /// |
| 35 | /// `ptr` must point to a valid mmap'd region of at least `len` bytes. |
| 36 | pub fn prefetch_pages(ptr: *const u8, len: usize) { |
| 37 | if ptr.is_null() || len == 0 { |
| 38 | return; |
| 39 | } |
| 40 | // Align to page boundary. |
| 41 | let page_size = 4096; |
| 42 | let aligned_ptr = (ptr as usize & !(page_size - 1)) as *mut libc::c_void; |
| 43 | let aligned_len = (len + page_size - 1) & !(page_size - 1); |
| 44 | |
| 45 | unsafe { |
| 46 | libc::madvise(aligned_ptr, aligned_len, libc::MADV_WILLNEED); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | /// Pre-fetch a batch of disjoint memory ranges. |
| 51 | /// |