MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / prefetch_pages

Function prefetch_pages

nodedb/src/data/io/prefetch.rs:36–48  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

34///
35/// `ptr` must point to a valid mmap'd region of at least `len` bytes.
36pub 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///

Callers 2

prefetch_batchFunction · 0.85
prefetch_pages_null_safeFunction · 0.85

Calls 1

is_nullMethod · 0.45

Tested by 1

prefetch_pages_null_safeFunction · 0.68