cd /news/ai-infrastructure/use-your-nvidia-gpu-s-vram-as-swap-s… · home topics ai-infrastructure article
[ARTICLE · art-19680] src=github.com pub= topic=ai-infrastructure verified=true sentiment=· neutral

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

A developer released a tool that allows Linux users to repurpose Nvidia GPU VRAM as swap space, effectively tripling addressable memory on systems with soldered RAM. The nbd-vram daemon uses CUDA's memory copy functions to allocate VRAM and exposes it as a block device via the kernel's NBD driver, bypassing Nvidia's restricted P2P API that limits direct VRAM access to Quadro and datacenter GPUs. The solution targets laptops with non-upgradable memory, enabling an RTX 3070 laptop to expand from 16GB to 46GB of total swap capacity by combining RAM, VRAM, zram compression, and SSD overflow.

read3 min publishedJun 2, 2026

Use your NVIDIA GPU's VRAM as swap space on Linux.

Built for laptops with soldered memory and no upgrade path. If you have an RTX card sitting there with 8GB of VRAM and you're getting swapped to SSD, this puts that VRAM to work.

Tested on: RTX 3070 Laptop (GA104M, 16 GB physical, 8 GB VRAM), driver 580.159.03, kernel 6.17, Pop!_OS. Allocated 7 GB for swap. End result including zram and SSD swap ~46 GB, tripled the addressable memory. Overflow order is: RAM fills, then VRAM absorbs spill (fast, PCIe), then zram compresses the rest (CPU), then SSD only if everything else is exhausted.

A small daemon allocates VRAM via the CUDA driver API, then serves it as a block device using the NBD (Network Block Device) protocol over a Unix socket. The kernel's built-in nbd

driver connects to it and exposes /dev/nbdX

. From there it's a normal swap device.

Data path: kernel swap subsystem - /dev/nbdX - nbd kernel driver - Unix socket - nbd-vram daemon - cuMemcpyHtoD/DtoH - GPU VRAM.

No kernel module to write or maintain. No NVIDIA kernel symbols. Survives kernel and driver updates without rebuilding anything.

The "obvious" approach is nvidia_p2p_get_pages_persistent

, which pins VRAM pages in BAR1 so the CPU can access them directly via ioremap_wc

. Every existing project that tried this route hits the same wall: the NVIDIA driver returns EINVAL

on consumer GeForce GPUs. Both the persistent and non-persistent variants, both flag values. It's gated at the RM level for Quadro/datacenter SKUs only, regardless of driver version.

The other approach - directly ioremap_wc

the BAR1 physical address without going through the P2P API - also doesn't work. The GPU's internal page tables only have ~16 MiB of BAR1 mapped (just the display framebuffer). Reads from the rest return zeros. mkswap

appears to succeed, then swapon

fails because the swap header isn't actually there.

The NBD approach sidesteps all of this. cuMemcpyHtoD

and cuMemcpyDtoH

work on any CUDA GPU without any special permissions.

  • NVIDIA GPU with CUDA support (any consumer RTX/GTX card)
  • NVIDIA driver with libcuda.so.1

(no CUDA toolkit needed) - Linux kernel 3.0+ (nbd module, built into most distros) nbd-client

packagegcc

,make

git clone https://github.com/c0dejedi/nbd-vram
cd nbd-vram
sudo ./install.sh
sudo systemctl start vram-swap-nbd

Verify:

swapon --show

The service is enabled on install, so it comes up automatically on every boot.

Edit /etc/systemd/system/vram-swap-nbd.service

:

Environment=VRAM_SETUP_SIZE_MB=7168    # how much VRAM to use
Environment=VRAM_SWAP_PRIORITY=1500   # swap priority (higher = used first)

The daemon tries the requested size first and backs off in 512 MiB steps if the GPU is short on memory - so it will grab as much as it can even if the display compositor is already loaded. VRAM_SETUP_SIZE_MB

is the ceiling, not a hard requirement.

After changing, run sudo systemctl daemon-reload && sudo systemctl restart vram-swap-nbd

.

The installer asks whether to enable power-aware management on first install. If enabled, the service automatically stops when you unplug from AC (or when battery drops below a threshold), and restarts when power is restored. Manual systemctl stop

is always respected and won't be overridden.

To change settings after install, edit /etc/nbd-vram.conf

. Changes take effect on the next poll (within 60 seconds) or immediately on the next AC plug/unplug event.

sudo bash test-nbd.sh

Allocates VRAM, connects the NBD device, does a 1 MiB write/readback check, activates swap, then prints teardown instructions. install.sh

handles teardown automatically if a test instance is running.

To stress the full partition after the smoke test passes:

sudo bash test-fill.sh

Writes the entire VRAM partition with zeros, verifies a sample read back, then auto-restores swap on exit.

Measured on RTX 3070 Laptop via test-fill.sh

(7 GiB sequential write, 4M blocks):

  • Sequential throughput: ~1.3 GB/s
  • Latency is lower than NVMe since the path goes through PCIe to GPU rather than storage

For laptops already using zram, set VRAM swap at a higher priority so it absorbs overflow before hitting SSD.

sudo bash uninstall.sh

MIT - Sean Lobjoit (c0dejedi)

── more in #ai-infrastructure 4 stories · sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/use-your-nvidia-gpu-…] indexed:0 read:3min 2026-06-02 ·