nbd-vram: using an idle NVIDIA GPU as Linux swap space
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
At a glance
- What is it?
- nbd-vram turns unused VRAM on a hybrid-graphics laptop into a high-priority swap device over NBD. It is a narrow tool for a narrow machine, and the suspend path is where it gets interesting.
- Who is it for?
- Adopt nbd-vram if you run a hybrid-graphics laptop where the NVIDIA card is idle, the RAM is soldered, and you already accept that swap is a normal part of the machine's life. Do not adopt it if you game or run CUDA workloads on that GPU, if you need swap to survive a suspend under heavy memory pressure, or if you are not comfortable with a custom systemd unit that stops and restarts swap automatically.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 131 days ago.
- What is it written in?
- Mainly Shell, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- c0deJedi/nbd-vram582 ★ · +19
| Repository | 2026-09-20 | 2026-11-25 |
|---|---|---|
| c0deJedi/nbd-vram | 563 | 582 |
19 Stars in the last 66 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
The specific laptop problem nbd-vram addresses
The target machine is a hybrid-graphics laptop: an integrated AMD or ATI GPU drives the display, an NVIDIA card sits mostly idle, and the system memory is soldered with no upgrade path. The README frames the pitch around exactly that shape of hardware, and the tested configuration is an AMD/ATI plus RTX 3070 Laptop (GA104M) with 16 GB RAM and 8 GB VRAM on Pop!_OS, driver 580.159.03, kernel 6.17. The project allocated 7 GB of that VRAM as swap, and the README states the resulting addressable memory including zram and SSD swap is roughly 46 GB, tripled from stock.
The intended overflow order is explicit: RAM fills first, VRAM absorbs the spill over PCIe, zram compresses what remains using the CPU, and the SSD is touched only when everything else is exhausted. That ordering is the whole argument. An NVMe drive waking from a power-saving sleep answers a page fault in milliseconds, which the README describes as a stutter. VRAM answers in microseconds, which the README describes as no stutter at all. It is not a capacity play so much as a latency play, plus a wear argument: swap is write-heavy, and routing that churn away from finite NAND matters more on laptops where the storage is also soldered.
How the daemon, NBD and the kernel driver fit together
The mechanism is deliberately boring, and that is the point. A small daemon written in C allocates VRAM through the CUDA driver API, then serves that memory as a block device over the NBD protocol on a Unix socket. The kernel's built-in nbd driver connects to the socket and exposes /dev/nbdX, which is then registered as an ordinary swap device. The documented data path runs: kernel swap subsystem, /dev/nbdX, nbd kernel driver, Unix socket, nbd-vram daemon, cuMemcpyHtoD and cuMemcpyDtoH, GPU VRAM.
The README is candid about why the obvious alternatives fail, and this is the most useful part of the design write-up. The NVIDIA P2P API, nvidia_p2p_get_pages_persistent, is gated at the RM level for Quadro and datacenter SKUs, so consumer GeForce cards return EINVAL regardless of driver version, for both the persistent and non-persistent variants. Mapping BAR1 directly without the P2P API fails too, because the GPU's internal page tables map only about 16 MiB of BAR1, just the display framebuffer. Reads beyond that return zeros, so mkswap appears to succeed and swapon then fails because the swap header is not actually there. The NBD route avoids both walls because cuMemcpyHtoD and cuMemcpyDtoH work on any CUDA GPU without special permissions. There is no kernel module to write or maintain and no NVIDIA kernel symbols, so the README claims it survives kernel and driver updates without rebuilding.
Installing nbd-vram and confirming the swap device exists
The README gives a four-command install. It clones the repository, runs the installer as root, and starts the systemd unit. The service is enabled on install, so it comes back on every boot.
git clone https://github.com/c0dejedi/nbd-vram
cd nbd-vram
sudo ./install.sh
sudo systemctl start vram-swap-nbdTo verify, the README uses swapon with the show flag. The expected output is a partition-type device named /dev/nbd0, sized around 7G in the tested configuration, with priority 1500.
swapon --show
# NAME TYPE SIZE USED PRIO
# /dev/nbd0 partition 7G 0B 1500If that row does not appear, the daemon did not connect and the kernel never saw a block device. The installer also asks whether to enable power-aware management on first install. If you accept, the service stops when you unplug from AC or when the battery drops below a threshold, and restarts when power returns. A manual systemctl stop is respected and will not be overridden. The installer sets VRAM_NBD_THREADS and VRAM_NBD_CONNECTIONS to nproc, which is why the README says there is nothing to tune for a first run.
Configuration keys that actually change behaviour
Configuration lives in the systemd unit at /etc/systemd/system/vram-swap-nbd.service, with four environment variables. VRAM_SETUP_SIZE_MB is the ceiling, not a hard requirement: the daemon tries the requested size and backs off in 512 MiB steps if the GPU is short on memory, so it grabs as much as it can even when the display compositor is already loaded. VRAM_SWAP_PRIORITY sets the swap priority, where higher means used first. VRAM_NBD_THREADS and VRAM_NBD_CONNECTIONS control worker threads and NBD connections, and the README says to keep them equal to each other. More connections let the daemon drain concurrent swap I/O in parallel, but the benefit saturates around your physical core count, and single-stream workloads do not use it at all. After any edit, the README prescribes daemon-reload followed by a restart of vram-swap-nbd.
Environment=VRAM_SETUP_SIZE_MB=7168 # how much VRAM to use
Environment=VRAM_SWAP_PRIORITY=1500 # swap priority (higher = used first)
Environment=VRAM_NBD_THREADS=8 # worker threads; install.sh sets this to nproc
Environment=VRAM_NBD_CONNECTIONS=8 # nbd connections; keep equal to threadsPower-management settings after install live in /etc/nbd-vram.conf rather than the unit file. Changes there take effect on the next poll, within 60 seconds, or immediately on the next AC plug or unplug event. That split between two config files is a small wart worth knowing about before you go hunting for a battery threshold in the wrong place.
Suspend, resume and the failure the project will not hide
This is the section that decides whether nbd-vram is appropriate for your machine. The installer enables vram-swap-nbd-suspend.service, which tears the swap down before the machine sleeps and brings it back on wake. The README states this is required for correctness, not a nicety: on suspend the NVIDIA driver powers down the GPU and destroys the CUDA context backing the swap device, so any swap I/O still in flight blocks forever and the machine can hang on resume. The unit is ordered ahead of both systemd's sleep services and NVIDIA's power-down hooks, so the swapoff runs while the GPU is still alive, VRAM is freed before power-off, and a fresh context is built on resume. If swap was already stopped, manually or by power management, it is left stopped. On a machine that never suspends, the hook never fires.
The documented limitation is the one to take seriously. If swap is heavily used and the paged-out data cannot fit back into RAM, the pre-sleep swapoff fails with ENOMEM. The README says this case is deliberately not forced, to avoid a panic, which means the machine may still hang on resume. The project is explicit that there is no way around evacuating VRAM into a RAM that cannot hold it, and the only remedy offered is to free memory before suspending. If your workflow regularly pushes the machine into deep swap and then closes the lid, this tool is the wrong tool, and no configuration key fixes it.
When the GPU is doing something else
While nbd-vram is active, the VRAM it holds is not available to anything else. The README truncates on this point, but the implication follows directly from the mechanism: the daemon allocates VRAM through the CUDA driver API and keeps it. A game, a Blender render, a local model, or any CUDA job that wants that memory is competing with your swap device. The backoff behaviour in 512 MiB steps means the daemon will take less when the GPU is already loaded, but that is a startup-time negotiation, not a runtime yield. The swap size is fixed once the device is up.
This is the sharpest trade-off in the project. You are converting a resource that a laptop owner might otherwise want for compute into a memory tier that only helps under pressure. On a machine where the NVIDIA card is genuinely idle, that is close to free capacity. On a machine where you occasionally game or run CUDA, you are choosing between two uses of the same 8 GB, and the README's own framing, an RTX card sitting there with 8GB of VRAM, assumes the first case. The power-management option softens this: stopping the service on battery also frees the VRAM, so unplugging before a game is a workable habit. Nothing in the README suggests the daemon releases VRAM dynamically when another process asks for it.
How nbd-vram differs from zram and ordinary SSD swap
The real alternative on most Linux laptops is zram, and nbd-vram is not a replacement for it. zram compresses pages in RAM using the CPU, which costs CPU cycles and RAM itself. nbd-vram moves pages to a different physical memory pool over PCIe, which costs bus bandwidth and GPU memory instead. The README's tested configuration runs both, and the overflow order puts VRAM ahead of zram and the SSD behind it. So the honest comparison is not either-or: the project is designed to sit between RAM and zram as a middle tier, and it works best on a machine that already has zram configured.
Against plain SSD swap, the difference is latency and wear. The README describes single faults answered in roughly 250 microseconds from VRAM versus milliseconds from an NVMe drive waking from a power-saving sleep. That gap is what you feel as a stutter when a background app pages in or when you switch back to something left open for hours. The wear argument runs the other way from zram: swap writes are heavy, and sending that churn to VRAM instead of NAND saves write cycles, which the README notes matters most on the soldered-storage laptops this is built for. Compared with building a custom kernel module that maps VRAM, the NBD approach trades peak throughput for surviving kernel and driver updates without a rebuild.
Requirements, licence and what maintenance looks like
The requirements list is short and worth checking before you clone anything. You need an NVIDIA GPU with CUDA support, any consumer RTX or GTX card, and an NVIDIA driver providing libcuda.so.1. The CUDA toolkit is not required. The README recommends Linux kernel 5.6 or newer because that is where PR_SET_IO_FLUSHER landed and the swap-deadlock protection leans on it, though older kernels still run with that one safeguard disabled, and the nbd module is built into most distributions. You also need the nbd-client package plus gcc and make. The repository is a single C file, nbd-vram.c, built by a Makefile with gcc -O2 -Wall -o nbd-vram nbd-vram.c -ldl -lpthread, alongside shell scripts for connect, disconnect, power checking, sleep and uninstall, plus systemd and udev directories. There is no package manager entry, so upgrades mean pulling the repository again and rerunning install.sh.
The licence is MIT, which is permissive and places few obligations on redistribution, though the usual caveat applies that this is not legal advice and you should read LICENSE yourself if you plan to ship it. On maintenance: the last push was on 2026-07-17, which is recent enough that the repository is not stale, but there are no published GitHub releases, so there is no versioned artifact to pin and no changelog to read. The upgrade cost is therefore low in build terms and higher in verification terms: every update means re-checking that swapon --show still reports /dev/nbd0 and that the suspend unit still orders correctly ahead of the NVIDIA power-down hooks, because those are the two places where a silent regression would hurt.
Editorial conclusion
Adopt nbd-vram if you run a hybrid-graphics laptop where the NVIDIA card is idle, the RAM is soldered, and you already accept that swap is a normal part of the machine's life. Do not adopt it if you game or run CUDA workloads on that GPU, if you need swap to survive a suspend under heavy memory pressure, or if you are not comfortable with a custom systemd unit that stops and restarts swap automatically. Before trusting it, verify three things on your own hardware: that swapon --show reports /dev/nbd0 at the priority you configured, that the suspend unit actually runs swapoff before the NVIDIA driver powers the GPU down, and what your machine does when a pre-sleep swapoff fails because the paged-out data will not fit back in RAM. That last case is the one the project documents as unfixable, and it is the one to test deliberately rather than discover at 2am.
Frequently asked questions
How do I install nbd-vram?
Clone the repository, run sudo ./install.sh, then sudo systemctl start vram-swap-nbd. The service is enabled on install, so it starts automatically on every boot afterwards.
Does nbd-vram need the CUDA toolkit?
No. The README lists an NVIDIA driver providing libcuda.so.1 as the requirement and states that the CUDA toolkit is not needed, along with the nbd-client package, gcc and make.
Why does nbd-vram use NBD instead of the NVIDIA P2P API?
The README states that nvidia_p2p_get_pages_persistent returns EINVAL on consumer GeForce GPUs because it is gated at the RM level for Quadro and datacenter SKUs, and that mapping BAR1 directly fails because only about 16 MiB is mapped. cuMemcpyHtoD and cuMemcpyDtoH work on any CUDA GPU without special permissions.
What happens to nbd-vram when the laptop suspends?
The installer enables vram-swap-nbd-suspend.service, which tears the swap down before sleep and rebuilds it on resume, because the NVIDIA driver destroys the CUDA context backing the swap device. The README notes that if paged-out data cannot fit back into RAM, the pre-sleep swapoff fails and the machine may still hang on resume.
Can I use the NVIDIA GPU for other work while nbd-vram is running?
The VRAM allocated to swap is not available to other processes while the service is active. The daemon backs off in 512 MiB steps at startup if the GPU is short on memory, and the power-management option stops the service on battery, which frees the VRAM.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/c0dejedi-nbd-vram)Star history chart for your README
[](https://hysenlabs.com/projects/c0dejedi-nbd-vram)Was this useful?