Linux: read ahead of the mapped loads at start
On Linux every load phase read its files one page fault (one 128 KB readahead) at a time, so a cold start spent most of its time waiting on the drive at queue depth ~2. A new platform::advise_willneed asks the kernel for a range in 128 KiB steps (WILLNEED reads at most one readahead window per call), and is called before the weight load, the native dense upload, the profile fill (256 pairs ahead, STRATA_FILL_AHEAD), the peer tier's fill (--peer-device), the resident RAM copy and the MTP draft files. STRATA_READ_AHEAD=0 turns it off. Each phase logs its time. Gen3 NVMe, RTX 5090, 32 GB, Q2_0 resident at 262K: ready in 70 s, was ~920 s.
This commit is contained in:
1 parent
2de94bca5e
commit
cb33c0bac5
10 files changed
+137
-10
No files matched your search
@@ -887,6 +887,23 @@ void FileExpertSource::prefetch_pairs(const std::pair<int32_t, int32_t>* pairs,
|
||||
fill_many(todo);
|
||||
}
|
||||
|
||||
bool FileExpertSource::advise_pairs(const std::pair<int32_t, int32_t>* pairs, int64_t n) const {
|
||||
if (base_ == nullptr || !direct_.empty() || !strata::platform::read_ahead_enabled()) return false;
|
||||
for (int64_t i = 0; pairs != nullptr && i < n; ++i) {
|
||||
const int64_t l = pairs[i].first, e = pairs[i].second;
|
||||
if (l < 0 || e < 0 || l >= n_layers_ || e >= n_expert_) continue;
|
||||
if (role_ptr_.empty()) { // experts.bin: the blob is one contiguous range
|
||||
if (const uint8_t* b = mapped_blob(l, e)) strata::platform::advise_willneed(b, layer_blob_bytes_[(size_t) l]);
|
||||
continue;
|
||||
}
|
||||
for (int r = 0; r < 3; ++r) {
|
||||
const size_t k = (size_t) (3 * l + r);
|
||||
strata::platform::advise_willneed(role_ptr_[k] + (size_t) ((uint64_t) e * role_bytes_[k]), role_bytes_[k]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void FileExpertSource::fill_many(const std::vector<Fill>& todo) {
|
||||
if (todo.empty()) return;
|
||||
if (!direct_.empty()) {
|
||||
@@ -1647,6 +1664,7 @@ bool FileExpertSource::pin_cache_complement(
|
||||
std::atomic<uint64_t> copied{0};
|
||||
std::atomic<bool> failed{false};
|
||||
std::mutex fail_mu;
|
||||
const auto copy_t0 = std::chrono::steady_clock::now();
|
||||
std::string fail_msg;
|
||||
auto fail = [&](const std::string& m) {
|
||||
std::lock_guard<std::mutex> lock(fail_mu);
|
||||
@@ -1668,6 +1686,13 @@ bool FileExpertSource::pin_cache_complement(
|
||||
batch.clear();
|
||||
return true;
|
||||
};
|
||||
if (direct_.empty()) { // mapped reads: ask for the layer's blobs before copying them
|
||||
std::vector<std::pair<int32_t, int32_t>> ahead;
|
||||
for (int64_t expert = 0; expert < n_expert_; ++expert)
|
||||
if (offsets[(size_t) layer * (size_t) n_expert_ + (size_t) expert] != kNoComplement)
|
||||
ahead.emplace_back((int32_t) layer, (int32_t) expert);
|
||||
(void) advise_pairs(ahead.data(), (int64_t) ahead.size());
|
||||
}
|
||||
for (int64_t expert = 0; expert < n_expert_; ++expert) {
|
||||
const size_t index = (size_t) layer * (size_t) n_expert_ + (size_t) expert;
|
||||
const uint64_t offset = offsets[index];
|
||||
@@ -1718,8 +1743,9 @@ bool FileExpertSource::pin_cache_complement(
|
||||
#endif
|
||||
const int64_t done = layers_done.fetch_add(1) + 1;
|
||||
if (done % 8 == 0 || done == n_layers_)
|
||||
std::fprintf(stderr, "FileExpertSource: copied cache complement through layer %lld/%lld (%.2f GiB)\n",
|
||||
(long long) done, (long long) n_layers_, (double) copied.load() / 1073741824.0);
|
||||
std::fprintf(stderr, "FileExpertSource: copied cache complement through layer %lld/%lld (%.2f GiB, %.0f s)\n",
|
||||
(long long) done, (long long) n_layers_, (double) copied.load() / 1073741824.0,
|
||||
std::chrono::duration<double>(std::chrono::steady_clock::now() - copy_t0).count());
|
||||
}
|
||||
};
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user