Skip to content

perf(fileservice): cache late scan reads without forced eviction - #32093

Merged
mergify[bot] merged 17 commits into
matrixorigin:mainfrom
aunjgr:perf/reuse-cache-admission
Nov 8, 2026
Merged

mergify[bot] merged 17 commits into
matrixorigin:mainfrom
aunjgr:perf/reuse-cache-admission

Conversation

@aunjgr

@aunjgr aunjgr commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #30849.

What this PR does / why we need it:

Persisted readers stop retaining decoded columns after a fixed scan-position threshold. Permit late reads to fill unused decoded-cache capacity on their first touch, while preventing their decode-buffer allocation from evicting resident data. Keep ordinary early reads and S3-FIFO replacement behavior unchanged.

Reserve actual allocator backing bytes before conversion. Account for pending fills and live buffers still held after eviction until their final release. When capacity is unavailable or pressure is active, decode transiently and prevent later rehoming into an eviction-capable allocation. Conditional publication rechecks capacity and pressure using ordinary S3-FIFO queue placement without eviction.

Carry the allocation mode through local, S3, disk-cache conversion and byte-decoding paths, preserving explicit write suppression, destination ownership and shared-decode policy separation. Known capacity refusal bypasses allocator/pressure locks and avoids advertising a memory fill that cannot publish; pending fills can still accept joins, disk publication remains independent, and transient conversion sharing remains available.

Review status

Ready for review at the requester's direction on 2026-11-08. The acceptance decision and benchmark evidence are recorded in comments. Earlier performance criteria and unresolved signals below remain available for review.

Prior readiness verification (2026-11-04)

The user updated the criterion on 2026-11-04: no confirmed query or Total regression is sufficient; a confirmed speedup is not required. Correctness, resource bounds, no-spill SF100 checks and applicable scale controls remain required.

  • Latest authoritative main dbf3efd4b5 merged without conflicts; full local pre-push checks passed before this update.
  • Independent SF10 and SF100 comparisons use clean main and one PR at a time, with cold full suites excluded and no benchmark-time data/result verification. The combined profiling branch is not used as acceptance.
  • SF100 uses all64 CPUs. A placement-sensitive pilot is preserved but excluded; every accepted arm uses the same interleaved NUMA policy. Any spilling invalidates SF100.
  • SF10 is accepted. Independent SF100 acceptance is incomplete: RAM Q18 and disk Q1/Q12/Q16/Q20/Q22 have slower-query intervals requiring confirmation or correction. Latest full query/Total tables and resource observations: perf(fileservice): cache late scan reads without forced eviction #32093 (comment)
  • The accepted campaign finished before the unrelated server workloads started. Later overlapping confirmations are excluded and stopped; awaiting a quiet server129 window. Earlier benchmark tables below retain their original source pins and are historical evidence.

Design

The approved design is versioned here. This revision keeps the existing decoded cache, reader threshold and S3-FIFO algorithm.

Validation

  • Normal owning packages passed: fileservice, fifocache, readutil, objectio and blockio.
  • Focused allocation/publication/lifecycle race tests passed.
  • Tests cover first-touch fill, stable fitting prefix through oversized repeated scans, competing reservations, held buffers after eviction, pressure/shrink, foreign data, failure/cancellation, explicit suppression, disk conversion and shared decoding.
  • Full final pre-push gate passed: module graph, conventions, molint, license headers/dependencies and golangci-lint (0 issues).

Performance evidence

New performance results will be appended as separate comments.

@aunjgr

aunjgr commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Why the cache gain disappears at SF100

Diagnosis of draft PR #32093, exact production head 255e5b419b0f12d77b351c42a922b4f86d769e75 against parent main f0d7f9ef7b.

Finding

The bounded FIFO observation history forgets a long cyclic scan before its next visit. The PR therefore continues bypassing decoded admission at SF100, even with most of the configured cache empty. SF10 fits within the history window and reaches decoded-cache hits. This is separate from SQL spilling.

Comparable isolated Q6 diagnostics

