-- Leo's gemini proxy

-- Connecting to perso.pw:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini;

Mounting video ram on Linux


Author: Solène

Date: 10 February 2024

Tags: linux


Comment on Mastodon


Introduction


Hi, did you ever wonder if you could use your GPU memory as a mount point, like one does with tmpfs and RAM?


Well, there is a project named vramfs that allows you to do exactly this on FUSE compatible operating system.


In this test, I used an NVIDIA GTX 1060 6GB in an external GPU case connected with a thunderbolt cable to a Lenovo T470 laptop running Gentoo.


vramfs official GitHub project page


Setup


Install the dependencies, you need a C++ compiler and OpenCL headers for C++ (the package name usually contains "clhpp").


Download the sources, either with git or using an archive.


Run `make` and you should obtain a binary in `bin/vramfs`.


Usage


It's pretty straightforward to use, as root, run `vramfs /mountpoint 3G` to mount a 3 GB storage on `/mountpoint`.


The program will stay in foreground, use Ctrl+C to unmount and stop the mount point.


Speed test


I've been doing a simple speed test using `dd` to measure the write speed compare to a tmpfs.


The vramfs mount point was able to achieve 971 MB/s, it was CPU bound by the FUSE program because FUSE isn't very efficient compared to a kernel module handling a file system.


t470 /mnt/vram # env LC_ALL=C dd if=/dev/zero of=here.disk bs=64k count=30000
30000+0 records in
30000+0 records out
1966080000 bytes (2.0 GB, 1.8 GiB) copied, 2.02388 s, 971 MB/s

Meanwhile, the good old tmpfs reached 3.2 GB/s without using much CPU, this is a clear winner.


t470 /mnt/tmpfs # env LC_ALL=C dd if=/dev/zero of=here.disk bs=64k count=30000
30000+0 records in
30000+0 records out
1966080000 bytes (2.0 GB, 1.8 GiB) copied, 0.611312 s, 3.2 GB/s

Limitations


I tried to use the vram mount point as a temporary directory for portage (the Gentoo tool building packages), but it didn't work due to an error. After this error, I had to umount and recreate the mount point otherwise I was left with an irremovable directory. There are bugs in vramfs, no doubts here :-)


Arch Linux wiki has a guide explaining how to use vramfs to store a swap file, but it seems to be risky for the system stability.


ArchWiki: Swap on video


Conclusion


It's pretty cool to know that on Linux you can do almost what you want, even store data in your GPU memory.


However, I'm still trying to figure a real use case for vramfs except that it's pretty cool and impressive. If you figure a useful situation, please let me know.

-- Response ended

-- Page fetched on Mon May 6 03:23:27 2024