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

Function fadv_dontneed

nodedb-wal/src/mmap_reader.rs:53–74  ·  view source on GitHub ↗

Call `posix_fadvise(POSIX_FADV_DONTNEED)` on an open WAL segment fd. Once a segment has been iterated end-to-end during catchup, we don't need its pages in cache any longer. Release them back to the kernel so replay doesn't pin GiBs of page cache.

(fd: &std::fs::File, len: usize, path: &Path)

Source from the content-addressed store, hash-verified

51/// need its pages in cache any longer. Release them back to the kernel so
52/// replay doesn't pin GiBs of page cache.
53fn fadv_dontneed(fd: &std::fs::File, len: usize, path: &Path) {
54 if len == 0 {
55 return;
56 }
57 let rc = unsafe {
58 libc::posix_fadvise(
59 fd.as_raw_fd(),
60 0,
61 len as libc::off_t,
62 libc::POSIX_FADV_DONTNEED,
63 )
64 };
65 if rc == 0 {
66 observability::FADV_DONTNEED_COUNT.fetch_add(1, Ordering::Relaxed);
67 } else {
68 tracing::warn!(
69 path = %path.display(),
70 errno = rc,
71 "posix_fadvise(DONTNEED) failed on exhausted WAL segment",
72 );
73 }
74}
75
76/// Memory-mapped WAL segment reader.
77///

Callers 1

release_pagesMethod · 0.85

Calls 1

as_raw_fdMethod · 0.45

Tested by

no test coverage detected