1
0
mirror of https://github.com/Zygo/bees.git synced 2025-05-17 21:35:45 +02:00

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 <bees@furryterror.org>
This commit is contained in:
Zygo Blaxell 2021-06-22 22:10:28 -04:00
parent a9cd19a5fe
commit 97d70ef4c5

View File

@ -231,11 +231,12 @@ bees_readahead(int const fd, off_t offset, size_t size)
Timer readahead_timer; Timer readahead_timer;
BEESNOTE("readahead " << name_fd(fd) << " offset " << to_hex(offset) << " len " << pretty(size)); BEESNOTE("readahead " << name_fd(fd) << " offset " << to_hex(offset) << " len " << pretty(size));
BEESTOOLONG("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)); DIE_IF_NON_ZERO(readahead(fd, offset, size));
// Make sure this data is in page cache #if 0
// Note spelling: readahead vs read ahead // Make sure this data is in page cache by brute force
BEESNOTE("read ahead " << name_fd(fd) << " offset " << to_hex(offset) << " len " << pretty(size)); // 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) { while (size) {
static uint8_t dummy[BEES_READAHEAD_SIZE]; static uint8_t dummy[BEES_READAHEAD_SIZE];
size_t this_read_size = min(size, sizeof(dummy)); 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; offset += this_read_size;
size -= this_read_size; size -= this_read_size;
} }
#endif
BEESCOUNTADD(readahead_ms, readahead_timer.age() * 1000); BEESCOUNTADD(readahead_ms, readahead_timer.age() * 1000);
} }