1
0
mirror of https://github.com/Zygo/bees.git synced 2025-06-16 09:36:17 +02:00

readahead: report the original size in BEESTOOLONG

BEESTOOLONG was always reporting a size of zero, and the offset of the
end of the readahead region.  Report the original size instead (and also
in BEESTRACE and BEESNOTE).

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
Zygo Blaxell
2022-12-30 14:36:55 -05:00
parent 9587c40677
commit c327e0bb10

View File

@ -215,7 +215,7 @@ BeesTooLong::operator=(const func_type &f)
} }
void void
bees_readahead(int const fd, off_t offset, size_t size) bees_readahead(int const fd, const off_t offset, const 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));
@ -230,18 +230,20 @@ bees_readahead(int const fd, off_t offset, size_t size)
// and might discard the readahead request entirely, // and might discard the readahead request entirely,
// so it's maybe, *maybe*, worth doing both. // so it's maybe, *maybe*, worth doing both.
BEESNOTE("emulating readahead " << name_fd(fd) << " offset " << to_hex(offset) << " len " << pretty(size)); BEESNOTE("emulating readahead " << name_fd(fd) << " offset " << to_hex(offset) << " len " << pretty(size));
while (size) { auto working_size = size;
auto working_offset = offset;
while (working_size) {
// don't care about multithreaded writes to this buffer--it is garbage anyway // don't care about multithreaded writes to this buffer--it is garbage anyway
static uint8_t dummy[BEES_READAHEAD_SIZE]; static uint8_t dummy[BEES_READAHEAD_SIZE];
size_t this_read_size = min(size, sizeof(dummy)); const size_t this_read_size = min(working_size, sizeof(dummy));
// Ignore errors and short reads. It turns out our size // Ignore errors and short reads. It turns out our size
// parameter isn't all that accurate, so we can't use // parameter isn't all that accurate, so we can't use
// the pread_or_die template. // the pread_or_die template.
(void)!pread(fd, dummy, this_read_size, offset); (void)!pread(fd, dummy, this_read_size, working_offset);
BEESCOUNT(readahead_count); BEESCOUNT(readahead_count);
BEESCOUNTADD(readahead_bytes, this_read_size); BEESCOUNTADD(readahead_bytes, this_read_size);
offset += this_read_size; working_offset += this_read_size;
size -= this_read_size; working_size -= this_read_size;
} }
#endif #endif
BEESCOUNTADD(readahead_ms, readahead_timer.age() * 1000); BEESCOUNTADD(readahead_ms, readahead_timer.age() * 1000);