Pool recycling of pageout'd regions: validate syscall costs and residency semantics

Open
#1 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
linux, rust

Research direction

Start at ThreadLocalStealer::deallocate and run the listed experiments across the representative allocation sizes, measuring first-touch time, mincore residency, AnonHugePages in /proc/self/smaps, and syscall overhead for each advisory. Done means comparing the four mitigation proposals on Linux 5.15+ and recording whether the data supports a runtime change or documentation-only approach.

Written by the indexing model from the issue text.

Description

Context

When a user allocates a region, writes to it, calls pageout (MADV_PAGEOUT), and then deallocates, the pool recycles the (now-cold) allocation. The next caller that writes to the recycled region pays page-fault cost on first access. The pool's implicit contract ("cheap to re-hand-out") is violated silently.

Current deallocation path:

  1. Drop routes through ThreadLocalStealer::deallocate → worker queue.
  2. Eventually either handed out again, or moved to the global injector and later cleared by the background worker via MADV_FREE (Linux) / MADV_DONTNEED (other).
  3. MADV_FREE on pageout'd pages is a no-op — the pages are already gone.

Pages can also lose THP backing silently. MADV_COLD / MADV_PAGEOUT may split a transparent huge page to operate on a sub-range; splits are not automatically reversed.

Experiments to run

Measure, in isolation, with representative allocation sizes (2 MiB, 16 MiB, 128 MiB, 1 GiB):

  • Baseline write cost on a freshly-mmaped anonymous region with MADV_HUGEPAGE: first-touch fault cost, bandwidth for full write-through.
  • Post-MADV_PAGEOUT cost: pageout a resident region, re-write it. Measure fault cost and whether THP is still in effect (/proc/self/smaps → AnonHugePages).
  • Post-MADV_COLD cost: same, but just marking cold. Does re-touch rebuild THP?
  • Post-MADV_DONTNEED cost: does the kernel re-fault into huge pages, or small pages?
  • Post-MADV_FREE (then reclaimed) cost: pressure the kernel into reclaiming, then re-touch.
  • Syscall overhead of MADV_DONTNEED / MADV_FREE / mincore per call, as a function of region size.

Track per-scenario:

  • Time to first-touch the region after the advisory.
  • Residency after re-touch (via mincore).
  • Huge-page status after re-touch.

Mitigation proposals to compare

  1. Every dealloc runs MADV_DONTNEED on the region before it re-enters the pool. Guarantees the next caller faults into fresh (presumably THP-backed) pages. Costs one syscall per dealloc.
    • Open question: after MADV_DONTNEED, does the next touch fault into a huge page, or small pages? Empirically the kernel has flip-flopped on this across versions.
  2. MADV_DONTNEED only on promotion to the global injector. Thread-local reuse skips it (fast path for allocate-then-dealloc-then-allocate within one thread). Cross-thread handoffs pay the cost.
  3. mincore-gated decision. Call mincore first; only MADV_DONTNEED if a significant fraction of the region is non-resident (heuristic: user recently pageout'd). Adds a syscall but may be cheaper than unconditional MADV_DONTNEED on huge regions.
  4. Status quo + documentation. pageout's doc warns callers that deallocating a pageout'd region hands cold memory to the next caller. No runtime mitigation.

Decision inputs

  • Absolute syscall cost vs. absolute page-fault cost at representative sizes.
  • Whether MADV_DONTNEED reliably rebuilds THP on re-touch under current kernels (5.15+ target).
  • Whether mincore's cost scales acceptably for our size classes (up to 128 GiB).

Scope

Investigation only for 0.1.x. If experiments point to a clear winner, ship the mitigation in a minor release. Until then, rely on the (yet-to-add) doc warning on pageout.

Dominant language
Rust
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.