Live data from Hacker News

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

github.com

101–110 of 142 posts

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

#101

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

> you probably don't need 16 GB of VRAM just to render the desktop

Microsoft: hold my beer

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

#102

Earlier quoted context omitted.

So can VRAM actually be used like regular RAM? E.g. if I have a 16GB module and my GPU has 16GB VRAM, could it be made so that my system reports 32GB RAM? What would be the implications of that?

Typical desktop GPU ram does not support being write-back cached by the CPU. With PCIe resizable BAR, you could map the area into ram, so you could technically fit 32GB to memory, but it would have to be uncached (or write-combine cached), which would make it really, really slow. There are a bunch of datacenter GPUs that support full cache coherency, but if you used them like that the VRAM would be very high latency…

[flagged]

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

#103

Earlier quoted context omitted.

Typical desktop GPU ram does not support being write-back cached by the CPU. With PCIe resizable BAR, you could map the area into ram, so you could technically fit 32GB to memory, but it would have to be uncached (or write-combine cached), which would make it really, really slow. There are a bunch of datacenter GPUs that support full cache coherency, but if you used them like that the VRAM would be very high latency…

I assume on Linux you could use something like daxctl to tell the kernel to treat the vRAM as normal RAM, but I think this would be Intel/AMD only.

I don't think it would help. It's not just a software issue that can be fixed in the kernel, the hardware fundamentally isn't part of the cache coherency system of the CPU.

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

#104
post #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://gith…

Yeah, I used to map my 8 megabytes of video memory through the mtd back in the day, it helped build those .. you know .. X11 drivers .. ;)

Man, that brings back memories.

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

#105
Why does my Apple Sillicon Mac with 32gb of RAM use (or even create?!) a swapfile, when 20gb is still unused/"free"?

Why can I not just enter a simple command to entirely-disable swapfile, like with Linux's:

>>>>swapoff -a

Seems kind of silly, unless the point is intentionally to wear-down the SSD's lifespan.

Having a GUI swapfile-disable system preference would be awesome. It would also be awesome if Apple finally abandoned this system settings/layout "phase" – it's still word-salad (compared to decades of preference panes).

#Apple #Feedback #swapfile

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

#107

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…

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 ;)

Wouldn't this prevent the nvidia GPU from being power gated since it's never "idle"? So like your battery life regresses?

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

#108
Nice, I might try using this as I'm currently on 16 GB of RAM / 11 GB VRAM and feel like the VRAM is usually idle except for when I game or try a local LLM.

It would be nice to have dynamic scaling or even just auto-shutoff on VRAM pressure if I forget I have this enabled and then fire up a game or LLM.

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

#110
Building a swap device at user level used to be one of those classic unsolvable problems, because what if your daemon needs to swap in a page in order to swap in a page? Or at least it was discussed at a reason why microkernels will never work. I’m not sure what the solution is here.
Post reply on HN