Live data from Hacker News

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

github.com

51–60 of 142 posts

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

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

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

#53
post #17

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.

Gen 4.0 x16 is 32 GB/s in each direction, but the way this is implemented is not the way you'd go about this if you wanted high performance. Edit: Their benchmarks are also run using ZRAM, which compresses pages before writing to swap. Not sure what the performance overhead of that is, but it's probably quite a bit. First of all, it's a userspace program hooking the nbd driver, which is known for being slow. It also…

yup. it's nbd and userspace making it slow. zram on the other hand adds little.

one can get rid of zram and just reimplement some compression in shaders but I think that would be a pointless optimization.

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

#54

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

It really depends on what you run and how much RAM you have to do it in. I run some machines into swap just by running a couple browsers and some containers in the background on a 16GB laptop. I've also run a single light browser and essentially nothing else on 4GB and been fine:)

I'm very surprised, I run a docker swarm with multiple docker stacks on my 16GB RAM laptop which is also my main machine. i have multiple browsers each with multiple tabs. I also run multiple VM (Qemu/KVM) and even by gaming on top of all of that, I can not make it swap.

Edit: Typo

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

#55
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/

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

#57
post #36

Earlier quoted context omitted.

Another possible reason that occurred to me: what if you have VRAM but you're not using it all the time? For example, let's say you bought a GPU because you like to play video games. When you're not actively gaming, you probably don't need 16 GB of VRAM just to render the desktop. Might as well use it for something else, right? Edit: Although, this is predicated on the system being able to release VRAM that is acting…

It's easy enough to 'offline' swap space on Linux normally so I suspect that would work fine, as long as you didn't instantly run out of RAM when doing so.

If you have enough swap on disk available, it should be fine.

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

#59
post #17

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.

Swapping to a NVMe will also consume PE cycles on your NAND, ie wearing it out over time.

RAM/VRAM don’t degrade from use.

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

#60

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

Another possible reason that occurred to me: what if you have VRAM but you're not using it all the time? For example, let's say you bought a GPU because you like to play video games. When you're not actively gaming, you probably don't need 16 GB of VRAM just to render the desktop. Might as well use it for something else, right? Edit: Although, this is predicated on the system being able to release VRAM that is acting…

I am catching up on comments

The reason I wrote this is I run this laptop in hybrid (AMD display + NVIDIA as swap). So all at VRAM was going to waste.

On your question re: switchable swap. It's on my to-do list ;)

Post reply on HN