Fresh private clone/process per arm; both scales use all 32 local CPUs, 48 GiB application limit, no swap, 16 GiB CN SHARED decoded cache, fileservice disk cache disabled, agg_spill_mem=32 GiB. Four executions followed by separate CPU profiling and native EXPLAIN. First execution is cold and excluded from the following table. No input or result verification.

Scale Main warm wall, fourth call PR warm wall, fourth call PR decoded-cache hit rate PR physical disk read PR SHARED cache occupied
SF10 0.1797 s 0.0363 s 100.00% 0.000 GiB 1.693 / 16 GiB
SF100 3.1205 s 3.1257 s 5.71% 8.623 GiB 1.102 / 16 GiB

SF10 PR becomes 100% decoded-cache hits on execution 3; main remains about 56.4%. SF100 remains about 5.7% in both versions on execution 4. All four original cases have zero observed spill events, zero swap, and zero cache-pressure admission skips/evictions/triggers. The SF100 PR repeats roughly 278,000 local entry reads per query.

Source mechanism

  • reuse_admission.go:25: history allowance is min(cache_capacity/1024, 64 MiB), deducted from the existing payload budget. At 16 GiB cache this is 16 MiB.
  • fifocache/reuse.go:30: each full-key observation costs 256 + len(path) bytes.
  • fifocache/reuse.go:35-64: a late miss is admitted only after the key is already present in the cache/history namespace.
  • fifocache/reuse.go:96-107: history is trimmed FIFO by metadata bytes and separately by represented decoded bytes.
  • reader.go:1034-1037,1135: with 32 readers, the initial 129 blocks per reader keep ordinary admission; later blocks require reuse.

Native Q6 scans show 7,324 blocks at SF10 versus 73,684 at SF100. The ordinarily admitted prefix is roughly 4,128 blocks: about 56% of SF10 but only 5.6% of SF100. The SF10 late-key working set is about 12,800 entries; SF100 is about 278,000. Even with zero path bytes the 16 MiB history cannot retain more than 65,536 keys. A long repeated scan inserts new observations while evicting the previous pass before those keys can be reused.

Runtime confirmation of the binding limit

A separate diagnostic binary was built from the exact PR head using a Go build overlay, adding counters only. Tracked production sources and the scored benchmark binaries were unchanged. This run is diagnostic evidence, not scored performance evidence.

The last counter snapshot after repeated SF100 Q6 shows:

calls=1900544
admits=0
metadata_trims=1844245
represented_trims=0
metadata_used=16777102
metadata_limit=16777216
represented=3438431488
represented_limit=15446782772
path_len=42

The actual key cost is 298 bytes, so the history retains exactly 56,299 keys. The metadata limit binds while the history represents only about 3.20 GiB of decoded data, far below its separate 14.39 GiB represented-data bound. Every observed candidate in this isolated long cyclic scan is denied admission. Cache-space exhaustion and the represented-data bound are not causing these observed denials. This confirms the exact-key FIFO metadata window as the immediate cause.

All four query calls and the subsequent profiling/native calls in this diagnostic completed under the strict no-spill gate. Original uninstrumented diagnostics independently show the same cache hit behavior.

CPU evidence

Separate CPU-clock user profiles after four executions: SF100 PR has 38.63% self samples in LZ4 decode (main 47.67%); SF10 PR has no sampled LZ4 decode. SF10 profiles are short (126 PR samples), so percentages are directional, not a precise CPU savings estimate. The cache counters and physical-read deltas establish the miss behavior independently.

Valid SF100 whole-suite measurements (preliminary: two pairs)

Five planned pairs were paused after two complete pairs to diagnose the scaling failure. These are wall times; each startup had one excluded cold Q1-Q22 pass. No spilling was observed in either retained cold or scored pass. Two pairs do not establish performance acceptance.

