Abstract
Modern computer systems rely on hand-crafted heuristics to manage critical resources like memory and network bandwidth. However, these static rules are often brittle and fail to adapt to diverse workloads. This paper introduces PolicySmith, a framework that leverages Large Language Models (LLMs) and evolutionary search to automatically synthesize "instance-optimal" heuristic code. By shifting intelligence from opaque neural network weights to interpretable, high-performance code, PolicySmith discovers caching policies that outperform 14 state-of-the-art baselines and generates safe, kernel-ready congestion control logic. Our results suggest a paradigm shift from universal, human-written heuristics toward dynamically evolved, context-specific code.
Introduction
At the foundation of almost every computer system lies a set of heuristics: expert-written "rules of thumb" designed to manage complex resources. From TCP congestion control algorithms to cache eviction policies like LRU (Least Recently Used), these heuristics are the invisible gears of the digital world.
Despite their ubiquity, traditional heuristics suffer from a fundamental flaw: brittleness. A cache policy optimized for web traffic often performs poorly when applied to database workloads. As hardware and applications evolve at an accelerating pace, human developers are trapped in a losing arms race, manually tweaking and re-implementing rules to keep up with shifting environments. While machine learning (ML) offers a potential path toward "instance-optimality"—policies perfectly tuned to a specific context—standard neural networks are often too opaque, computationally expensive, and difficult to verify for safety-critical environments like the Linux kernel.
The PolicySmith Framework
PolicySmith addresses these challenges by treating policy design as an automated search problem guided by LLMs. Rather than deploying a neural network at runtime, PolicySmith uses the LLM as a high-level "programmer" to generate standard C or C++ code that can be compiled and executed with zero inference overhead.
The framework consists of four primary components that operate in an offline evolutionary loop:
- Template: A user-defined scaffold that defines the function signature and provides natural language constraints (e.g., "avoid floating-point arithmetic" or "minimize memory usage").
- Generator: An LLM (specifically GPT-4o-mini) that writes candidate heuristic code to fill the template.
- Checker: A validator that ensures the generated code is syntactically correct and safe. For kernel-level tasks, this includes the Linux eBPF verifier, which prevents unsafe memory access or unbounded loops.
- Evaluator: A context-specific test harness (such as a cache simulator) that scores the candidate code based on target metrics like hit rate or throughput.
During the evolutionary process, PolicySmith prompts the LLM to generate a batch of candidates. The highest-performing versions are fed back into the LLM's prompt as examples for the next generation, allowing the code to evolve and specialize for a specific workload over multiple iterations.
Case Studies and Evaluation
To demonstrate the versatility of PolicySmith, the authors evaluated it across two distinct systems domains: web caching and network congestion control.
Web Caching
Using real-world block I/O traces from CloudPhysics and Microsoft Research (MSR), PolicySmith was tasked with generating priority scoring functions for cache eviction. The results were striking: the synthesized heuristics matched or outperformed 14 state-of-the-art baselines, including established algorithms like ARC, LHD, and SIEVE.
Crucially, the generated policies exhibited strong generalization. A heuristic evolved on a single trace often outperformed all baselines on a majority of other traces within the same dataset. For instance, one generated policy ("Heuristic X") beat all baselines on 64% of the MSR traces, suggesting that LLMs can identify deep structural patterns in workloads that human-designed rules miss.
Congestion Control and Kernel Safety
Generating code for the Linux kernel is notoriously difficult due to the strict safety requirements of the eBPF verifier. PolicySmith successfully navigated these constraints, with 63% of LLM-generated candidates passing the verifier on the first attempt. With a single round of automated error feedback, the success rate rose to 82%. The framework successfully synthesized diverse TCP logic capable of varying bandwidth utilization from 23% to 98%, demonstrating its ability to explore a wide design space while maintaining safety.
Discussion: The End of the Universal Heuristic
The success of PolicySmith suggests that the industry's search for a "one-size-fits-all" heuristic may be reaching its end. Instead of shipping static algorithms, future systems could ship with self-evolving logic that re-synthesizes its own code as the deployment context shifts. This approach provides the performance benefits of data-driven optimization while retaining the speed, safety, and interpretability of traditional code.
Furthermore, the cost of this optimization is remarkably low. Generating 500 candidate heuristics for a caching workload cost approximately $7.00 in API fees and required only 5.5 CPU-hours. This makes automated policy synthesis accessible for a wide range of applications.
Limitations and Future Work
While promising, PolicySmith currently relies on offline simulators; its effectiveness is therefore limited by the fidelity of the test harness. If a simulator fails to capture real-world nuances, the generated code may underperform in production. Additionally, future work is needed to develop lightweight "context detectors" that can trigger re-synthesis when a workload changes significantly. Finally, expanding the framework to coordinate multiple system components—such as the cache and the network stack simultaneously—remains an open challenge.
Conclusion
PolicySmith demonstrates that LLMs can do more than write prose; they can serve as sophisticated engines for systems optimization. By replacing man-made heuristics with evolved code, we can build systems that are more performant, more adaptable, and easier to maintain than those governed by the static rules of the past.
Summary updated