Use video RAM as swap in Linux

If you are into the headless or console experience, there are a couple of ways to put your machine’s graphics card to good use. Most new boxes come with a GPU that has a substantial amount of RAM that is normally used for direct rendering. Using the Memory Technology Device (MTD) support in the Linux kernel, you can actually map the video card RAM to a block device and format it for swap use or as a ramdisk.

The Gentoo wiki has detailed instructions for doing this. The only tricky part is determining the video memory address, but after that it’s a simple modprobe to load the MTD driver and you can run mkswap/swapon on the device just as if you were creating a normal swap disk. Considering many machines have 512MB of video RAM and it’s waaaaay faster than disk, this could give you a pretty huge performance boost.

You can still use your graphics card in X, but you’ll need to reserve a small chunk of that RAM for normal graphics use, use the VESA driver, and add inform the driver that it should only use that teensy portion of memory. “VideoRam 4096” in the XF86Config, for instance, will let you use your card in X and only eat the first 4MB of RAM. Everything after that 4MB is fair game for swap. Michal Schulz wrote a bit about calculating the memory address offsets to make this all work. It’s the second link below, for those of you who aren’t hardcore enough to deal with only the command line.

Use Memory On Video Card As Swap
Configuring X11 With A VRAM Storage Device

Discuss this article with the rest of the community on our Discord server!

ADVERTISEMENT

Maker Faire Bay Area 2023 - Mare Island, CA

Escape to an island of imagination + innovation as Maker Faire Bay Area returns for its 15th iteration!

Buy Tickets today! SAVE 15% and lock-in your preferred date(s).

FEEDBACK