okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
6ca60e9a0
main
1// sycl/src/ngram/ple_reader.cpp - SYCL port: upstream src/ngram/ple_reader.cpp plus a per-gather timing trace 2// (STRATA_PLE_TRACE=1: where a decode round's PLE wait goes). See include/strata/ngram/ple_reader.hpp. 3#include <cstdio> 4#include <cstdlib> 5#include "strata/ngram/ple_reader.hpp" 6 7#include <algorithm> 8#include <chrono> 9#include <condition_variable> 10#include <cstring> 11#include <deque> 12#include <exception> 13#include <mutex> 14#include <thread> 15#include <unordered_map> 16 17namespace strata::ngram { 18 19using platform::Completion ; 20using platform::DirectFile ; 21using platform::now_us ; 22 23double ReaderStats ::percentile (double q )const { 24if (read_us .empty ())return 0.0 ; 25 std::vector < float > v (read_us ); 26const size_t k = std::min (v .size ()- 1 , (size_t ) (q * (double ) (v .size ()- 1 )+ 0.5 )); 27 std::nth_element (v .begin (),v .begin ()+ (ptrdiff_t )k ,v .end ()); 28return v [k ]; 29} 30 31namespace { 32 33constexpr size_t LATENCY_RING = 65536 ; 34constexpr uint32_t WAYS = 8 ; 35constexpr uint32_t EMPTY = 0xFFFFFFFFu ; 36 37/// Set-associative row cache: 8 ways per set, round-robin replacement inside a set. Bounded by construction. 38struct RowCache { 39uint64_t sets = 0 ; 40uint32_t rb = ROW_BYTES ;// bytes per row 41 std::vector < uint32_t > keys ;// sets * WAYS 42 std::vector < uint8_t > data ;// sets * WAYS * rb 43 std::vector < uint8_t > next ;// per-set replacement pointer 44uint64_t used = 0 ; 45 46void init (uint64_t rows ,uint32_t row_bytes = ROW_BYTES ) { 47sets = rows /WAYS ; 48rb = row_bytes ; 49keys .assign (sets * WAYS ,EMPTY ); 50data .assign (sets * WAYS * rb ,0 ); 51next .assign (sets ,0 ); 52used = 0 ; 53 } 54static uint64_t mix (uint32_t r ) { 55uint64_t x = r * 0x9E3779B97F4A7C15ull ; 56return x ^ (x >>29 ); 57 } 58const uint8_t * find (uint32_t row )const { 59if (sets == 0 )return nullptr ; 60const uint64_t s = mix (row ) %sets ; 61for (uint32_t w = 0 ;w < WAYS ;++ w ) 62if (keys [s * WAYS + w ]== row )return & data [(s * WAYS + w )* rb ]; 63return nullptr ; 64 } 65void insert (uint32_t row ,const uint8_t * bytes ) { 66if (sets == 0 || find (row )!= nullptr )return ; 67const uint64_t s = mix (row ) %sets ; 68uint32_t w = next [s ]; 69next [s ]= (uint8_t ) ((w + 1 ) %WAYS ); 70if (keys [s * WAYS + w ]== EMPTY )++ used ; 71keys [s * WAYS + w ]= row ; 72 std::memcpy (& data [(s * WAYS + w )* rb ],bytes ,rb ); 73 } 74}; 75 76struct Use { 77uint32_t row ; 78uint32_t in_page ;// byte offset of the row inside the read buffer 79uint8_t * dst ; 80}; 81 82struct Job { 83uint64_t offset = 0 ;// aligned file offset 84uint32_t length = 0 ;// PAGE or 2 * PAGE (a row that straddles a page boundary) 85uint32_t ticket = 0 ; 86 std::vector < Use > uses ; 87double issued_us = 0 ; 88bool keepalive = false;// no rows and no ticket: it only keeps the SSD awake (`set_keepalive`) 89}; 90 91struct TicketState { 92uint32_t pending = 0 ;// jobs not yet completed 93uint32_t jobs = 0 ;// SYCL port trace: jobs issued, and when it was issued / first submitted / last completed 94double t_issue = 0 ,t_first = 0 ,t_last = 0 ; 95}; 96bool ple_trace () { 97static const bool v = std::getenv ("STRATA_PLE_TRACE" )!= nullptr ; 98return v ; 99} 100 101}// namespace 102 103// THREADING. With `io_thread` (the default) one worker thread owns every DirectFile call: it submits queued jobs 104// and reaps completions, so `issue` on the caller's thread only builds jobs and wakes it (~11 us per ReadFile 105// no longer lands on the host loop). `mu` guards everything below except `file`, which only the worker touches 106// (plus `wake`, which is thread-safe). Without `io_thread` the caller does all of it, as before. 107struct PleReader ::Impl { 108DirectFile file ; 109uint64_t table_offset = 0 ; 110uint64_t n_rows = 0 ; 111uint32_t row_bytes = ROW_BYTES ; 112uint32_t max_inflight = 0 ; 113uint8_t * slab = nullptr ;// max_inflight slots of 2 pages 114 std::vector < uint32_t > free_slots ; 115 std::vector < Job > inflight ;// indexed by slot 116 std::vector < Completion > delayed ;// completed but held back by fault injection 117 std::deque < Job > queue ;// not yet submitted 118 std::unordered_map < uint32_t ,TicketState > tickets ; 119uint32_t next_ticket = 1 ; 120RowCache cache ; 121ReaderStats stats ; 122size_t ring_pos = 0 ; 123double delay_us = 0 ; 124 std::string error ; 125// the keep-alive (`set_keepalive`), steady-clock microseconds; `keep_us` 0 = off 126double keep_us = 0 ; 127double keep_window_us = 0 ; 128double last_issue_us = 0 ;// the last `issue` 129double last_read_us = 0 ;// the last read that went out, rows or keep-alive 130uint64_t rng = 0x9E3779B97F4A7C15ull ; 131 132bool threaded = false; 133bool stop = false; 134 std::mutex mu ; 135 std::condition_variable cv_work ;// worker: there is something to submit 136 std::condition_variable cv_done ;// collectors: a ticket may have completed 137 std::thread worker ; 138 139uint8_t * slot_buf (uint32_t s ) {return slab + (size_t )s * 2 * PAGE ; } 140bool busy ()const {return free_slots .size ()< max_inflight || !delayed .empty (); } 141 142void cancel_queued () { 143for (const Job & job :queue ) { 144auto it = tickets .find (job .ticket ); 145if (it != tickets .end ()&& it -> second .pending > 0 )-- it -> second .pending ; 146 } 147queue .clear (); 148 } 149 150void record_latency (double us ) { 151stats .read_us_sum += us ; 152if (stats .read_us .size ()< LATENCY_RING )stats .read_us .push_back ((float )us ); 153else stats .read_us [ring_pos ++ %LATENCY_RING ]= (float )us ; 154 } 155 156bool pump () { 157while (!queue .empty ()&& !free_slots .empty ()) { 158const uint32_t s = free_slots .back (); 159free_slots .pop_back (); 160inflight [s ]= std::move (queue .front ()); 161queue .pop_front (); 162Job & j = inflight [s ]; 163j .issued_us = now_us (); 164if (ple_trace ()) { 165auto tt = tickets .find (j .ticket ); 166if (tt != tickets .end ()&& tt -> second .t_first == 0 )tt -> second .t_first = j .issued_us ; 167 } 168 std::string kerr ;// a keep-alive read that cannot go out must not fail the reader 169if (!file .submit (j .offset ,slot_buf (s ),j .length ,s ,j .keepalive ?kerr :error )) { 170if (j .keepalive ) {// no more of them: the SSD may sleep as before 171keep_us = 0 ; 172j .keepalive = false; 173free_slots .push_back (s ); 174continue ; 175 } 176j .uses .clear (); 177auto it = tickets .find (j .ticket ); 178if (it != tickets .end ()&& it -> second .pending > 0 )-- it -> second .pending ; 179free_slots .push_back (s ); 180cancel_queued (); 181return false; 182 } 183last_read_us = j .issued_us ; 184if (!j .keepalive ) {// a keep-alive read counts when it completes (`finish`) 185stats .submit_us += now_us ()- j .issued_us ; 186++ stats .reads ; 187 } 188 } 189return true; 190 } 191 192/// When the next keep-alive read is due, or < 0 when none is: it is off, the reader failed, or no rows 193/// were asked for within the window (then the SSD may sleep; the next `issue` re-arms it). 194double keepalive_due (double now )const { 195if (keep_us <=0 || !error .empty ()|| last_issue_us <=0 || now - last_issue_us > keep_window_us )return -1 ; 196return last_read_us + keep_us ; 197 } 198 199/// One page of the table, a different one each time, so the SSD really reads (not its controller's buffer). 200void queue_keepalive () { 201rng ^=rng <<13 ; 202rng ^=rng >>7 ; 203rng ^=rng <<17 ; 204const uint64_t first = table_offset /PAGE ,end = (table_offset + n_rows * (uint64_t )row_bytes ) /PAGE ; 205Job j ; 206j .offset = (first + (end > first ?rng % (end - first ) :0 ))* PAGE ; 207j .length = PAGE ; 208j .keepalive = true; 209queue .push_back (std::move (j )); 210 } 211 212bool finish (const Completion & c ) { 213const uint32_t s = (uint32_t )c .tag ; 214if (s >=inflight .size ()) { 215error = "PleReader: invalid table-read completion" ; 216cancel_queued (); 217return false; 218 } 219Job & j = inflight [s ]; 220if (j .keepalive ) {// no rows: it counts once it is done, with how long it took; 221if (c .ok ) {// a failed one turns the keep-alive off, not the reader 222++ stats .keepalive_reads ; 223stats .keepalive_us_max = std::max (stats .keepalive_us_max ,now_us ()- j .issued_us ); 224 }else { 225keep_us = 0 ; 226 } 227j .keepalive = false; 228free_slots .push_back (s ); 229return error .empty () ?pump () : true; 230 } 231if (!c .ok ) { 232error = "PleReader: a table read failed" ; 233cancel_queued (); 234j .uses .clear (); 235auto it = tickets .find (j .ticket ); 236if (it != tickets .end ()&& it -> second .pending > 0 )-- it -> second .pending ; 237free_slots .push_back (s ); 238return false; 239 } 240record_latency (now_us ()- j .issued_us ); 241stats .bytes += c .bytes ; 242const uint8_t * buf = slot_buf (s ); 243for (const Use & u :j .uses ) { 244if (u .in_page + row_bytes > c .bytes ) { 245error = "PleReader: short read inside the table" ; 246cancel_queued (); 247j .uses .clear (); 248auto it = tickets .find (j .ticket ); 249if (it != tickets .end ()&& it -> second .pending > 0 )-- it -> second .pending ; 250free_slots .push_back (s ); 251return false; 252 } 253 } 254for (const Use & u :j .uses ) { 255 std::memcpy (u .dst ,buf + u .in_page ,row_bytes ); 256cache .insert (u .row ,buf + u .in_page ); 257 } 258auto it = tickets .find (j .ticket ); 259if (it != tickets .end ()&& it -> second .pending > 0 )-- it -> second .pending ; 260if (ple_trace ()&& it != tickets .end ())it -> second .t_last = now_us (); 261j .uses .clear (); 262free_slots .push_back (s ); 263return error .empty () ?pump () : true; 264 } 265 266/// Completions (or wake packets) just returned by `file.wait`, applying fault injection. 267bool process (const Completion * got ,int n ) { 268bool ok = true; 269for (int i = 0 ;i < n ;++ i ) { 270if (got [i ].tag == DirectFile ::WAKE_TAG )continue ; 271if (got [i ].tag >=inflight .size ()) { 272error = "PleReader: invalid table-read completion" ; 273cancel_queued (); 274ok = false; 275continue ; 276 } 277if (delay_us > 0 && now_us ()- inflight [(uint32_t )got [i ].tag ].issued_us < delay_us ) { 278delayed .push_back (got [i ]); 279++ stats .late_injected ; 280continue ; 281 } 282if (!finish (got [i ]))ok = false;// drain the rest of this batch so no completed slot is stranded 283 } 284return ok ; 285 } 286 287bool release_delayed () { 288const double now = now_us (); 289for (size_t i = 0 ;i < delayed .size ();) { 290if (now - inflight [(uint32_t )delayed [i ].tag ].issued_us >=delay_us ) { 291const Completion c = delayed [i ]; 292delayed .erase (delayed .begin ()+ (ptrdiff_t )i ); 293if (!finish (c ))return false; 294 }else { 295++ i ; 296 } 297 } 298return true; 299 } 300 301/// Caller-thread mode: process whatever has completed; blocks up to `timeout_ms` for the first completion. 302bool drain (int timeout_ms ) { 303Completion got [64 ]; 304if (!delayed .empty ()) { 305if (!release_delayed ())return false; 306timeout_ms = 0 ;// keep polling the held completions 307 } 308const int n = file .wait (got ,64 ,timeout_ms ); 309return process (got ,n ); 310 } 311 312void worker_loop () { 313 std::unique_lock < std::mutex > lk (mu ); 314for (;;) { 315// Idle: wait for work. While rows are being asked for, the wait ends in time for a keep-alive read. 316while (!(stop || !queue .empty ()|| busy ())) { 317const double now = now_us (); 318const double due = keepalive_due (now ); 319if (due < 0 )cv_work .wait (lk ); 320else if (now >=due )queue_keepalive (); 321else cv_work .wait_for (lk , std::chrono::microseconds (std::max < int64_t > (1000 , (int64_t ) (due - now )))); 322 } 323if (stop && !busy ())break ; 324if (error .empty ()&& !pump ()&& error .empty ())error = "PleReader: submit failed" ; 325if (!delayed .empty ()&& !release_delayed ()&& error .empty ())error = "PleReader: read failed" ; 326if (!error .empty ()) { 327cv_done .notify_all (); 328if (!busy ()) {cv_work .wait (lk , [& ] {return stop ; });break ; } 329 } 330if (!busy ()) {cv_done .notify_all ();continue ; } 331// Block in the port WITHOUT the lock, so `issue` can queue work; `issue` wakes us with a packet. 332const int timeout = delayed .empty () ?-1 :0 ; 333lk .unlock (); 334Completion got [64 ]; 335const int n = file .wait (got ,64 ,timeout ); 336lk .lock (); 337if (!process (got ,n )&& error .empty ())error = "PleReader: read failed" ; 338cv_done .notify_all (); 339 } 340 } 341}; 342 343PleReader ::PleReader () :impl_ (new Impl ) {} 344PleReader ::~PleReader () { 345close (); 346delete impl_ ; 347} 348 349bool PleReader ::open (const std::string & path ,uint64_t table_offset ,uint64_t n_rows ,uint32_t max_inflight , 350uint64_t cache_rows , std::string & err ,bool io_thread ,uint32_t row_bytes ) { 351close (); 352if (max_inflight == 0 || max_inflight > 1024 ) {err = "PleReader: max_inflight must be 1..1024" ;return false; } 353if (row_bytes == 0 || row_bytes > PAGE ) {err = "PleReader: row_bytes must be 1..4096" ;return false; } 354if (!impl_ -> file .open (path ,err ))return false; 355impl_ -> row_bytes = row_bytes ; 356if (table_offset + n_rows * (uint64_t )row_bytes > impl_ -> file .size ()) { 357err = "PleReader: the table extends past the end of " + path ; 358close (); 359return false; 360 } 361impl_ -> table_offset = table_offset ; 362impl_ -> n_rows = n_rows ; 363impl_ -> max_inflight = max_inflight ; 364impl_ -> slab = (uint8_t * )DirectFile ::alloc_aligned ((size_t )max_inflight * 2 * PAGE ); 365if (impl_ -> slab == nullptr ) {err = "PleReader: cannot allocate read buffers" ;close ();return false; } 366impl_ -> inflight .assign (max_inflight ,Job {}); 367impl_ -> free_slots .clear (); 368for (uint32_t s = max_inflight ;s -- > 0 ;)impl_ -> free_slots .push_back (s ); 369impl_ -> cache .init (cache_rows ,row_bytes ); 370impl_ -> error .clear (); 371impl_ -> keep_us = 0 ; 372impl_ -> last_issue_us = impl_ -> last_read_us = 0 ; 373impl_ -> rng = 0x9E3779B97F4A7C15ull ^ (uint64_t )now_us (); 374if (impl_ -> rng == 0 )impl_ -> rng = 1 ; 375reset_stats (); 376impl_ -> stop = false; 377impl_ -> threaded = io_thread ; 378if (io_thread ) { 379try { 380impl_ -> worker = std::thread ([this ] {impl_ -> worker_loop (); }); 381 }catch (const std::exception & e ) { 382err = std::string ("PleReader: cannot create I/O worker: " )+ e .what (); 383close (); 384return false; 385 }catch (...) { 386err = "PleReader: cannot create I/O worker" ; 387close (); 388return false; 389 } 390 } 391return true; 392} 393 394void PleReader ::close () { 395Impl & m = * impl_ ; 396if (m .worker .joinable ()) { 397 { 398 std::lock_guard < std::mutex > lk (m .mu ); 399m .stop = true; 400m .queue .clear ();// unsubmitted work is dropped; in-flight reads still drain 401 } 402m .cv_work .notify_all (); 403m .file .wake (); 404m .worker .join (); 405 } 406// Outstanding reads must finish before their buffers are released (caller-thread mode, or a worker that 407// stopped on an error). 408if (m .file .is_open ()) { 409while (m .free_slots .size ()< m .max_inflight ) { 410Completion c [64 ]; 411const int n = m .file .wait (c ,64 ,-1 ); 412if (n == 0 )break ; 413for (int i = 0 ;i < n ;++ i ) 414if (c [i ].tag != DirectFile ::WAKE_TAG )m .free_slots .push_back ((uint32_t )c [i ].tag ); 415 } 416 } 417m .file .close (); 418DirectFile ::free_aligned (m .slab ); 419m .slab = nullptr ; 420m .queue .clear (); 421m .tickets .clear (); 422m .delayed .clear (); 423m .inflight .clear (); 424m .free_slots .clear (); 425m .cache .init (0 ); 426m .threaded = false; 427m .stop = false; 428m .keep_us = 0 ; 429m .last_issue_us = m .last_read_us = 0 ; 430} 431 432bool PleReader ::is_open ()const {return impl_ -> file .is_open (); } 433uint32_t PleReader ::row_bytes ()const {return impl_ -> row_bytes ; } 434 435PleReader ::Ticket PleReader ::issue (const uint32_t * rows ,size_t n ,uint8_t * out_raw ) { 436Impl & m = * impl_ ; 437 std::unique_lock < std::mutex > lk (m .mu , std::defer_lock ); 438if (m .threaded )lk .lock (); 439const uint32_t id = m .next_ticket ++ ; 440if (m .next_ticket == 0 )m .next_ticket = 1 ; 441const double now = now_us (); 442const bool rearm = m .keep_us > 0 && (m .last_issue_us <=0 || now - m .last_issue_us > m .keep_window_us ); 443m .last_issue_us = now ; 444TicketState & ts = m .tickets [id ]; 445// After a failed read the reader stays failed (`collect` reports `error` until the next `open`) and its worker has 446// parked (worker_loop). A ticket queued now would never be read and `collect` would wait for it for ever, so it 447// is not queued: it has no jobs, and `collect` returns the error at once. 448if (!m .error .empty ()) { 449ts .pending = 0 ; 450return Ticket {id }; 451 } 452 std::unordered_map < uint64_t ,size_t > by_page ;// aligned offset -> index in `jobs` 453 std::vector < Job > jobs ; 454for (size_t i = 0 ;i < n ;++ i ) { 455const uint32_t rb = m .row_bytes ; 456uint8_t * dst = out_raw + i * rb ; 457++ m .stats .requests ; 458if (rows [i ] >=m .n_rows ) { 459 std::memset (dst ,0 ,rb ); 460continue ; 461 } 462if (const uint8_t * hit = m .cache .find (rows [i ])) { 463 std::memcpy (dst ,hit ,rb ); 464++ m .stats .cache_hits ; 465continue ; 466 } 467const uint64_t at = m .table_offset + (uint64_t )rows [i ]* rb ; 468const uint64_t first = at /PAGE * PAGE ; 469const uint32_t length = (uint32_t ) ((at + rb - 1 ) /PAGE * PAGE - first + PAGE ); 470auto f = by_page .find (first ); 471if (f != by_page .end ()) { 472Job & j = jobs [f -> second ]; 473j .length = std::max (j .length ,length ); 474j .uses .push_back (Use {rows [i ], (uint32_t ) (at - first ),dst }); 475++ m .stats .dedup_rows ; 476continue ; 477 } 478by_page .emplace (first ,jobs .size ()); 479Job j ; 480j .offset = first ; 481j .length = length ; 482j .ticket = id ; 483j .uses .push_back (Use {rows [i ], (uint32_t ) (at - first ),dst }); 484jobs .push_back (std::move (j )); 485 } 486// Sorted by offset: prefill chunks then read the SSD in near-sequential order. 487 std::sort (jobs .begin (),jobs .end (), [](const Job & a ,const Job & b ) {return a .offset < b .offset ; }); 488ts .pending = (uint32_t )jobs .size (); 489ts .jobs = ts .pending ; 490ts .t_issue = now_us (); 491const bool has_jobs = ts .pending > 0 ; 492for (Job & j :jobs )m .queue .push_back (std::move (j )); 493if (m .threaded ) { 494lk .unlock (); 495if (has_jobs ) { 496m .cv_work .notify_one (); 497m .file .wake ();// in case the worker is blocked in the port 498 }else if (rearm ) { 499m .cv_work .notify_one ();// the keep-alive had lapsed: start it again 500 } 501 }else if (!m .pump ()&& m .error .empty ()) { 502m .error = "PleReader: submit failed" ; 503 } 504return Ticket {id }; 505} 506 507bool PleReader ::collect (Ticket t , std::string & err ) { 508Impl & m = * impl_ ; 509const double start = now_us (); 510if (m .threaded ) { 511 std::unique_lock < std::mutex > lk (m .mu ); 512auto it = m .tickets .find (t .id ); 513if (it == m .tickets .end ()) {err = "PleReader: unknown ticket" ;return false; } 514m .cv_done .wait (lk , [& ] { 515const auto current = m .tickets .find (t .id ); 516return current == m .tickets .end ()|| current -> second .pending == 0 ; 517 }); 518it = m .tickets .find (t .id ); 519if (it == m .tickets .end ()) {err = "PleReader: unknown ticket" ;return false; } 520if (!m .error .empty ()) {err = m .error ;m .tickets .erase (it );return false; } 521m .stats .wait_us += now_us ()- start ; 522if (ple_trace ()&& it -> second .jobs > 0 && it -> second .jobs < 200 ) { 523const TicketState & ts = it -> second ; 524const double now = now_us (); 525 std::fprintf (stderr ,"ple trace: %3u jobs issue->submit %8.1f submit->last %8.1f last->return %8.1f " 526"collect wait %8.1f us\n" ,ts .jobs ,ts .t_first - ts .t_issue ,ts .t_last - ts .t_first , 527now - ts .t_last ,now - start ); 528 } 529m .tickets .erase (it ); 530return true; 531 } 532auto it = m .tickets .find (t .id ); 533if (it == m .tickets .end ()) {err = "PleReader: unknown ticket" ;return false; } 534while (it -> second .pending > 0 ) { 535const bool drained = m .drain (-1 ); 536if (!drained && m .error .empty ())m .error = "PleReader: read failed" ; 537it = m .tickets .find (t .id ); 538if (it == m .tickets .end ()) {err = "PleReader: unknown ticket" ;return false; } 539 } 540if (!m .error .empty ()) {err = m .error ;m .tickets .erase (it );return false; } 541m .stats .wait_us += now_us ()- start ; 542m .tickets .erase (it ); 543return true; 544} 545 546void PleReader ::set_keepalive (double period_ms ,double window_s ) { 547Impl & m = * impl_ ; 548 { 549 std::lock_guard < std::mutex > lk (m .mu ); 550m .keep_us = m .threaded && period_ms > 0 ?period_ms * 1000.0 :0.0 ; 551m .keep_window_us = window_s > 0 ?window_s * 1e6 :0.0 ; 552 } 553m .cv_work .notify_all (); 554} 555 556void PleReader ::set_injected_delay_us (double delay_us ) { 557 std::lock_guard < std::mutex > lk (impl_ -> mu ); 558impl_ -> delay_us = delay_us < 0 ?0 :delay_us ; 559} 560const ReaderStats & PleReader ::stats ()const {return impl_ -> stats ; } 561ReaderStats PleReader ::snapshot ()const { 562Impl & m = * impl_ ; 563 std::unique_lock < std::mutex > lk (m .mu , std::defer_lock ); 564if (m .threaded )lk .lock (); 565return m .stats ; 566} 567void PleReader ::reset_stats () { 568Impl & m = * impl_ ; 569 std::unique_lock < std::mutex > lk (m .mu , std::defer_lock ); 570if (m .threaded )lk .lock ();// the worker may be counting a keep-alive read 571m .stats = ReaderStats {}; 572m .ring_pos = 0 ; 573} 574uint64_t PleReader ::cache_capacity ()const {return impl_ -> cache .sets * WAYS ; } 575uint64_t PleReader ::cache_size ()const {return impl_ -> cache .used ; } 576 577}// namespace strata::ngram