Query Main mean wall (s) PR mean wall (s) Change
Q1 9.3126 9.6692 +3.83%
Q2 0.8332 0.2838 -65.94%
Q3 4.3759 4.4251 +1.12%
Q4 3.0397 3.1631 +4.06%
Q5 4.6660 4.3486 -6.80%
Q6 2.5558 2.6691 +4.43%
Q7 5.2473 5.3292 +1.56%
Q8 4.5274 4.4022 -2.77%
Q9 11.1918 11.0035 -1.68%
Q10 6.2904 6.4108 +1.91%
Q11 1.1187 0.3342 -70.12%
Q12 5.2055 5.3965 +3.67%
Q13 3.4968 3.4102 -2.48%
Q14 3.5161 3.3906 -3.57%
Q15 6.5479 6.7861 +3.64%
Q16 0.9309 0.8151 -12.45%
Q17 4.0943 4.4490 +8.66%
Q18 7.8212 7.6672 -1.97%
Q19 6.4933 6.2024 -4.48%
Q20 5.4683 5.1970 -4.96%
Q21 10.9881 11.1204 +1.20%
Q22 0.5503 0.5819 +5.73%
Total 108.2717 107.0552 -1.12%

The small-footprint queries Q2 and Q11 still improve by about 66% and 70%. Large lineitem scans do not receive the same cache benefit. This is consistent with the directly observed Q6 admission failure. Other query-specific differences have not been independently attributed.

Limits and next design requirement

More warmups do not repair FIFO history starvation. Increasing the SQL spill threshold fixed the invalid spilling setup but cannot repair decoded-cache admission. The 16 GiB payload cache also cannot hold an entire SF100 multi-column workload: Q6 alone reports 15.65 GiB of decoded InputSize before allocator overhead. Fixing history alone must not blindly admit a full oversized scan and recreate the earlier large-scale cache churn. Admission must preserve a bounded useful subset and recognize recurrence over a longer scan, while respecting the same configured memory limit and adding no cache tier.

The original 32 GiB application / 2 GiB aggregate-spill-threshold attempt is INVALID because spilling occurred; its timings and resource-exhaustion error are excluded from acceptance and regression claims. Server129 has not been used for this diagnosis.

@aunjgr aunjgr changed the title perf(fileservice): admit late decoded reads after observed reuse perf(fileservice): cache late scan reads without forced eviction Nov 3, 2026
@XuPeng-SH

XuPeng-SH commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 81dc205861d95334ee36a3ad2f830eb1770634d0

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 81dc205861d95334ee36a3ad2f830eb1770634d0

Assessment: request_changes

The design appropriately reuses existing reservation and FIFO owners. Validated remote-cache reads bypass the new no-eviction mode and require an integration fix. The recorded acceptance of the 1.89% SF1000 slowdown is preserved.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

  • P2 pkg/vm/engine/readutil/reader.go:1035: A late persisted read carries MemoryCacheNoEvict and receives a validated remote-cache hit while the destination memory cache is full.
    Impact: RemoteCache.Read uses the ordinary MemCache allocator, which evicts resident data before conditional publication. Late remote hits can therefore replace the resident working set despite the new policy.
    Evidence: cache.go:118-120 assigns the remote allocator to MemCache; remote_cache.go:171 bypasses allocatorForDecode. The LocalFS.Read probe fails resident preservation on the candidate (remote-cache-probe-v2.jsonl). Routing that copy through the entry-selected allocator passes both preservation and ordinary-read controls (remote-cache-control-retry.jsonl). Apply this routing and extend the existing remote-reservation test.

Validation:

  • Preflight, native build, frozen-source/delta and formatting checks passed; source remained unchanged.

  • All 10 new tests passed under race; the complete fifocache race suite passed. The candidate diagnostic reproduced the defect, and the allocator-routing control passed.

  • Reused frozen-head build, UT, SCA and compose BVT CI. All 12 discussion entries were reconciled; 11 terminal receipts match retained logs and inputs in validation-index.json.

Limitations:

  • The full fileservice race run timed out; a focused retry timed out during build/link. Complete package race validation and adaptive stress remain incomplete locally.

  • Remote transport was mocked. Performance evidence was reused as reported, including the accepted SF1000 slowdown and unresolved SF100 signals.

