TL;DR
When AI agents evolve their own code in massive parallel batches—a process called Recursive Self-Improvement (RSI)—their working memory violently overflows GPU memory in synchronized waves. Mayfly tames this memory tsunami using High-Bandwidth Flash (HBF), orchestrating exactly when to read memory directly from flash and when to pull it back to fast GPU memory, slashing evaluation times by up to 55% without burning out the flash drives.
What Problem Does This Paper Address?
Imagine an AI trying to make itself smarter. In harness RSI, a fixed Large Language Model (LLM) proposes dozens of edits to its own scaffolding (prompts, tools, and control flow) and tests them simultaneously across benchmarks. Each test is an agent session alternating between thinking (LLM calls) and acting (running tools in a sandbox).
During a session, the LLM stores its conversation history in a KV cache so it doesn't have to re-read everything from scratch on every turn. In standard chatbot serving, KV caches mostly sit idle waiting for slow humans to type back, making it easy to offload them to cheap SSDs or CPU RAM.
RSI has no humans. Sessions launch all at once, tool calls return in under a second, and memory usage surges in a massive synchronized burst before declining as tasks finish. Under heavy load, the KV caches of active, ready-to-run sessions alone blow past the GPU's ultra-fast High-Bandwidth Memory (HBM).
High-Bandwidth Flash (HBF)—NAND flash memory stacked directly onto the GPU package—offers massive capacity right next to the compute cores. However, using it naively fails:
- Swapping KV caches back into HBM before running leaves ready sessions stuck in a traffic jam waiting for HBM space.
- Reading everything in-place directly from HBF overwhelms the flash's sustained read bandwidth, slowing down every token generation step.
- Flash wear-out: Moving data back and forth on every sub-second tool call—or holding onto dead memory after a session finishes—destroys the flash's limited write endurance.
Methods
Mayfly is a lifecycle-aware memory manager spanning the serving runtime, a custom GPU attention kernel, and a specialized controller on the HBF base die. Instead of guessing what memory is "hot" or "cold," it listens directly to the RSI orchestrator's lifecycle events:
- One Backing Copy: When an immutable 16-token KV block is evicted from HBM, it is written to HBF once. Switching between "ready" (LLM call) and "parked" (waiting on a tool) doesn't trigger data movement. Even if a block is pulled back into HBM later, its HBF copy stays valid, meaning future evictions require zero writes.
- Per-Step Move-or-Read Gate: Before each generation step, a gatekeeper estimates token throughput. Because HBM and HBF use separate channels, the GPU can read both simultaneously. Mayfly allows overflowing requests to read KV in-place from HBF only as long as those flash reads "hide" behind HBM read times without dragging down overall step throughput. As sessions finish during the burst's decline and free up HBM, Mayfly seamlessly migrates active KV back into HBM.
- Two-Path Exact Attention: Mayfly splits attention calculations across thread blocks—one group reading HBM, another reading striped pages from HBF—merging the results via log-sum-exp reduction for exact attention with zero dropped context.
- KV-Native Flash Controller & Instant Trims: Unlike human users who vanish without saying goodbye, the RSI orchestrator knows the exact millisecond a session ends. It sends a
trimsignal to the HBF controller, immediately marking that session's blocks dead so garbage collection never wastes writes copying dead data. Because KV caches can always be recomputed from text tokens if an error or power loss occurs, the controller skips heavy storage-grade journaling.
Datasets
The authors evaluate Mayfly using recorded traces and replays from real agentic and RSI workloads:
- DGM (Darwin Gödel Machine): Coding agent RSI runs evaluated on SWE-bench and SWE-rebench (using OpenHands trajectories).
- RRSI: Agent harness refinement traces on EngDesign tasks.
- Harness²: OpenCode agent harness refinement runs across 25 LAB tasks.
- TraceLab: 8,058 interactive Claude Code and Codex human-agent sessions (used to contrast human wait times against autonomous RSI bursts).
No new benchmark datasets were introduced; instead, real multi-generation RSI traces were replayed in a discrete-event simulator calibrated within ~1% of a physical NVIDIA H200 GPU.
Key Insights and Ideas
- Decouple state switches from flash writes: 88% of tool calls finish in under a second. Treating a tool call as "cold" and demoting its memory creates a write-amplification nightmare. Keeping a persistent flash copy turns 80 state switches per session into a single flash write.
- Follow both sides of the wave: In-place flash reads save you during the memory peak, while migrating back to HBM saves you during the long tail. Doing one without the other actually makes performance worse!
- Recomputability changes hardware design: Traditional SSDs must guard every 4 KiB of user data against power loss for years. RSI KV caches live for under 94 minutes and can be regenerated via prefill if a read fails. Trading away unneeded data retention and heavy FTL journals unlocks massive flash endurance and tiny SRAM footprints.
Key Results
Evaluated on a simulated H200 GPU (99 GB KV budget in HBM) with added 512 GB HBF stacks:
- Big Speedups at Scale: At 128 concurrent sessions (4 HBF sites), Mayfly finishes generations 34% sooner than parking KV on HBF (with 1.9× lower median time-to-first-token) and 23% sooner than greedily reading from HBF whenever HBM is full. At 256 sessions (8 HBF sites), the speedup over parking jumps to 55% (2.6× lower median TTFT).
- Zero Preemptions & Lower Energy: Mayfly eliminates request preemptions (0 vs. 735 in HBF-parking at 256 sessions) and cuts total energy consumption by 9–22% compared to NVMe SSD offloading.
- Zero Write Amplification: Each block is written once, achieving an ideal Write Amplification Factor (WAF) of 1.00. Every byte written to HBF is read back 1,040 to 4,380 times (compared to 0.20–0.88 times in standard LLM serving pools). This extends flash lifespan by 1.7–2.8× over 30-minute TTL timers and 9–37× over policies that drop flash copies on restore.
Limitations and Future Work
- Simulated HBF Hardware: Because HBF is an emerging specification (currently standardized via OCP) rather than commodity off-the-shelf silicon, the end-to-end system is evaluated via a calibrated H200 simulator and component-level models rather than physical HBF stacks.
- Append-Only Assumption: Mayfly's single-write backing copy relies on agent harnesses appending to their conversation history. Harnesses that actively rewrite, trim, or compress middle-of-context history invalidate KV blocks from the edit onward, requiring new writes.
- Thermal Throttling: Sustained flash activity generates heat; while Mayfly still achieves a 36% speedup at 256 sessions under severe thermal throttling (202 GB/s per site vs. 467 GB/s), bandwidth scarcity narrows its margin at lower concurrencies.
Summary updated