r/bashonubuntuonwindows • u/Appropriate_Form7598 • 7h ago
WSL2 I built an open-source swap cascade for WSL2 that uses idle GPU VRAM as a compressed read cache in front of an NVMe origin (over AF_VSOCK and /dev/dxg, no TCP)
If you run heavy builds or Docker/compilers inside WSL2 on a 32 GB Windows machine, you've probably hit the point where WSL2 memory fills up and everything slows to a crawl while your GPU sits there with gigabytes of idle VRAM.
I built `vramshared` (open-source, MIT/GPL-2.0) to fix that without turning GPU memory into a single point of failure: https://github.com/emersonbusson/vramshared
How it works on WSL2 + Windows:
- Inside WSL2, `ramsharedd` sits in a 3-tier swap cascade: `zram` (prio 200) -> `ramsharedd` (prio 100, using `ublk`/`io_uring` or falling back to `NBD` on stock WSL2 kernels) -> standard WSL2 disk swap (prio -2).
- VRAM is never trusted with dirty pages. Every write goes to an authoritative NVMe origin first (`WriteThroughCacheBackend`), and idle GPU VRAM acts strictly as a volatile read cache (with optional LZ4/nvCOMP compression in 2 MiB slabs and CRC32 checks before decode). If you launch a game or local LLM on Windows, it yields VRAM immediately and falls back to NVMe reads.
- Zero TCP between guest and host: inside WSL2 it queries per-process WDDM VRAM budgets directly via `/dev/dxg`, talks to the Windows host service (`ramshared-winsvc`) over `AF_VSOCK` / `AF_HYPERV` for leases and an opt-in pooled VRAM cache (`RSCP` v1, port 2762), uses a least-privilege SCM broker (`ramshared-winbroker`) bound only to local Named Pipes, and routes WSL2->Windows calls through a tiny SHA-256-sealed GUI launcher (`ramshared-hostlaunch`, `CREATE_NO_WINDOW`) so console windows don't flash on your desktop.
- Teardown (`ramshared down --plan`) checks resident RAM before swapoff so you don't deadlock WSL2 under memory pressure, and `ramshared top` gives a live TUI with per-engine GPU activity and swap drain status.
Full disclosure: the stress harness is in `tools/benchmarks/`, but I haven't published benchmark tables in the README yet. If anyone here runs heavy Rust/C++ builds or multiple distros in WSL2 and wants to try it out or break it, I'd appreciate the feedback.