aunjgr commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the validated remote-cache allocation-policy bypass in c6855c678c.

RemoteCache.Read now copies validated response bytes through entry.allocatorForDecode(r.allocator). A full-cache late read uses transient storage and preserves resident entries; available capacity can still reserve/publish; explicit write suppression wins; ordinary reads retain their existing eviction behavior. The independently owned copy remains necessary because the RPC response is released after processing.

Merged authoritative main d7185c9a92 in 473acb6b87. Main has replaced the previous cache package with the reference-owning s3fifo implementation. Conditional publication now uses that implementation's ownership, charge guard, insertion notifications and small/main/ghost queue placement. It does not call an eviction path. The obsolete cache-package extension was removed.

Validation:

  • The new full-cache late-read case fails with the original allocator route and passes with the fix.
  • The existing reservation test now exercises LocalFS.Read with eight policy/validation cases, RPC-storage independence, resident membership, publication and cleanup accounting. Payloads are two bytes; transport is mocked.
  • Focused allocation/remote tests passed under race; affected fileservice, S3-FIFO and reader packages passed normal mode.
  • Complete fileservice and S3-FIFO race suites passed. The directly affected remote-hit case and concurrent conditional-publication case each passed 100 race repetitions.
  • The complete pre-push gate passed: package graph, MO conventions/molint, license headers/dependencies and golangci-lint (0 issues). Latest authoritative main is merged; the branch is zero commits behind it.

The recorded SF1000 measurements and the requester's acceptance remain historical evidence. This update adds no new TPC-H run or performance claim; the earlier performance comments remain unchanged.

@aunjgr
aunjgr requested a review from XuPeng-SH November 8, 2026 17:49

aunjgr commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

The current versioned design includes the integration with main's reference-owning S3-FIFO and the validated remote-hit allocator routing. The PR description is unchanged; the fix and validation record is appended separately. Review has been re-requested from XuPeng-SH.

@XuPeng-SH

XuPeng-SH commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: c6855c678ce17c9d71cbd7c0142181009b398e52

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: c6855c678ce17c9d71cbd7c0142181009b398e52

Assessment: approve

The remote-cache allocation bypass is resolved. Late reads reserve unused backing capacity and publish through existing S3-FIFO ownership and queue semantics without eviction; ordinary reads retain replacement behavior. The added accounting and allocation modes are justified by pending and pinned-buffer lifetimes. The recorded performance tradeoff remains accepted.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Reviewed all 17 changed files, affected allocation/publication/conversion owners, related issue #30849 and every discussion entry. Saved the change map, ownership audit and exact-once discussion assessment.

  • Local isolation preflight and frozen-source, whitespace, gofmt and discussion/CI identity checks passed; receipts and retained logs are reconciled in validation-ledger.json.

  • Frozen-head CI reports successful shared build, UT, SCA, coverage and compose BVT. Considered the current-head author's normal/race and 100-repeat remote/publication reports, with source verification of their policy and cleanup oracles.

Limitations:

  • No local Go tests completed: the default Go 1.26.6 rejected the required 1.27.1, and the explicit toolchain download timed out before compilation. Author raw execution logs were not supplied.

  • Remote transport is mocked. Historical SF1000 paired Total slowdown of 1.89% and unresolved SF100 signals remain recorded; requester acceptance is preserved. No fresh performance qualification of the new base is claimed.

@mergify mergify Bot added the queued label Nov 8, 2026
@mergify

mergify Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as 32dbfe1 at 20:42 UTC

1 h 34 min in the queue, 1 h 9 min of it CI.

So far

  • ✅ Entered the queue Sun 8 Nov, 19:08 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Passed · in place
  • ✅ Merged 20:42 · 32dbfe1 · squash
3 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = CI Required
    • check-neutral = CI Required
    • check-skipped = CI Required

Times in UTC · dashboard · how the merge queue works

This branch was previously deployed

1 inactive deployment
ci — 2a5215e9 Deployed Nov 8, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants