Skip to content

Instantly share code, notes, and snippets.

@reatlat
Created September 16, 2025 21:13
Show Gist options
  • Select an option

  • Save reatlat/b3f495b471c327515dafac5ff7421520 to your computer and use it in GitHub Desktop.

Select an option

Save reatlat/b3f495b471c327515dafac5ff7421520 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
# --- Detect Steam App ID from environment ---
APPID="${SteamAppId:-${STEAM_COMPAT_APP_ID:-}}"
if [[ -z "${APPID}" ]]; then
echo "[RAMCACHE] ERROR: Steam AppID not found in env (SteamAppId / STEAM_COMPAT_APP_ID)."
echo "Launch this via Steam (it sets the vars), or set APPID= manually."
exit 1
fi
# --- Detect Steam root (native or Flatpak) ---
STEAM_ROOT="$HOME/.steam/steam"
if [[ ! -d "$STEAM_ROOT" ]]; then
ALT="$HOME/.var/app/com.valvesoftware.Steam/.local/share/Steam"
if [[ -d "$ALT" ]]; then
STEAM_ROOT="$ALT"
fi
fi
if [[ ! -d "$STEAM_ROOT" ]]; then
echo "[RAMCACHE] ERROR: Steam root not found."
exit 1
fi
# --- Paths to accelerate ---
SHADER_SSD_PERSIST="$STEAM_ROOT/steamapps/shadercache-ssd/$APPID" # persistent storage on SSD
SHADER_LINK_PATH="$STEAM_ROOT/steamapps/shadercache/$APPID" # path Steam/game expects
SHADER_RAM="/dev/shm/steam-ramcache/$APPID/shadercache" # RAM folder
# (optional) accelerate DXVK/VKD3D caches as well:
DXVK_SSD_PERSIST="$STEAM_ROOT/steamapps/compatdata/$APPID/dxvk-cache"
DXVK_LINK_PATH="$STEAM_ROOT/steamapps/compatdata/$APPID/dxvk-cache"
DXVK_RAM="/dev/shm/steam-ramcache/$APPID/dxvk-cache"
VKD3D_SSD_PERSIST="$STEAM_ROOT/steamapps/compatdata/$APPID/vkd3d-cache"
VKD3D_LINK_PATH="$STEAM_ROOT/steamapps/compatdata/$APPID/vkd3d-cache"
VKD3D_RAM="/dev/shm/steam-ramcache/$APPID/vkd3d-cache"
# Enable/disable additional caches
ACCEL_DXVK="${ACCEL_DXVK:-1}"
ACCEL_VKD3D="${ACCEL_VKD3D:-1}"
rsync_safe() { rsync -a --delete --inplace --no-whole-file "$@"; }
prepare_pair() {
local persist="$1" linkpath="$2" ramdir="$3"
# If there is still a normal folder instead of a symlink, move it to persistent storage
if [[ -e "$linkpath" && ! -L "$linkpath" ]]; then
mkdir -p "$(dirname "$persist")"
mkdir -p "$persist"
rsync_safe "$linkpath/" "$persist/" || true
rm -rf "$linkpath"
fi
# Create RAM folder and preload data from persistent storage
mkdir -p "$ramdir"
if [[ -d "$persist" ]]; then
rsync_safe "$persist/" "$ramdir/" || true
fi
# Replace the original path with a symlink to the RAM folder
mkdir -p "$(dirname "$linkpath")"
ln -sfn "$ramdir" "$linkpath"
}
sync_back_pair() {
local persist="$1" linkpath="$2" ramdir="$3"
mkdir -p "$persist"
rsync_safe "$ramdir/" "$persist/" || true
# After exit, remove symlink and restore a normal folder
rm -f "$linkpath"
mkdir -p "$linkpath"
rsync_safe "$persist/" "$linkpath/" || true
}
cleanup() {
echo "[RAMCACHE] Syncing caches back to SSD..."
sync_back_pair "$SHADER_SSD_PERSIST" "$SHADER_LINK_PATH" "$SHADER_RAM"
if [[ "$ACCEL_DXVK" == "1" ]]; then
sync_back_pair "$DXVK_SSD_PERSIST" "$DXVK_LINK_PATH" "$DXVK_RAM"
fi
if [[ "$ACCEL_VKD3D" == "1" ]]; then
sync_back_pair "$VKD3D_SSD_PERSIST" "$VKD3D_LINK_PATH" "$VKD3D_RAM"
fi
echo "[RAMCACHE] Done."
}
trap cleanup EXIT
echo "[RAMCACHE] AppID=$APPID | Steam=$STEAM_ROOT"
echo "[RAMCACHE] Preparing RAM caches..."
prepare_pair "$SHADER_SSD_PERSIST" "$SHADER_LINK_PATH" "$SHADER_RAM"
if [[ "$ACCEL_DXVK" == "1" ]]; then
prepare_pair "$DXVK_SSD_PERSIST" "$DXVK_LINK_PATH" "$DXVK_RAM"
fi
if [[ "$ACCEL_VKD3D" == "1" ]]; then
prepare_pair "$VKD3D_SSD_PERSIST" "$VKD3D_LINK_PATH" "$VKD3D_RAM"
fi
echo "[RAMCACHE] Launching game..."
exec "$@"
@reatlat
Copy link
Author

reatlat commented Sep 16, 2025

Steam RAM Cache Launcher

This script allows you to temporarily move Steam shader caches (and optionally Proton’s DXVK/VKD3D caches) into RAM (/dev/shm) while a game is running.
When the game exits, caches are synced back to SSD automatically.

With plenty of RAM (e.g. 32–64 GB), this can reduce shader stutter and improve overall responsiveness in games.


Features

  • Moves Steam shadercache into RAM on game launch
  • (Optional) Moves DXVK/VKD3D caches for Proton games into RAM
  • Automatically syncs back to SSD after exit
  • Universal: works with any game, detects AppID automatically
  • Safe: restores normal folders if something goes wrong

Installation

  1. Save the script to your home directory:

    mkdir -p ~/bin  
    nano ~/bin/steam-ramcache  
  2. Paste the script contents and save (Ctrl+O, Enter, then Ctrl+X).

  3. Make it executable:

    chmod +x ~/bin/steam-ramcache  

Usage

  1. In Steam, right-click on a game → PropertiesLaunch Options.

  2. Enter:

    /home/<USERNAME>/bin/steam-ramcache %command%  

    Replace <USERNAME> with your Linux username.

  3. Launch the game.
    The script will:

    • Move shader/DXVK/VKD3D caches into /dev/shm
    • Create symlinks so Steam and Proton use the RAM cache
    • Sync caches back to SSD when the game exits

Options

Disable DXVK and VKD3D caching (use only Steam shadercache):

ACCEL_DXVK=0 ACCEL_VKD3D=0 /home/<USERNAME>/bin/steam-ramcache %command%  

Verifying

Check that the game’s shadercache is a symlink:

ls -l ~/.steam/steam/steamapps/shadercache  

Monitor RAM usage:

df -h /dev/shm  

Troubleshooting

  • Permission denied → ensure script is executable:
    chmod +x ~/bin/steam-ramcache

  • Steam root not found
    The script checks both:

    • ~/.steam/steam
    • ~/.var/app/com.valvesoftware.Steam/.local/share/Steam (Flatpak Steam)
  • rsync not found → install via your package manager.

  • Low RAM → disable DXVK/VKD3D acceleration with environment variables.


Uninstall / Revert

To stop using the RAM cache for a game, simply remove the script from Launch Options in Steam.
The script restores normal folders after every exit, so nothing permanent is left behind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment