7 ms·
Use your Nvidia GPU's VRAM as swap space on Linux
- usxr1515 4mo agoNice
- simonask 4mo agoI mean, cool, but I’d rather not?
- margalabargala 4mo agoSo don't. Not everything is for you.
- TurkTurkleton 4mo agoDidn't you hear? The author of this daemon is going around and forcibly installing it on anyone's computer that has soldered memory and an Nvidia GPU. I heard even he brings a Ludovico-technique chair with him and straps you in and pins your eyelids open like A Clockwork Orange so you have to watch.
- dspillett 4mo agoSo, erm, don't?
- gchamonlive 4mo agoWouldn't it be faster to swap to vram if you are sitting there with 8gigs of it unused than swapping to ssd and burning its write cycles, assuming you absolutely need swap
- monkpit 4mo agoThe HN equivalent of “1 star - I’ve never eaten at this restaurant” type of reviews.
- xfalcox 4mo agoGiven 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.
- mathisfun123 4mo agothis is the pcmasterrace equivalent of being all upper body and with scrawny legs lol
- tempoponet 4mo agoIt's fine for dense models where you need them in VRAM, less so for MoE where you're offloading layers to ram. But 32/32 is pretty good for both in the popular ~30b range right now.
- xxs 4mo agorunning 5090 on 32GB RAM is just weird, still
- zamadatix 4mo agoActually not that crazy of a spread. E.g. I have 48 GB + 32 GB in my gaming PC because if you go beyond 48 GB you start having to trade off more and more performance to keep the memory controller from falling over, so you really have to have a good reason to want to load more. Server platforms, like Epyc, it tends not to matter as much because you have so many channels for bandwidth and a beefier memory controller to handle them. Then on the VRAM side it's more about what makes sense for the GPU and how you plan on using it there (games or AI or modeling or whatever), and for a lot of cases the 5090 is just a good card to get for one reason or another (it just has a ton of compute + bandwidth for a consumer part).
- ownagefool 4mo agoWhat's this trade off about? I thought it was a simple 2 dims are probably better than 4, but unsure how you'd ever land on 48?
- yjftsjthsd-h 4mo ago> 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.
- Wowfunhappy 4mo agoAnother 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 as swap when it's time to start a game. Can it do that?
- Saris 4mo agoIt'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.
- eru 4mo agoIf you have enough swap on disk available, it should be fine.
- c0dejedi 4mo agoI 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 ;)
- kllrnohj 4mo agoWouldn't this prevent the nvidia GPU from being power gated since it's never "idle"? So like your battery life regresses?
- jcmfernandes 4mo agoQ: Why? A: Why not?
- Sohcahtoa82 4mo ago[dead]
- bobsmooth 4mo agoRAM disks have always fascinated me. In a different timeline every PC has a 100gb of RAM and 50TB HDDs are the norm.
- pixl97 4mo agoBack when HDDs were all there was ramdisks were interesting, but SSDs pretty much killed most of that as they have massively increased IOPS over disks. Hard drives that huge scare me as it would take days to backup all the data off them.
- bobsmooth 4mo agoIn my fantasy RAM was the predominate technology over flash.
- freedomben 4mo agoHaving 128 GB in my desktop, I can never, ever go back. It truly unlocks a whole different computing experience. I've only had one OOM in the last 5 years and it was in my own code where I had a bad memory leak. It's the only way to live
- dragontamer 4mo agoRemember 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.
- Nate75Sanders 4mo agoPossibly LSM compaction.
- einichi 4mo agooh god please don't create more demand for GPUs
- tmostak 4mo agoGPU-accelerated databases have a long history. I founded HeavyAI (previously MapD/OmniSci) in 2013, but there are or have been many other startups in this space, such as Voltron Data, Kinetica, Sqream, etc. And now you have major players like IBM, Starburst, and Microsoft (which just announced Fabric SQL on GPU today) working on their own GPU-accelerated systems. GPUs have a huge advantage in terms of compute, memory, and interconnect bandwidth over CPU, as long as you can keep them fed with data. I believe within 2-3 years databases and data warehouses on GPU will be common. The widespread use of agents to query data will be a part of this, as there will be a need to run far more queries at lower latency than needed for the ETL and BI workloads of the past.
- c0dejedi 4mo agoInsightful take, looking into these
- myself248 4mo agoAnd smart NICs are moving significant amounts of compute directly onto the network interface, though I haven't seen anyone combining a GPU and a 100GbE NIC into a single part yet. Where does a few more steps of evolution take us? A wide path between a few heavy devices, and then the CPU off to the side just orchestrating the data flow?
- hardwaresofton 4mo agoYou want to waste VRAM, in this economy?
- kevin_thibedeau 4mo agoIt's 1GiB. What could it cost, $10?
- hardwaresofton 4mo agocan't stand the thought of people not understanding the above reply[0] [0]: https://knowyourmeme.com/memes/its-one-banana-michael-what-could-it-cost-10 https://knowyourmeme.com/memes/its-one-banana-michael-what-c...
- theandrewbailey 4mo agoI wish it cost $10. (Kinda goes against the original spirit of the reference)
- willis936 4mo agoI'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.
- SV_BubbleTime 4mo agoThey already do that on windows and it kinda sucks. If you are targeting something like LMStudio or ComfyUI, both of those have superior methods to do exactly this.
- effnorwood 4mo agouse your car for an anchor on a big boat!
- SV_BubbleTime 4mo agoI mean, if you aren’t using the car while using the boat and it won’t really damage the car… yes?
- oneshtein 4mo agoAnd when you use your car, then what?
- SV_BubbleTime 4mo agoThen it doesn’t function as a boat anchor anymore. The point is that only a few people are using their GPU at any time. The bandwidth is terrible here, but if it wasn’t, this would be a good utilization of resources.
- bandrami 4mo agoThere's probably somebody in Monaco who does that
- RachelF 4mo agoNice 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.
- Teknoman117 4mo agoGen 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 uses a bounce buffer in userspace before transferring to the GPU. So when the kernel needs to swap a page, it has to first copy it into a userspace facing buffer. The userspace program that has to wake back up and issue the cuda operation to copy the page into device memory. nbd also doesn't really do a good job of supporting high queue depth or merging adjacent accesses. So if the kernel is issuing a bunch of 4K page swaps without any coalescing, you're going to end up with at least million kernel/userspace context switches per second just to handle 4 GB/s (4 GB / 4K page), let alone 64 GB/s. And that's just the NBD portion, forget the mess that is the NVIDIA driver. PCIe can move a lot of data, but in order to get anything even resembling the full bandwidth, you have to have use DMA engines with long page lists. Having to set up a transfer for every 4K page over PCIe will not reach full saturation of the bus. Swapping to NVMe is a very optimized path -> the swapper can submit lists of pages directly to the NVMe driver and the controller can DMA them directly out of RAM, no copies or context switches CPU side at all. This could probably be improved by migrating to the ublk driver as it might let you avoid the userspace bounce buffer. It'd also be able to have multiple write queues to at least set up CUDA copies in parallel.
- lstodd 4mo agoyup. 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.
- LouisvilleGeek 4mo agoFinally 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?
- UnfitFootprint 4mo agoNo software benchmarks? BAR for RAM is cool but I want to see how much it _actually_ beats pcie nvme
- deleted 4mo ago[deleted]
- dlt713705 4mo agoDoes anyone these days really use swap for anything than S4 suspend ?
- kccqzy 4mo agohttps://news.ycombinator.com/item?id=40697318 https://news.ycombinator.com/item?id=40697318 This HN comment and the linked post brought up a lot of good points. The main takeaway is that swap should primarily be considered a mechanism for equality of reclamation, not for emergency extra memory, where equality of reclamation means file-backed pages and anonymous pages are subject to similar criteria for being evicted from physical memory. I used to have zero swap on my Linux desktop and this convinced me to add at least a small swap partition.
- sidewndr46 4mo agoI just set swappiness to zero years ago and never looked back.
- kccqzy 4mo agoThat’s like the complete opposite advice. Chris said the lowest recommended swappiness is 1. I have it set to 100.
- sidewndr46 4mo agoAgreed, but it means I still don't run into an OOM condition abruptly since the swap is there. It turns out modern disks are pretty fast, so the system freezes for a bit as physical memory is exhausted. Then I usually stop some of what I am doing and it goes back to normal.
- dlt713705 4mo agoMy point is not to say that swap should not be configured on a Linux system. On bare-metal machines, I personally always set a swap partition equal in size to the amount of RAM because I usually want to be able to put the machine into S4 (suspend to disk). I don't consider swap to be emergency RAM storage. I know that the kernel will decide by itself to use swap even if it has plenty of available RAM and the swappiness threshold is not reached. Nevertheless, my two decent laptops (one with 16 GB RAM, the other with 64 GB RAM) never swap, even with Docker Swarm and multiple stacks, multiple VMs, desktop activities, and gaming. It's been a while since I last saw a physical machine actively swapping. I understand that some limited hardware may need swap, but I can't see such hardware having a GPU with plenty of VRAM. That said, hacking things is always fun :)
- drdaeman 4mo agoWhat 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.
- sgjohnson 4mo ago>Sequential throughput: ~1.3 GB/s sounds VERY low, also, wouldn't random read/write speed be MUCH more relevant here?
- mmastrac 4mo agoI 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?
- Teknoman117 4mo agoMemory on an expansion card isn't gated on PCIe 5, it's gated on CXL support. CXL and PCIe use the same electrical/physical layer but the protocol is very different. The problem with putting (system) RAM on a PCIe card is that PCIe is not a cache-coherent interconnect. If you have a cache line that resides on your GPU sitting inside your processor's cache a remote modification to that memory by either the GPU, another CPU core or some other PCIe device with NOT invalidate the CPU cache line. You also have the fun situation that if it's modified on both ends simultaneously the resulting state will be non-deterministic. Device drivers have to be very careful about synchronization when accessing memory-like areas on PCIe. CXL adds a cache coherency protocol among other things, so that invalidations and snoops can be exchanged over the interconnect.
- wang_li 4mo agoIt’s deterministic. But as the user you don’t know enough to know what was determined.
- lowbloodsugar 4mo agoThis is why I read HN.
- nialv7 4mo agoI mean, you prompted something useful out of an AI, good job. But then use that to ask for donation? Feels weird, man.
- dspillett 4mo agoAs much as I'm avoiding GenAI myself⁰ I think your reaction is what feels a bit weird. You wouldn't be sending a tip for simply prompting the LLM, but for having the original idea and verifying/testing the result. If you don't feel right donating for that, then don't. Seeing a “buy me a coffee” link is hardly onerous, and it isn't exactly in-your-face here (I didn't notice at all until your comment mentioned it). -------- [0] I want to code, I like the nitty-gritty, and if I want to outsource I'd prefer to outsource to a human¹ than GenAI [1] they might outsource to GenAI of course, that is their choice and as long as they properly verify the output before handing it on to me I shouldn't have to care
- kimixa 4mo agoI remember this being a thing done a while back using linux's MTD/phram drivers - https://wiki.archlinux.org/title/Swap_on_video_RAM 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 https://github.com/Overv/vramfs - which may be more compatible.
- aa-jv 4mo agoYeah, 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.
- molticrystal 4mo agoFor 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 https://github.com/prsyahmi/GpuRamDrive Fork with AMD support: https://github.com/brzz/GpuRamDrive/ https://github.com/brzz/GpuRamDrive/
- c0dejedi 4mo agoThanks for sharing this, good read :-)
- rwmj 4mo agoSimilar 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 https://libguestfs.org/nbdkit-vram-plugin.1.html
- c0dejedi 4mo agoThank you for pointing me to this
- zx8080 4mo agoNvme ssd weights much less than GPU, and it matters for a laptop.
- dbdr 4mo ago[dead]
- steeve 4mo agosidenote: it is possible to use Vulkan to map GPU memory to CPU space and even map it back to CUDA: https://x.com/steeve/status/2055042304344231978?s=20 https://x.com/steeve/status/2055042304344231978?s=20
- theblazehen 4mo agoI've implemented the same idea with OpenCL: https://github.com/theblazehen/vramblk https://github.com/theblazehen/vramblk There is originally https://github.com/Overv/vramfs https://github.com/Overv/vramfs however that has the overhead of a FUSE filesystem + loop device when using as a swap device. The performance is rather lackluster however, it's far from a miracle "now you effectively have more ram for a 90% performance drop" - it definitely feels like traditional swapping
- moviepiq 4mo ago[dead]
- mrwizrd 4mo agoI have long wished it was possible to do this. What a great bit of code. Thanks.
- enthus1ast_ 4mo agoAnd now, I want HDMI as direct connection hight speed network socket.
- voxadam 4mo agoHDMI is largely unidirectional.
- enthus1ast_ 4mo agoBut it's 48 gbp/s unidirectional.
- londons_explore 4mo agoIt seems obvious to me that this should be a built in functionality of the kernel. The kernels job is to manage resources - and GPU ram is one such resource, and it can be used for many of the same uses as regular ram.
- ProllyInfamous 4mo agoWhy 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
- netbsdusers 4mo agoThe 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.
- ProllyInfamous 4mo agoYou'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.
- NortySpock 4mo agoNice, 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.
- vecchio 4mo ago[dead]
- tlb 4mo agoBuilding 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.
- netbsdusers 4mo agoThe general principle is that what is involved in paging should not be paged itself. Wiring the memory of that whole daemon is then a trivial solution to the problem.
- kccqzy 4mo agoYour daemon can be smart enough to know which are its own pages and prevent them from being swapped out. The Linux kernel also prevents its own text pages from being swapped out, so the solution exists and I don’t see why it doesn’t apply to microkernel designs.
- tgtweak 4mo agoI think you can definitely improve the throughput/iops by using BAR vs treating it like a file store/mount through cuda which adds a lot of overhead.
- 1matin 4mo agoNice idea, but I'm sure a ton of things can go wrong with it. It needs extensive edge case handling in order to be usable widely.
- ryanshrott 4mo ago[dead]
- cgnguyen 4mo ago[dead]
- deleted 4mo ago[deleted]
- hearstcastle8 4mo agoIterating VRAM as swap space. Reliable tracker .iso installs on SSD drive.
- AI2070 4mo agoThe catch is volatility: one CUDA process reclaims the VRAM, and your swap just evaporates.
- c0dejedi 4mo ago[flagged]
- c0dejedi 4mo ago[flagged]
- c0dejedi 4mo agoThe nbd-vram daemon got a thread pool, ~4x concurrent 4K IOPS, and the swap-pressure freeze is finally gone. Fresh benchmarks against NVMe included: https://www.seanlobjoit.com/posts/2026-06-12-vram-swap-two-weeks-in-multithreading-and-the-deadlock https://www.seanlobjoit.com/posts/2026-06-12-vram-swap-two-w...