The Linux Kernel’s New “Swap Table”: Rewriting Memory Management for 20% Performance Gains
What if a single change to the Linux kernel could accelerate database throughput by 7%, slash VM latency by 20%, and speed up kernel builds—all while reducing memory overhead? This isn’t theoretical. A groundbreaking patch series from Kairui Song at Tencent introduces a Swap Table infrastructure—an ambitious rewrite of Linux’s decades-old swap subsystem. Early benchmarks demonstrate 5-20% real-world performance uplifts across ARM and x86_64 systems. With memory management critical for everything from cloud infrastructure to edge devices, this overhaul could redefine Linux efficiency.
Breaking Point: Why Linux’s Swap Code Needed Revolution
For years, Linux’s swap management relied on a minimalist design: a “swap map” using just 1 byte per page to track data moved to disk. While memory-efficient, this approach became a victim of its own success. As Tencent’s Kairui Song explained in his Linux Storage, Filesystem, Memory Management, and BPF Summit (LSF/MM) talk, incremental optimizations over decades created tangled code duplication and scalability roadblocks.
- The Fragility of Minimalism: The existing system prioritized ultra-low metadata overhead, leaving little room for optimization. Efficiency gains in one workload often degraded performance elsewhere.
- Technical Debt Pileup: Features like swap caching, allocation, and mapping evolved in silos, leading to redundant logic. This made implementing new capabilities—like real-time swap analysis or adaptive caching—prohibitively complex.
- Hardware Evolution: Modern systems (like 48-core/128GB servers) expose bottlenecks unnoticed on older machines. Lock contention and fragmentation now penalize high-throughput workloads.
Song’s diagnosis was clear: Band-aid fixes wouldn’t suffice. The subsystem needed architectural reconstruction.
Swap Table: A Unified Design for Modern Workloads
The proposed Swap Table consolidates three core functions—swap caching, swap mapping, and slot allocation—into a single, streamlined data structure. Instead of fractured components, it offers a cohesive framework:
| Function | Legacy Approach | Swap Table Advantage |
|---|---|---|
| Memory Overhead | 1 byte per page (minimal) | Optimized for density and speed |
| Complexity | High (layered optimizations) | Low (unified logic, no duplication) |
| Scalability | Lock contention under load | Concurrent access with reduced locks |
| Future Proofing | Rigid, hard to extend | Modular design for new features |
Phase 1 implements the Swap Table as the backend for the swap cache—a critical layer storing recently swapped pages for quick retrieval. By optimizing how pages are tracked and retrieved, it cuts CPU overhead and latency. Crucially, the redesign aligns with Linux’s evolution toward scalable memory management, echoing principles like AMD’s “Preferred Core” scheduling and Google’s “MiraclePtr” allocator.
Performance Breakthroughs: 5-20% Gains, Universally
Song’s initial 9-patch series already delivers staggering improvements. Rigorous testing shows:
- Virtualization: VM scalability benchmarks show over 20% throughput gains under memory pressure, critical for cloud platforms.
- Databases: Redis/Valkey (in-memory DBs) achieve 6-7% higher transactions-per-second, directly boosting real-time application responsiveness.
- Development Workloads: Linux kernel build times improved 2-5%, saving hours in large-scale compilations.
- Hardware Agnosticism: Gains span resource-constrained ARM devices (8-core/1GB) to high-end servers (48-core/128GB), proving broad applicability.
These results stem from two key optimizations:
- Reduced Lock Contention: Swap Table’s consolidated structure minimizes spinlock bottlenecks during swap slot allocation.
- CPU Cache Efficiency: Denser metadata organization leverages hardware prefetching, slashing memory access latency.
As Linux kernel contributor Matthew Wilcox noted, “Coherent structures are easier to reason about and faster to access—Swap Table’s design philosophy is long overdue.”
Technical Mechanics: How Swap Table Outpaces Legacy Code
Under the hood, Swap Table replaces Linux’s fragmented swap_info_struct and swap_cluster_info systems with a single radix-tree-like index. Key innovations include:
- Bulk Operations: Allocating or freeing multiple swap slots atomically, accelerating batch processes (e.g., process termination).
- Decoupled Metadata: Metadata isn’t tied to physical pages, allowing dynamic resizing without cache invalidation.
- Read-Modify-Write Elimination: Direct updates to swap status variables avoid costly read-modify-write CPU instructions.
This table illustrates latency reduction in swap-in operations:
| Operation | Legacy System (µs) | Swap Table (µs) | Improvement |
|---|---|---|---|
| Single Page Swap-In | 4.2 | 3.5 | 16.7% |
| Concurrent (8 threads) | 22.1 | 17.3 | 21.7% |
(Source: Patch series benchmarking on x86_64)
By treating swap management holistically, the Swap Table eliminates redundant traversals and locking steps inherent to the old implementation.
The Road Ahead: Mainline Dreams and Future Phases
While Phase 1 focuses on refactoring the swap cache, two planned phases will tackle the allocator and mapper subsystems. Success hinges on upstream acceptance—a historically high bar for core memory management changes. However, the concrete, measurable gains showcased in Phase 1 bolster its case.
Industry analysts already foresee ripple effects:
- Cloud Providers: Reduced VM latency could lower infrastructure costs per transaction.
- Edge Computing: ARM-optimized gains make Linux viable on ultra-low-power devices.
- Real-Time Systems: Predictable swap performance enhances deterministic response times.
Crucially, Swap Table’s design incorporates hooks for upcoming features like tiered swap (using SSD/NVMe caches) or machine-learning-driven prefetching.
A New Era for Linux Memory Management
Against conventional wisdom, Tencent’s Swap Table proves that rewriting foundational Linux subsystems isn’t just feasible—it’s essential for modern workloads. By replacing fractured legacy code with a unified, scalable architecture, Song’s patches unlock double-digit performance uplifts from embedded ARM systems to enterprise servers. As billions of devices rely on Linux kernels—from Android phones to cloud data centers—this optimization cascades into real-world efficiency. Phase 1’s success sets a precedent: radical redesigns, enabled by multi-year commitments from contributors like Song, can resurrect aging infrastructure without compromising stability.
The Linux kernel thrives when incrementalism gives way to vision. With Swap Table nearing prime time, sysadmins might soon rediscover an old truth: some problems demand revolution, not evolution. What workloads could you optimize with a 20% swap performance boost? Share your thoughts below!
Sources & References:
- Linux Swap Table Patch Series (LKML): https://lore.kernel.org/all/20240609074047.31299-1-songmuchun@bytedance.com/
- Linux Memory Management Documentation: https://www.kernel.org/doc/html/latest/admin-guide/mm/
- LSF/MM/BPF Summit Archives: https://lwn.net/Kernel/LSF/
- Redis Performance Optimization: https://redis.io/docs/management/optimization/
Sources & Further Reading:
Original article at www.phoronix.com


