MCPcopy Create free account
hub / github.com/Niko1221/Strata / gate_capacity

Method gate_capacity

engine/src/core/expert_source.cpp:2348–2378  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2346}
2347
2348void FileExpertSource::gate_capacity() {
2349 if (!gate_on_ || (gate_win_++ % 16) != 0) return;
2350 const uint64_t total = expert_bytes(), room = gate_cache_room();
2351 if (total == 0 || room == 0) return; // unknown: the state stays
2352 gate_ratio_ = (double) room / (double) total;
2353 // and the read-ahead must pay: the share of its bytes a layer then used, over these 16 windows (64 MB at least read
2354 // ahead to judge). Below STRATA_IO_PF_GATE_USEFUL (0.10) it closes (a RAM tier holds what it would read: an 18 GiB
2355 // RAM tier, 0% used, -9..-15% decode); closed for that reason, it opens again for a probe every 256 windows.
2356 const uint64_t pf = io_pf_bytes_.load(std::memory_order_relaxed), used = io_pf_used_bytes_.load(std::memory_order_relaxed);
2357 const uint64_t dpf = pf - gate_prev_pf_, dused = used - gate_prev_used_;
2358 gate_prev_pf_ = pf;
2359 gate_prev_used_ = used;
2360 if (dpf >= (64ull << 20)) gate_useful_ = (double) dused / (double) dpf;
2361 const bool open = gate_open_.load(std::memory_order_relaxed);
2362 // A benefit-only closure must still get its periodic probe in the hysteresis band.
2363 // Only a real capacity closure needs the high watermark before reopening.
2364 const bool room_ok = (open || gate_useless_) ? gate_ratio_ >= gate_lo_ : gate_ratio_ > gate_hi_;
2365 bool want = room_ok;
2366 // too little to read ahead (< 128 MB in 16 windows: the RAM and VRAM tiers hold what is predicted) costs the look-ahead's
2367 // second layer and the I/O threads for nothing (an 18 GiB RAM tier: 2.5 GB read ahead in a run, -9..-16% decode)
2368 if (room_ok && open && gate_win_ > 16 && (dpf < (128ull << 20) || gate_useful_ < gate_min_useful_)) {
2369 want = false;
2370 gate_useless_ = true;
2371 gate_useless_since_ = gate_win_;
2372 } else if (room_ok && !open && gate_useless_) {
2373 want = gate_win_ - gate_useless_since_ >= 256; // the probe
2374 if (want) gate_useless_ = false;
2375 }
2376 if (!room_ok) gate_useless_ = false;
2377 if (want != open) { gate_open_.store(want, std::memory_order_relaxed); ++gate_flips_; }
2378}
2379
2380// Fills buffer `v` (reserved by claim_stage) outside the lock, then publishes it.
2381bool FileExpertSource::fill_stage(size_t v, int64_t layer, int64_t expert, uint8_t* dst) {

Callers

nothing calls this directly

Calls 3

gate_cache_roomFunction · 0.85
loadMethod · 0.45
storeMethod · 0.45

Tested by

no test coverage detected