You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sequential read: 141 Store demands for 64 MiB on base (read-ahead re-opens windows under concurrent FUSE reads) #779
Corrected 2026-11-24: The 141-demand measurement reproduces on the base on both engines, but the causal claim below is wrong: BATCH_BYTES is GC-mark-only and 1/4/8 MiB candidates all still measure 141/140. The read path re-opens the 8 MiB read-ahead window when the two FUSE receive workers deliver reads out of order. See the measurement and correction comment. The 20-demand figure at 910f686c is confirmed by its commit message.
What
mounted_sequential_read measures the Store demands of one 64 MiB sequential read through a real kernel mount. On the current layerfs_v2_0_0 (and on main) it takes about 141 Store demands, while the test's bound is 64 — so the test fails on the base itself, before any p4 work.
Why (base regression, not snapshot rollback)
d19d98f138 ("perf(gc): mark reads record headers, not pack bodies", 2026-11-17) is already in layerfs_v2_0_0 (verified: git merge-base --is-ancestor d19d98f138 up/release). It caps one object-demand call at
so a 64 MiB read is ~64 MiB / 512 KiB = 128 data demands plus ~13 metadata demands ≈ 141, on both SQLite and PostgreSQL. The earlier 20-demand figure belongs to 910f686c (2026-11-06), before that cap existed; the workspace client still asks for 8 MiB read-ahead streams, but the persistence path splits them at 512 KiB.
PR #770 only changed the test bound (64 → 192) and, after review, restored the release's 64 so the regression stays visible. It does not introduce the extra demands.
What to do
Pick one, with a measurement on both engines (the FUSE test needs a privileged host with /dev/fuse):
Raise/adapt the batch: let one call carry a sequential read-ahead window (e.g. 4–8 MiB), or make BATCH_BYTES grow with the read-ahead stream while keeping BATCH_RANGES as the hard cap. Measure demands and RSS (MOUNTED_READ prints rss_before_kb/vm_hwm_kb); 4 MiB should land near 20–30 demands.
Keep 512 KiB and lower the test bound to reflect the new batching, documenting the memory/latency trade (this changes the contract, so it needs the perf rationale from d19d98f138).
PR #770 keeps the 64 bound, so it will report this failure until the base is fixed; it is not a regression of that PR. Tracked here so the fix lands on the base rather than in the p4 PR.
Correction: 141 is real on the base, but the 512 KiB batch is not the cause
I re-ran mounted_sequential_read on throwaway builds of 87e46c65 (up/release) and on base + one-constant candidates. 141 Store demands reproduce on both engines, but the stated mechanism does not: BATCH_BYTES is used only by the GC mark's read_ranges, and changing it does not move the count.
mounted_sequential_read.rs: MOST_DEMANDS = 64 (:31); "Store demands" is the delta of store.work().object_batches, i.e. one counted StorePorts::read_canonical_batch (one StoreReader.objects call); one kernel read is 128 KiB.
The 20-demand figure is recorded in the 910f686c commit message: 541 -> 20 on both engines.
BATCH_BYTES is reached only from wave_edges (mark walk, walk.rs) and group_directories (kept-waste accounting, waste.rs). The mounted read path is BaseRead::emit -> CanonicalClient::read_through/read_ahead -> StorePorts::read_canonical_batch -> StoreReader.objects -> storage.read_objects; it never calls edges.rs, so the 8 MiB read-ahead stream is not split at 512 KiB.
Base repeats: 141, 141, 141, 140, 134 (the 134 run had eprintln instrumentation only). Each variant was a real rebuild: the build log recompiles layerfs-persistence and every dependent crate.
Actual cause
Instrumented base: 127 read_through calls, every one with until == start; 127 fetch_ahead calls of 21-37 objects (~25 = the uncached tail of a re-opened 8 MiB window), upstream_batches 137-143. The mount has two receive workers (RECEIVE_SLOTS = 2; logs show ThreadId(11) and ThreadId(12)), so 128 KiB READs arrive out of order. Streams::follow only continues a stream on exact adjacency (next == start); an out-of-order continuation opens a fresh stream whose until is its own end, and the next read that matches it re-opens the full 8 MiB window. fetch_ahead filters already-cached chunks, so each re-opened window costs one demand for its ~25-object tail: 127 tails + ~13 metadata demands ~= 141.
Recommendation
Do not raise or adapt BATCH_BYTES: no constant on that path is involved (1/4/8 MiB all measure 141/140). Fix the stream match instead: when no exact continuation exists, follow a window of the same root that already contains start (until > start) rather than opening a new one. A 12-line throwaway prototype on the base is memory-neutral (same 8 MiB READ_AHEAD, same 16 MiB READ_AHEAD_CACHE, same 64 MiB object cache) and lands at 20 SQLite / 27 PostgreSQL demands - the 910f686c range - with SQL statements also down (498 -> 314 SQLite, 284 -> 82 PostgreSQL). RSS/VmHWM stay in the same 100/175 MB band on SQLite (PostgreSQL +~13 MB in the single run; no cache or window size changed).
The test bound stays 64. I changed no release ref and pushed nothing; the branch, worktree and container used for this are throwaway and have been removed.
changed the title [-]Sequential read: 512 KiB object batches cost ~141 Store demands for 64 MiB (base regression since d19d98f138)[/-][+]Sequential read: 141 Store demands for 64 MiB on base (read-ahead re-opens windows under concurrent FUSE reads)[/+]on Nov 24, 2026
Activity
mengmengmengqiang commentedon Nov 24, 2026
Correction: 141 is real on the base, but the 512 KiB batch is not the cause
I re-ran
mounted_sequential_readon throwaway builds of87e46c65(up/release) and on base + one-constant candidates. 141 Store demands reproduce on both engines, but the stated mechanism does not:BATCH_BYTESis used only by the GC mark'sread_ranges, and changing it does not move the count.Verified statically
up/release=87e46c652a7c9caf80859f1ceb8dfddfaee10f36.git merge-base --is-ancestor d19d98f138 87e46c65-> 0:d19d98f138is in the base.edges.rs:BATCH_RANGES = 1024(:53),BATCH_BYTES = 512 * 1024(:55).mounted_sequential_read.rs:MOST_DEMANDS = 64(:31); "Store demands" is the delta ofstore.work().object_batches, i.e. one countedStorePorts::read_canonical_batch(oneStoreReader.objectscall); one kernel read is 128 KiB.910f686ccommit message: 541 -> 20 on both engines.BATCH_BYTESis reached only fromwave_edges(mark walk,walk.rs) andgroup_directories(kept-waste accounting,waste.rs). The mounted read path isBaseRead::emit -> CanonicalClient::read_through/read_ahead -> StorePorts::read_canonical_batch -> StoreReader.objects -> storage.read_objects; it never callsedges.rs, so the 8 MiB read-ahead stream is not split at 512 KiB.Measured (base 87e46c6)
Container
dsh:current,--privileged --network host,-v /home/dell/.dsh/layerfs/scratch:/scratch -v /home/dell/.cargo:/home/dell/.cargo, freshCARGO_TARGET_DIRper tree,TMPDIR=/scratch/tmp779; PostgreSQL 17 on 127.0.0.1:55432.Base repeats: 141, 141, 141, 140, 134 (the 134 run had
eprintlninstrumentation only). Each variant was a real rebuild: the build log recompileslayerfs-persistenceand every dependent crate.Actual cause
Instrumented base: 127
read_throughcalls, every one withuntil == start; 127fetch_aheadcalls of 21-37 objects (~25 = the uncached tail of a re-opened 8 MiB window),upstream_batches137-143. The mount has two receive workers (RECEIVE_SLOTS = 2; logs show ThreadId(11) and ThreadId(12)), so 128 KiB READs arrive out of order.Streams::followonly continues a stream on exact adjacency (next == start); an out-of-order continuation opens a fresh stream whoseuntilis its own end, and the next read that matches it re-opens the full 8 MiB window.fetch_aheadfilters already-cached chunks, so each re-opened window costs one demand for its ~25-object tail: 127 tails + ~13 metadata demands ~= 141.Recommendation
Do not raise or adapt
BATCH_BYTES: no constant on that path is involved (1/4/8 MiB all measure 141/140). Fix the stream match instead: when no exact continuation exists, follow a window of the same root that already containsstart(until > start) rather than opening a new one. A 12-line throwaway prototype on the base is memory-neutral (same 8 MiBREAD_AHEAD, same 16 MiBREAD_AHEAD_CACHE, same 64 MiB object cache) and lands at 20 SQLite / 27 PostgreSQL demands - the910f686crange - with SQL statements also down (498 -> 314 SQLite, 284 -> 82 PostgreSQL). RSS/VmHWM stay in the same 100/175 MB band on SQLite (PostgreSQL +~13 MB in the single run; no cache or window size changed).The test bound stays 64. I changed no release ref and pushed nothing; the branch, worktree and container used for this are throwaway and have been removed.
[-]Sequential read: 512 KiB object batches cost ~141 Store demands for 64 MiB (base regression since d19d98f138)[/-][+]Sequential read: 141 Store demands for 64 MiB on base (read-ahead re-opens windows under concurrent FUSE reads)[/+]fix(workspace): follow a containing read-ahead window instead of re-o…