-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Cache and Eviction
-
None
-
Storage Engines - Transactions
-
4,823.02
-
SE Transactions - 2026-05-22, SE Transactions - 2026-06-05, SE Transactions - 2026-06-19, SE Transactions - 2026-07-03, SE Transactions - 2026-07-17, SE Transactions - 2026-07-31, SE Transactions - 2026-08-14, SE Transactions - 2026-08-28, SE Transactions - 2026-09-11, SE Transactions - 2026-09-25, SE Transactions - 2026-10-09, SE Transactions - 2027-01-29
-
5
Motivation
On large caches (18 GB+) under high update pressure, the eviction walker is the candidate-discovery bottleneck: it samples the btree hoping to find the oldest dirty pages before pressure reaches the trigger, and on fast dirty generation it cannot keep up. The WT-17234 investigation demonstrated this across eight tuning attempts — deeper sampling, walker persistence, dominance gating, cache-fill gates — every variant that helped one workload class hurt another. FTDC on the failing approaches showed the walker doing 1.83x the work of baseline while delivering 32% lower insert throughput.
This ticket implements a structurally different approach: drive dirty-candidate discovery from the write path instead of from walker sampling. The walker stops being the throughput-limiting component; it only has to drain entries the producer has already identified.
Design
The full ring protocol, including the slot sequence states, is documented in a block comment above WTI_DIRTY_INDEX in src/evict/evict_private.h.
Producer (modify path, src/evict/evict_dirty_index.c)
Every successful cursor modify announces the dirty leaf ref into a per-btree bounded ring (WTI_DIRTY_INDEX). The ring is a fixed-size circular array where each slot carries the WT_REF pointer plus its own sequence counter, independent of the shared head/tail counters (slot = position \& mask, capacity a power of two). The drain also reinserts filtered pages, and the LRU trim reinserts trimmed dirty leaves.
- Capacity: derived from the btree's on-disk file size divided by an estimated page count (min(maxleafpage, 64KB)), clamped to [WTI_DIRTY_INDEX_MIN_CAPACITY (16K), WTI_DIRTY_INDEX_MAX_CAPACITY (256K)] slots and rounded up to a power of two. The history store always gets the maximum capacity. Allocated once when the btree handle opens (_wt_dirty_index_alloc) and freed at handle close (_wt_dirty_index_destroy); capacity is fixed for the handle's lifetime. Metadata, read-only, no-evict, salvage, verify and checkpoint handles get no ring.
- Dedup: WT_PAGE.dirty_index_slot is a one-indexed back-pointer; a page already in the ring is a single relaxed atomic load + branch, no ring access. Two sentinels mark a page holding no slot: NONE (never inserted) and CLEARED (a claim was released); a third, BLOCKED, is held by split retirement.
- Slot reservation: a producer CAS-advances head, but only once the target slot's sequence counter confirms the previous occupant has already been drained. A sequence lagging the reserved position means the ring is full (counted as insert_ring_full) — the producer bails rather than overwrite a live entry or block. A sequence ahead of it means another producer just took the position, so the producer retries.
- Slot ownership isn't page ownership: winning the slot CAS still requires winning a second CAS on the page's back-pointer (NONE/CLEARED → this slot), then re-validating that ref/page/state didn't change underneath it. Losing either race abandons the slot (insert_contended) instead of blocking — the ring is best-effort, the tree walker remains the source of truth.
- Low-pressure gate: on a disaggregated connection, a page the candidacy filter would reject for too few modifications under low pressure is not inserted.
- head and tail are padded onto separate cache lines so the single-consumer drain's tail update can't bounce the line the producers are spinning on.
Consumer (drain)
The dirty-index helpers live in src/evict/evict_dirty_index.c; the drain itself (_evict_dirty_index_drain, evict_dirty_index_drain_ring) lives alongside _evict_walk_tree in src/evict/evict_walk.c, since it shares that function's per-tree queue-slot budget and candidacy filter.
- The drain runs before the walker on each per-btree visit, filling the leading portion of the tree's queue-slot budget for this pass; whatever it doesn't fill, the walker's tree traversal covers. It runs only under dirty or updates pressure.
- Each popped ref is protected by a short-lived hazard pointer before ref->page is dereferenced. WT_GEN_SPLIT is held across the pop loop so a concurrent split cannot reclaim a ref still sitting in the ring. A ref whose hazard pointer is busy ends the pass (drain_hazard).
- Every popped candidate passes through the walker's own per-page candidacy filter (__evict_try_queue_page), so drain and walker apply identical rules. A candidate rejected by the filter is re-inserted at the back of the ring rather than dropped (drain_reinserted).
- Checkpoint interaction: a btree being checkpointed, or a disaggregated btree already visited by the running checkpoint, cannot have dirty pages evicted right now; the drain is skipped for that pass. Under a precise checkpoint, pages whose newest commit timestamp is ahead of the pinned stable timestamp are also not evictable; the drain tracks the timestamp range and parks until pinned stable crosses the midpoint.
Lifetime safety
- Page discard / eviction: __wt_dirty_index_clear_page empties the slot the back-pointer names before the WT_REF or WT_PAGE is reclaimed, falling back to a live-span search when needed.
- Split retirement: _wt_dirty_index_block_page moves the back-pointer to BLOCKED, removes the ref from the ring, and stashes it at _wt_dirty_index_retire_gen to cover drains already holding it.
- Temporary refs never enter the ring because the producer only accepts WT_REF_FLAG_LEAF refs in WT_REF_MEM.
Adaptive drain scheduling (per btree)
- Park / probe: after WTI_DRAIN_EMPTY_THRESHOLD consecutive empty drains, the drain parks and is probed once every WTI_DRAIN_PROBE_INTERVAL passes.
- Clean-pressure yield: the drain is skipped under clean-page eviction pressure so it does not compete for queue slots needed to find clean pages.
- Internal-page starvation guard: if the drain fills the full per-tree budget repeatedly, the walker receives a pass to reclaim internal pages.
- The drain checks the runtime-toggleable eviction_dirty_index flag on every entry.
Configuration
- eviction_dirty_index (default true): connection-level producer and drain switch.
- eviction_dirty_index_disagg (default false): additional gate for disaggregated-storage btrees.
Observability (FTDC)
Connection-level: eviction_dirty_index_ring_full_capacity_max, eviction_dirty_index_ring_peak_occupancy, eviction_dirty_index_scan_clear, and eviction_dirty_index_scan_clear_slots.
Per data-source: insert, contention, full-ring, drain scanned/queued/filtered/reinserted/stale/hazard, checkpoint/stable-lag/clean-pressure skips, and trim reinsertion counters. The shared eviction stat eviction_walk_skipped_drain_filled reports walker passes skipped after the drain filled the tree budget.
Performance — current branch
See the comment history for sys-perf comparisons, FTDC analysis, and the latest perf-required run.
Open follow-ups
- Confirm the residual InsertManyWithIndexes p95 latency trend with repeat runs.
- Run multipatch validation on read-only/in-cache workloads if an earlier single-run signal recurs.
- Keep eviction_dirty_index_disagg off by default pending dedicated disaggregated validation.
Delivery split
The work is split into three reviewable PR layers and registered as GitHub stack 15159. The cumulative stack replaces the original monolithic PR #13794; the original PR remains open until the replacement stack is complete and verified.
- WT-19140 — configuration definitions: adds the eviction_dirty_index and eviction_dirty_index_disagg option definitions and generated configuration code. Draft PR #15156.
- WT-17236 — runtime and integration: adds the per-btree dirty-index ring, the existing lock-free protocol unchanged, producer/drain call sites, statistics, lifetime handling, adaptive scheduling, and Catch2 coverage. Draft PR #15157.
- WT-19139 — Python and format coverage: adds the end-to-end eviction tests and test/format options on top of the runtime layer. Draft PR #15158.
The existing lock-free algorithm is not split across PRs; it moves as one mechanically preserved unit with its runtime tests. The final stack must reproduce the original PR's cumulative production and test diff before the original PR is superseded.
Related
- WT-17234 — eight-approach investigation that established the walker is the bottleneck at scale.
- WT-15538 — umbrella ticket for slow eviction under high update ratio.
- WT-16529 — queue usage / empty-queue investigation (pull-side, complementary).
- WT-16665 — dynamic queue resize (pull-side, complementary).
Branch and code layout
The dirty-index ring struct and protocol overview are declared in src/evict/evict_private.h. Allocation, teardown, insert, page-clear and split-retirement logic live in src/evict/evict_dirty_index.c. The drain and scheduling logic live in src/evict/evict_walk.c.
Test coverage:
- Catch2 test/catch2/misc_tests/test_dirty_index.cpp ([dirty_index]).
- Python test/suite/test_eviction08.py.
- test/format options cache.eviction_dirty_index and cache.eviction_dirty_index_disagg.
- is duplicated by
-
WT-17235 Push-model dirty-page index for eviction candidate discovery
-
- Closed
-
- is related to
-
WT-15538 Investigate slow eviction behavior when updates ratio is high
-
- Open
-
-
WT-16529 Increase eviction queue usage when the queue is frequently empty
-
- Open
-
-
WT-16665 Investigate eviction queue resize based on efficiency
-
- Open
-
-
WT-17392 Split evict_lru.c into focused source files
-
- Closed
-
- related to
-
WT-17634 SIGSEGV in __wt_checkpoint_tree_reconcile_update reached from eviction-time reconcile
-
- Backlog
-
-
WT-17638 SIGSEGV in __wt_ref_addr_copy when ref->home transient NULL during parent split
-
- Closed
-
-
WT-19139 Add eviction integration and format stress coverage for the dirty index
-
- Open
-
-
WT-19140 Separate dirty-index ring infrastructure from eviction integration
-
- Open
-
-
WT-17789 Identify freeable updates to help eviction
-
- Open
-