ple: keep the SSD awake while rows are read (STRATA_SSD_KEEPALIVE)
Some SSDs (here a WD_BLACK SN7100 on Windows 11) drop into a power state after ~250 ms without a command and stall the next reads 50-150 ms; the NVMe idle timeouts of Windows' power plan do not change it. In decode that hits the first read after a pause: at the start of a request, or after a few rounds whose rows all came from the row cache. --ple-io ram, which avoids the reads altogether, is not available on Windows. The reader's worker now reads one page of the table (a different one each time) when no read has gone out for 100 ms, until 60 s after the last issue; then the SSD may sleep until the next request re-arms it. A keep-alive read counts when it completes and stays out of the row-read counters and latencies; the "ple io" line adds "SSD kept awake by N reads (slowest X ms)". A keep-alive read that fails, or cannot be submitted, turns the keep-alive off instead of failing the reader. STRATA_SSD_KEEPALIVE=0 turns it off, =50 shortens the period; STRATA_SSD_KEEPALIVE_WINDOW sets the window in seconds. Only with the I/O worker (the default), not with --ple-sync-submit or --ple-io mmap/ram. The reader's statistics are now copied and reset under the worker's lock (snapshot()), since the worker may be counting a keep-alive read. The selftest checks the period, the window, the re-arm by a ticket the row cache serves, that rows and read counters are untouched, and that the caller-thread mode has none. A scan on that PC (reads after pauses of every length): 0 of 211 bursts stalled after pauses under 200 ms, 35 of 73 after 200 ms and more, 0 of 68 of those with the keep-alive on.
This commit is contained in:
1 parent
9d0b28df54
commit
4da8bfcbf9
6 files changed
+186
-10
No files matched your search
@@ -1923,6 +1923,17 @@ int main(int argc, char** argv) {
|
||||
pio.max_inflight = (uint32_t) o.ple_inflight;
|
||||
pio.cache_rows = (uint64_t) o.ple_row_cache;
|
||||
pio.io_thread = !o.ple_sync_submit;
|
||||
// Keep the SSD awake while rows are being asked for (PleReader::set_keepalive): some SSDs stall the first
|
||||
// reads 50-150 ms after ~250 ms without a command. STRATA_SSD_KEEPALIVE = ms without a read before one
|
||||
// page is read anyway (default 100, 0 = off), STRATA_SSD_KEEPALIVE_WINDOW = seconds after the last row
|
||||
// request that this goes on (default 60; then the SSD may sleep until the next request).
|
||||
{
|
||||
const char* ka = std::getenv("STRATA_SSD_KEEPALIVE");
|
||||
const char* kw = std::getenv("STRATA_SSD_KEEPALIVE_WINDOW");
|
||||
pio.keepalive_ms = ka != nullptr && *ka ? std::clamp(std::atof(ka), 0.0, 10000.0) : 100.0;
|
||||
pio.keepalive_window_s = kw != nullptr && *kw ? std::clamp(std::atof(kw), 1.0, 86400.0) : 60.0;
|
||||
if (pio.mode != strata::kernels::PleIo::Direct || !pio.io_thread) pio.keepalive_ms = 0;
|
||||
}
|
||||
if (!ple_table.open(o.ple_gguf, err, pio)) {
|
||||
std::fprintf(stderr, "strata generate: %s\n", err.c_str());
|
||||
return 1;
|
||||
@@ -1931,6 +1942,12 @@ int main(int argc, char** argv) {
|
||||
std::fprintf(stderr, "strata generate: PLE table %s (--ple-io ram) in %.1f s\n",
|
||||
ple_table.locked() ? "locked in RAM" : "loaded (not locked)",
|
||||
std::chrono::duration<double>(Clock::now() - tpl).count());
|
||||
if (pio.keepalive_ms > 0)
|
||||
std::fprintf(stderr, "strata generate: the SSD is kept awake while rows are read: one page of the table after "
|
||||
"%.0f ms without a read, until %.0f s after the last request "
|
||||
"(STRATA_SSD_KEEPALIVE=0 turns it off)\n", pio.keepalive_ms, pio.keepalive_window_s);
|
||||
else if (pio.mode == strata::kernels::PleIo::Direct)
|
||||
std::fprintf(stderr, "strata generate: SSD keep-alive off: the SSD may fall asleep between reads\n");
|
||||
const strata::core::WeightRef* wk = wt.find("blk.1.ple_key.weight");
|
||||
const strata::core::WeightRef* wv = wt.find("blk.1.ple_value.weight");
|
||||
const strata::core::WeightRef* wnk = wt.find("blk.1.ple_norm_key.weight");
|
||||
|
||||
Reference in new issue
Block a user