From 97d70ef4c5d583b3d22e78ad56fedba52072b40b Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Tue, 22 Jun 2021 22:10:28 -0400 Subject: [PATCH] bees: readahead() in the kernel is posix_fadvise(..., POSIX_FADV_WILLNEED) In theory, we don't need the pread() loop, because the kernel will do a better job with readahead(). In practice, we might still need the pread() code, as the readahead will occur at idle IO priority, which could adversely affect bees performance. More testing is required. Signed-off-by: Zygo Blaxell --- src/bees.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/bees.cc b/src/bees.cc index 979f914..9a01096 100644 --- a/src/bees.cc +++ b/src/bees.cc @@ -231,11 +231,12 @@ bees_readahead(int const fd, off_t offset, size_t size) Timer readahead_timer; BEESNOTE("readahead " << name_fd(fd) << " offset " << to_hex(offset) << " len " << pretty(size)); BEESTOOLONG("readahead " << name_fd(fd) << " offset " << to_hex(offset) << " len " << pretty(size)); - // This might not do anything? + // In the kernel, readahead() is identical to posix_fadvise(..., POSIX_FADV_DONTNEED) DIE_IF_NON_ZERO(readahead(fd, offset, size)); - // Make sure this data is in page cache - // Note spelling: readahead vs read ahead - BEESNOTE("read ahead " << name_fd(fd) << " offset " << to_hex(offset) << " len " << pretty(size)); +#if 0 + // Make sure this data is in page cache by brute force + // This isn't necessary and it might even be slower + BEESNOTE("emulating readahead " << name_fd(fd) << " offset " << to_hex(offset) << " len " << pretty(size)); while (size) { static uint8_t dummy[BEES_READAHEAD_SIZE]; size_t this_read_size = min(size, sizeof(dummy)); @@ -247,6 +248,7 @@ bees_readahead(int const fd, off_t offset, size_t size) offset += this_read_size; size -= this_read_size; } +#endif BEESCOUNTADD(readahead_ms, readahead_timer.age() * 1000); }