{"slug": "use-your-nvidia-gpu-s-vram-as-swap-space-on-linux", "title": "Use your Nvidia GPU's VRAM as swap space on Linux", "summary": "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.", "body_md": "Use your NVIDIA GPU's VRAM as swap space on Linux.\n\nBuilt 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.\n\nTested 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.\n\nA 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`\n\ndriver connects to it and exposes `/dev/nbdX`\n\n. From there it's a normal swap device.\n\nData path: kernel swap subsystem - /dev/nbdX - nbd kernel driver - Unix socket - nbd-vram daemon - cuMemcpyHtoD/DtoH - GPU VRAM.\n\nNo kernel module to write or maintain. No NVIDIA kernel symbols. Survives kernel and driver updates without rebuilding anything.\n\nThe \"obvious\" approach is `nvidia_p2p_get_pages_persistent`\n\n, which pins VRAM pages in BAR1 so the CPU can access them directly via `ioremap_wc`\n\n. Every existing project that tried this route hits the same wall: the NVIDIA driver returns `EINVAL`\n\non 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.\n\nThe other approach - directly `ioremap_wc`\n\nthe 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`\n\nappears to succeed, then `swapon`\n\nfails because the swap header isn't actually there.\n\nThe NBD approach sidesteps all of this. `cuMemcpyHtoD`\n\nand `cuMemcpyDtoH`\n\nwork on any CUDA GPU without any special permissions.\n\n- NVIDIA GPU with CUDA support (any consumer RTX/GTX card)\n- NVIDIA driver with\n`libcuda.so.1`\n\n(no CUDA toolkit needed) - Linux kernel 3.0+ (nbd module, built into most distros)\n`nbd-client`\n\npackage`gcc`\n\n,`make`\n\n```\ngit clone https://github.com/c0dejedi/nbd-vram\ncd nbd-vram\nsudo ./install.sh\nsudo systemctl start vram-swap-nbd\n```\n\nVerify:\n\n```\nswapon --show\n# NAME       TYPE      SIZE USED PRIO\n# /dev/nbd0  partition   7G   0B 1500\n```\n\nThe service is enabled on install, so it comes up automatically on every boot.\n\nEdit `/etc/systemd/system/vram-swap-nbd.service`\n\n:\n\n```\nEnvironment=VRAM_SETUP_SIZE_MB=7168    # how much VRAM to use\nEnvironment=VRAM_SWAP_PRIORITY=1500   # swap priority (higher = used first)\n```\n\nThe 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`\n\nis the ceiling, not a hard requirement.\n\nAfter changing, run `sudo systemctl daemon-reload && sudo systemctl restart vram-swap-nbd`\n\n.\n\nThe 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`\n\nis always respected and won't be overridden.\n\nTo change settings after install, edit `/etc/nbd-vram.conf`\n\n. Changes take effect on the next poll (within 60 seconds) or immediately on the next AC plug/unplug event.\n\n```\nsudo bash test-nbd.sh\n```\n\nAllocates VRAM, connects the NBD device, does a 1 MiB write/readback check, activates swap, then prints teardown instructions. `install.sh`\n\nhandles teardown automatically if a test instance is running.\n\nTo stress the full partition after the smoke test passes:\n\n```\nsudo bash test-fill.sh\n```\n\nWrites the entire VRAM partition with zeros, verifies a sample read back, then auto-restores swap on exit.\n\nMeasured on RTX 3070 Laptop via `test-fill.sh`\n\n(7 GiB sequential write, 4M blocks):\n\n- Sequential throughput: ~1.3 GB/s\n- Latency is lower than NVMe since the path goes through PCIe to GPU rather than storage\n\nFor laptops already using zram, set VRAM swap at a higher priority so it absorbs overflow before hitting SSD.\n\n```\nsudo bash uninstall.sh\n```\n\nMIT - Sean Lobjoit (c0dejedi)", "url": "https://wpnews.pro/news/use-your-nvidia-gpu-s-vram-as-swap-space-on-linux", "canonical_source": "https://github.com/c0dejedi/nbd-vram", "published_at": "2026-06-02 22:55:33+00:00", "updated_at": "2026-06-02 23:11:41.870147+00:00", "lang": "en", "topics": ["ai-infrastructure", "ai-chips", "ai-tools"], "entities": ["Nvidia", "RTX 3070", "CUDA", "Pop!_OS", "Linux"], "alternates": {"html": "https://wpnews.pro/news/use-your-nvidia-gpu-s-vram-as-swap-space-on-linux", "markdown": "https://wpnews.pro/news/use-your-nvidia-gpu-s-vram-as-swap-space-on-linux.md", "text": "https://wpnews.pro/news/use-your-nvidia-gpu-s-vram-as-swap-space-on-linux.txt", "jsonld": "https://wpnews.pro/news/use-your-nvidia-gpu-s-vram-as-swap-space-on-linux.jsonld"}}