Live data from Hacker News

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

github.com

121–130 of 142 posts

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

#121

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

[dead]

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

#122

Earlier quoted context omitted.

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?

Is VRAM not directly accessible by the system then? Since it's mapped directly into the CPU's address space, I had assumed that there's a simple DMA controller managing said access and I would then also naively assume that said controller is separate (or at least on a separate power plane) from the actual GPU.

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

#123

Earlier quoted context omitted.

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?

Good point, you might wanna disable it on battery, but I'm guessing a lot of people have their laptop plugged in practically 24x7.

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

#124
post #122

Earlier quoted context omitted.

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

Is VRAM not directly accessible by the system then? Since it's mapped directly into the CPU's address space, I had assumed that there's a simple DMA controller managing said access and I would then also naively assume that said controller is separate (or at least on a separate power plane) from the actual GPU.

they are talking about the scenario of having a discreet GPU in addition to the GPU on the CPU. So there's 2 GPUs, and the nvidia one has its own VRAM (typically of the GDDR variety even) that isn't shared with system RAM (hence the purpose of this project). So that also means 2 memory controllers.

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

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

It's true that Linux kernel is the throughput bottleneck. Unfortunately, the optimizations described above aren't sufficient to get within even 10% of hardware bandwidth.

Even if the swap system overhead drops to just a data copy, the memory management layer prevents swap from scaling to higher bandwidths. The issue is not data movement; it is in the page unmapping step (which requires expensive TLB shootdowns). Larger kernel changes are required.

My group wrote a paper on this: https://dl.acm.org/doi/10.1145/3731569.3764842

Linux's swap system is undergoing some large refactors lately. Hopefully some insights either from our work or Hermit (NSDI '23) can make it in to the mainline. I think Hermit's `rmap` optimization in particular is a candidate for upstream use.

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

#129

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…

The principle of a paging system is that main memory is just a cache for secondary memory, and the concept of "free memory" ideally rather means something like "memory that can be quickly reclaimed for another purpose". Sometimes anonymous memory will be of less us occupying main memory at some given time than would be letting cached file contents take their place.

You've described what the purpose of a swapfile is – thanks? My argument is simply that you don't need a swapfile with enough real memory; that swapfiles can unnecessarily shorten the lives of SSDs, entirely unnecessarily.

----

>I have 20GB of RAM free (me)

>>~need to have quick access to main memory

>I have 20GB of RAM free (still me)

>>~yeah but "quickly reclaimed for another purpose"

>I have 20GB of RAM free (!m!e!)

//of//32GB//ttl//

----

In linuxland, I'd just type `sudo swapoff -a` and be done with it. That machine has 96GB of RAM, so it would have ~84GB of RAM free (if, hypothetically, the same hardare/configuration were operating that system).

Does. not. need. a swapfile.

The operating system, during bootup, should think "hey I have dozens of gigabytes of RAM, won't be needing any swapfiles" – behind the scenes and without input.

Post reply on HN