diff --git a/docs/event-counters.md b/docs/event-counters.md index d376a3d..237826d 100644 --- a/docs/event-counters.md +++ b/docs/event-counters.md @@ -281,11 +281,14 @@ The `progress` event group consists of events related to progress estimation. readahead --------- -The `readahead` event group consists of events related to calls to `posix_fadvise`. +The `readahead` event group consists of events related to data prefetching (formerly calls to `posix_fadvise` or `readahead`, but now emulated in userspace). + * `readahead_bytes`: Number of bytes prefetched. + * `readahead_count`: Number of read calls. * `readahead_clear`: Number of times the duplicate read cache was cleared. - * `readahead_skip`: Number of times a duplicate read was identified in the cache and skipped. + * `readahead_fail`: Number of read errors during prefetch. * `readahead_ms`: Total time spent emulating readahead in user-space (kernel readahead is not measured). + * `readahead_skip`: Number of times a duplicate read was identified in the cache and skipped. * `readahead_unread_ms`: Total time spent running `posix_fadvise(..., POSIX_FADV_DONTNEED)`. replacedst diff --git a/src/bees.cc b/src/bees.cc index 95e2b47..e4a96ab 100644 --- a/src/bees.cc +++ b/src/bees.cc @@ -246,10 +246,6 @@ bees_readahead_nolock(int const fd, const off_t offset, const 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)); -#if 0 - // In the kernel, readahead() is identical to posix_fadvise(..., POSIX_FADV_DONTNEED) - DIE_IF_NON_ZERO(readahead(fd, offset, size)); -#else // Make sure this data is in page cache by brute force // The btrfs kernel code does readahead with lower ioprio // and might discard the readahead request entirely. @@ -263,13 +259,16 @@ bees_readahead_nolock(int const fd, const off_t offset, const size_t size) // Ignore errors and short reads. It turns out our size // parameter isn't all that accurate, so we can't use // the pread_or_die template. - (void)!pread(fd, dummy, this_read_size, working_offset); - BEESCOUNT(readahead_count); - BEESCOUNTADD(readahead_bytes, this_read_size); + const auto pr_rv = pread(fd, dummy, this_read_size, working_offset); + if (pr_rv >= 0) { + BEESCOUNT(readahead_count); + BEESCOUNTADD(readahead_bytes, pr_rv); + } else { + BEESCOUNT(readahead_fail); + } working_offset += this_read_size; working_size -= this_read_size; } -#endif BEESCOUNTADD(readahead_ms, readahead_timer.age() * 1000); }