HN
Today

Use your Nvidia GPU's VRAM as swap space on Linux

A clever Linux project allows users to utilize their NVIDIA GPU's VRAM as swap space, providing a high-speed memory overflow for systems with soldered RAM. This ingenious workaround taps into idle GPU resources, offering a significant performance boost over traditional SSD swap for those hitting memory limits. It's a prime example of Hacker News's appreciation for technical hacks that solve niche but persistent hardware limitations.

105
Score
31
Comments
#1
Highest Rank
18h
on Front Page
First Seen
Jun 2, 11:00 PM
Last Seen
Jun 3, 4:00 PM
Rank Over Time
3112132433447915101417

The Lowdown

The nbd-vram project introduces an innovative method to repurpose unused NVIDIA GPU VRAM as swap space on Linux. This solution is particularly aimed at laptops with soldered main memory and users with high-end RTX cards whose VRAM often sits idle when not engaged in intensive graphical or AI tasks, preventing system slowdowns from swapping to much slower SSDs.

  • How it Works: A small daemon allocates VRAM via the CUDA driver API and exposes it as a block device using the Network Block Device (NBD) protocol over a Unix socket. The kernel's nbd driver then integrates this into the standard swap subsystem.
  • Avoiding NVIDIA Limitations: The project cleverly bypasses NVIDIA's restrictions on consumer GeForce GPUs by using cuMemcpyHtoD/DtoH instead of the P2P API, which is typically gated to Quadro/datacenter SKUs.
  • Performance: Tests on an RTX 3070 Laptop showed sequential throughput of approximately 1.3 GB/s. While not saturating PCIe bandwidth, this is still significantly faster than NVMe for swap operations due to lower latency, and much faster than HDD.
  • Configuration & Management: Users can configure the VRAM swap size and priority. The system includes power-aware management, automatically pausing swap on battery power to conserve energy.
  • Memory Overflow Order: The optimal setup involves RAM filling first, followed by VRAM absorbing spill (fast, PCIe), then zram compressing data (CPU), and finally, SSD only as a last resort.

This project offers a compelling way to extend addressable memory and enhance system responsiveness for users who find themselves frequently hitting RAM limits on systems with underutilized, high-speed GPU memory.

The Gossip

Performance Ponderings

Many commenters questioned the reported sequential throughput of ~1.3 GB/s for VRAM swap, noting that the theoretical PCIe bandwidth is much higher (64GB/s for PCIe 4.0 x16). They highlighted that NVMe drives can often achieve twice this speed, albeit with higher latency, and emphasized the importance of random read/write speeds, not just sequential, for swap operations. Some users expressed a desire for benchmarks comparing VRAM swap directly against NVMe for real-world scenarios.

Niche Necessity vs. Novelty

A significant thread revolved around the practical utility and target audience for this solution. While some recognized its value for specific scenarios like laptops with soldered RAM or systems with abundant, idle VRAM (e.g., 32GB RAM + 32GB VRAM), others expressed skepticism, questioning the need to use 'expensive RAM for swap.' The project was praised as a 'good idea' for its niche application, particularly when facing frequent swapping to SSD.

VRAM Volatility & Conflicts

Concerns were raised regarding potential conflicts and instability when VRAM is simultaneously used for swap and its primary GPU workloads (e.g., gaming, AI, desktop rendering). Commenters questioned how the system handles dynamic VRAM allocation, fearing crashes if VRAM resources become scarce. The idea of dynamically vacating VRAM swap space when GPU-intensive applications launch was also discussed, with some noting that Windows' existing VRAM swap implementation 'kinda sucks' in this regard.

Swap's Systemic Significance

The discussion delved into the fundamental role of swap space in modern Linux systems. While some questioned if swap is still relevant beyond hibernation (S4 suspend), others cited an HN comment (and linked post) arguing that swap is crucial for 'equality of reclamation' – allowing both file-backed and anonymous pages to be efficiently managed, not just as an 'emergency extra memory' for low-RAM systems. This led to a consensus that even a small swap partition can be beneficial.