BEESTRACE("e_second " << e_second);
// Preread entire extent
- bees_readahead(second.fd(), e_second.begin(), e_second.size());
- bees_readahead(first.fd(), e_second.begin() + first.begin() - second.begin(), e_second.size());
+ bees_readahead_pair(second.fd(), e_second.begin(), e_second.size(),
+ first.fd(), e_second.begin() + first.begin() - second.begin(), e_second.size());
auto hash_table = ctx->hash_table();
return *this;
}
+static
void
-bees_readahead(int const fd, const off_t offset, const size_t size)
+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));
DIE_IF_NON_ZERO(readahead(fd, offset, size));
#else
// Make sure this data is in page cache by brute force
- // This isn't necessary and it might even be slower,
- // but the btrfs kernel code does readahead with lower ioprio
- // and might discard the readahead request entirely,
- // so it's maybe, *maybe*, worth doing both.
+ // The btrfs kernel code does readahead with lower ioprio
+ // and might discard the readahead request entirely.
BEESNOTE("emulating readahead " << name_fd(fd) << " offset " << to_hex(offset) << " len " << pretty(size));
auto working_size = size;
auto working_offset = offset;
BEESCOUNTADD(readahead_ms, readahead_timer.age() * 1000);
}
+void
+bees_readahead_pair(int fd, off_t offset, size_t size, int fd2, off_t offset2, size_t size2)
+{
+ BEESNOTE("waiting to readahead " << name_fd(fd) << " offset " << to_hex(offset) << " len " << pretty(size)
+ << ", " << name_fd(fd2) << " offset " << to_hex(offset2) << " len " << pretty(size2));
+ static mutex only_one;
+ unique_lock<mutex> m_lock(only_one);
+ bees_readahead_nolock(fd, offset, size);
+ bees_readahead_nolock(fd2, offset2, size2);
+}
+
+void
+bees_readahead(int const fd, const off_t offset, const size_t size)
+{
+ BEESNOTE("waiting to readahead " << name_fd(fd) << " offset " << to_hex(offset) << " len " << pretty(size));
+ static mutex only_one;
+ unique_lock<mutex> m_lock(only_one);
+ bees_readahead_nolock(fd, offset, size);
+}
+
void
bees_unreadahead(int const fd, off_t offset, size_t size)
{
extern thread_local default_random_engine bees_generator;
string pretty(double d);
void bees_readahead(int fd, off_t offset, size_t size);
+void bees_readahead_pair(int fd, off_t offset, size_t size, int fd2, off_t offset2, size_t size2);
void bees_unreadahead(int fd, off_t offset, size_t size);
string format_time(time_t t);