About swappy
The story and engineering principles behind rapid, dependable Linux swap allocation.
Why was swappy created?
Every Linux systems administrator, DevOps engineer, or cloud architect has experienced the dreaded moment when a lightweight cloud virtual machine runs out of memory during a compiler build, Docker image generation, or sudden spike in web traffic.
When the Linux Out-Of-Memory (OOM) killer kicks in, critical processes are terminated indiscriminately. While adding more physical RAM is the ultimate long-term fix, provisioning an immediate swap file provides an essential safety net that prevents system crashes and gives services time to recover or complete memory-intensive tasks.
Traditionally, creating a swap file required executing 5–6 separate shell commands:
- Allocating contiguous blocks with
ddorfallocate. - Setting strict permissions with
chmod 0600to prevent local users from reading memory dumps. - Setting root ownership with
chown root:root. - Formatting the file with swap signatures using
mkswap. - Enabling the swap area with
swaponand specifying priority flags. - Verifying active allocation with
swapon -s.
swappy encapsulates these repetitive, error-prone steps into a single, reliable command: swappy init.
Open Source & Community
swappy is released under the GNU General Public License v3.0 (GPL-3.0). It is free to use, modify, distribute, and integrate into your own automation infrastructure, deployment pipelines, and configuration management playbooks.
Maintained by Joshua Cox and open source contributors worldwide on GitHub.