logoalt Hacker News

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

230 pointsby tanelpoderyesterday at 10:55 PM65 commentsview on HN

Comments

yjftsjthsd-hyesterday at 11:36 PM

> 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.

Well, that does at least answer my immediate question about why I would ever swap from expensive RAM to really expensive RAM:) Feels niche, but when you want it it's a good idea.

show 1 reply
RachelFtoday at 12:31 AM

Nice idea, but something has gone very wrong here:

>Sequential throughput: ~1.3 GB/s

[on a RTX 3070 Laptop]

This RTX 3070 chip is on PCIe 4.0 x16 which should give 64GB/s. The 8GB of GDDR6 is 448GB/s.

Swapping to an NVMe drive would be twice as fast, but with higher latency.

show 2 replies
xfalcoxyesterday at 11:50 PM

Given my dev machine has 32GB of RAM and 32GB of VRAM that sits mostly idle when I'm not running AI models, this is not that bad of an idea.

show 1 reply
drdaemantoday at 1:04 AM

What about backpressure, how does it handle requirements for VRAM allocation when VRAM is used for swap space?

With X11 it's not that bad (buffers are pre-allocated), but with Wayland allocations are a lot more dynamic, so running low on VRAM can easily crash the whole desktop. I just had a few of such crashes with Hyprland+llama-server+KVM switching between computers without freeing VRAM.

molticrystaltoday at 4:05 AM

For windows I saw something similar to this years ago. An experimental proof of concept driver that allows the creation of a ram drive from vram for NVIDIA cards. Sequential is fast as you'd expect, random has lots of room for improvement.

>GpuRamDrive

>Create a virtual drive backed by GPU RAM.

https://github.com/prsyahmi/GpuRamDrive

Fork with AMD support:

https://github.com/brzz/GpuRamDrive/

show 1 reply
kimixatoday at 3:30 AM

I remember this being a thing done a while back using linux's MTD/phram drivers - https://wiki.archlinux.org/title/Swap_on_video_RAM - not sure if that's still relevant though as I don't know how it'll interact with DRM and how it handles reserving some of the vram - the suggested limit using xorg.conf is probably pretty obsolete now.

That page also has a fuse filesystem implementation on top of opencl - https://github.com/Overv/vramfs - which may be more compatible.

dragontamertoday at 12:10 AM

Remember how 16GBs used to be an enterprise level database mainframe?

Well, GPUs also have stupid amounts of compute on them. I have to imagine that there is some kind of database format that's useful with GPU compute attached.

Since the data is already in VRAM, the GPU can sort, join, or otherwise manipulate data as needed.

show 4 replies
sgjohnsontoday at 1:30 AM

>Sequential throughput: ~1.3 GB/s

sounds VERY low, also, wouldn't random read/write speed be MUCH more relevant here?

zx8080today at 5:39 AM

Nvme ssd weights much less than GPU, and it matters for a laptop.

rwmjtoday at 4:20 AM

Similar but using OpenCL APIs, so it works on AMD (for some definition of "works" since their drivers are quite buggy): https://libguestfs.org/nbdkit-vram-plugin.1.html

show 1 reply
willis936today at 12:19 AM

I'm more interested in the opposite. Nvidia linux drivers crash when you try to address more VRAM than you have. It'd be nice if they didn't.

show 1 reply
mmastractoday at 1:44 AM

I seriously looked at this as a way to improve the RAM situation in a QNAP 2U unit that I was having trouble sourcing RAM for. It's somewhat annoying that legit memory-over-PCIe is gated on PCIe5 and chipset support.

In the end I just had to bite the bullet and take a gamble on finding ECC DDR4 RAM that would work with the ancient AMD chipset...

This particular implementation seems to be running over too many layers to be particularly performant. Why not a custom block driver instead?

show 1 reply
dlt713705today at 12:50 AM

Does anyone these days really use swap for anything than S4 suspend ?

show 3 replies
hardwaresoftontoday at 12:12 AM

You want to waste VRAM, in this economy?

show 1 reply
UnfitFootprinttoday at 12:34 AM

No software benchmarks? BAR for RAM is cool but I want to see how much it _actually_ beats pcie nvme

jcmfernandesyesterday at 11:38 PM

Q: Why? A: Why not?

LouisvilleGeektoday at 12:32 AM

Finally a use for the expensive ram when it's not needed in workloads!

Now if it could be dynamically used and vacated on other GPU workloads?

effnorwoodtoday at 12:27 AM

use your car for an anchor on a big boat!

show 2 replies
bobsmoothtoday at 12:26 AM

RAM disks have always fascinated me. In a different timeline every PC has a 100gb of RAM and 50TB HDDs are the norm.

show 1 reply
lowbloodsugartoday at 1:49 AM

This is why I read HN.

nialv7today at 2:08 AM

I mean, you prompted something useful out of an AI, good job. But then use that to ask for donation? Feels weird, man.

usxr1515today at 12:47 AM

Nice

dbdrtoday at 6:02 AM

[dead]

Sohcahtoa82yesterday at 11:38 PM

[dead]

simonaskyesterday at 11:36 PM

I mean, cool, but I’d rather not?

show 4 replies