Turning idle GPU VRAM into Linux swap via NBD instead of kernel hacks
A new MIT-licensed project, nbd-vram, lets Linux users press unused NVIDIA GPU memory into service as swap space. The trick is avoiding the usual dead end: NVIDIA’s peer-to-peer page-pinning API returns EINVAL on consumer GeForce cards, and directly remapping BAR1 fails because only ~16 MiB is mapped for the display framebuffer. Instead, a userspace daemon allocates VRAM through CUDA’s standard cuMemcpy calls and exposes it as a block device using the Network Block Device protocol over a Unix socket, which the kernel’s stock nbd driver mounts as /dev/nbdX and treats as ordinary swap.
Because everything runs in userspace through driver APIs that work on any CUDA-capable card, there is no kernel module to maintain and the setup survives driver and kernel updates. On the author’s RTX 3070 laptop, 7 GB of VRAM swap sits between RAM and zram in the overflow chain, pushing total addressable memory to roughly 46 GB with sequential throughput around 1.3 GB/s, faster than NVMe. A systemd service handles auto-start, dynamic sizing if the compositor has already claimed memory, and optional power-aware shutdown when running on battery.
The target audience is owners of laptops with soldered RAM and no upgrade path, where an 8 GB discrete GPU otherwise sits idle while the system thrashes to SSD. It is a pragmatic workaround for a hardware-economics problem that NVIDIA’s artificial segmentation of consumer versus datacenter features helped create.
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.