Enable Process KSM (Linux Only)
Free RAM by letting Linux merge your duplicate model pages (KSM for ComfyUI)
- ksm_stats
If you run two ComfyUI instances on the same machine - an API worker plus your interactive install, a box with a couple of GPUs, a second instance for a different set of nodes - you're paying for the same model weights twice in RAM. ComfyUI is already a memory hog; double it and suddenly an 8 GB checkpoint plus its VAE and text encoders stop being "free" and start pushing you toward swap. Enable Process KSM is a Linux-only nudge that gets the kernel to notice those duplicate pages and merge them, and in a multi-instance setup it's one of the few genuinely free wins left.
Before you get excited: the savings are not magic, and the README says as much. KSM (Kernel Samepage Merging) only helps when identical pages actually exist. Two instances loading the same checkpoint file produce gigabytes of byte-identical resident pages - that's the case where it shines. One instance, one model, nothing duplicated: you'll save almost nothing, and you might even lose a little to the scanner's overhead.
How it works (and the name is a small lie)
The node itself doesn't enable anything when you run it. The real work happens the moment the pack loads at ComfyUI startup: __init__.py calls prctl(PR_SET_MEMORY_MERGE, 1) via ctypes, telling the kernel that this process's newly allocated anonymous pages are eligible to be merged. That's it - install the pack, restart, and the process is opted in. The EnableProcessKSMNode node you drop into a graph is a diagnostic: it reads back prctl(PR_GET_MEMORY_MERGE) to report whether process merging is ACTIVE, checks /proc/<pid>/ksm_stat for per-process stats when your kernel provides it, and appends the sysfs tuning commands you'd want to run anyway.
One catch that trips people up: opting in is not enough. KSM only actually merges pages if the kernel's KSM daemon is running, and most desktop distros leave it off:
echo 1 | sudo tee /sys/kernel/mm/ksm/run
The inputs and outputs that matter
There are none on the input side - this node takes zero inputs, so there's nothing to configure in the graph. All the real tuning lives in sysfs on the host. The single output is:
ksm_stats(STRING) - a text dump with the PID, the ACTIVE/INACTIVE status, current per-process stats if available, and the kernel commands to speed merging up. Wire it into a Show Text / Preview Text node to actually read it, or leave it dangling as a one-time validation and delete it from the workflow.
Installing it
It's a one-file utility with no pip dependencies and no model downloads - just ctypes from the Python standard library. Easiest path is ComfyUI Manager (search "comfyui-process-ksm"). Or the manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/Nuitari/comfyui-process-ksm
Then restart ComfyUI. Look for the [KSM AUTOMATION] Successfully enabled KSM on startup line in the console log - that's your confirmation it took. If you're on Windows or macOS, skip this pack entirely; the prctl call fails gracefully and nothing useful happens. It's Linux-only, by design.
Common issues and gotchas
- No savings. That's expected with a single instance. The README's own framing: "don't expect much in savings." This is a multi-instance tool.
- Negative
general_profit./sys/kernel/mm/ksm/general_profitshows net savings. If it's negative, the scan overhead outweighs the merging - turn KSM back off and move on. - "ksm_stat file not found" in the output. Harmless; older kernels don't expose the per-process file. The ACTIVE status line is what matters.
- Running inside Docker. The sysfs KSM knobs live on the host and usually aren't writable from a container, so enable the daemon at the host level or it silently does nothing.
- Slow merging. The daemon defaults to a modest scan rate. Bump it if you're impatient:
echo 10 | sudo tee /sys/kernel/mm/ksm/sleep_millisecsandecho 5000 | sudo tee /sys/kernel/mm/ksm/pages_to_scan.
It's a tiny pack, but for the specific problem of several ComfyUI processes chewing on the same weights, it's the right tool - and the diagnostic node at least gives you a number to prove it's working.
Inputs (0)
No inputs
Outputs (1)
| Name | Type | Description |
|---|---|---|
| ksm_stats | STRING | — |