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)
| 51 | /// need its pages in cache any longer. Release them back to the kernel so |
| 52 | /// replay doesn't pin GiBs of page cache. |
| 53 | fn 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 | /// |
no test coverage detected