← Back to Pull requests

bolt_unix: Remove madvise(MADV_RANDOM) on the data mmap #1356

Open
unknown opened this pull request with 296 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 24, 2026 20:12 UTC
Author

Removes the madvise(MADV_RANDOM) call on the database mmap in bolt_unix.go, so the mapping uses the kernel default (MADV_NORMAL). This is the same change as #940.

Fixes #939

Why

Since Linux 6.4 (kernel commit 8788f678, "mm: add vma_has_recency()"), page-table accesses in a VMA marked VM_RAND_READ no longer count as recent use. With MADV_RANDOM on bbolt's mmap, the kernel evicts etcd's cached database pages easily under memory pressure, and compaction then reads them back one 4 KiB page at a time. Details are in #939.

Results

As requested in #939, this was evaluated with etcd's own benchmark tools (tools/benchmark and tools/rw-heatmaps/rw-benchmark.sh) on Linux 6.12: results comment, full report.

| Benchmark test | Result |
| -------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| rw-benchmark.sh sweep | No change: across 60 read/write workload mixes, median +0.3% for reads and +0.3% for writes, all within 4.5% |
| Reads, plenty of memory | No change: point-read throughput and p99 latency within -1.1% to +0.6% |
| Reads under memory pressure | Faster without MADV_RANDOM: 19x to 41x the point-read throughput; a full list of all keys is 10.1x faster |
| Compaction under memory pressure | 11.9x faster without MADV_RANDOM (773 s vs 65.1 s); with compaction every minute under writes, the slowest compaction drops from 238 s to 19.2 s |

Notes

  • Only bolt_unix.go changes, as in #940. bolt_android.go, bolt_aix.go and bolt_solaris.go still set MADV_RANDOM; I can drop it there too if preferred.
  • Once this merges, I can backport it to release-1.5 and release-1.4 (used by etcd 3.7 and 3.6) and add the changelog entries.
  • Diff: 296 lines (+222 / -74) across 3 files Reviewer: tjungblu Review duration: 8547m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.40) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 296 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.341
    Real PR Conversation Timeline
    1 comments
    "Review active on #1356"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.0% (MEDIUM) · Higher = larger blast radius
    40.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21.3% · Safe to merge
    21.3%
    Repository