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
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.
// 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);
}