Docs / How-to guides

Add swap to your Otto server

Give your Otto server a swap file, so that when its sessions and builds run it out of memory it slows down instead of killing processes.

Before you start

Without swap, a server that runs out of memory has the kernel's OOM killer end a process at once: a session's Claude, a build, or Otto's own daemon. With swap, the server pages out memory it has not used lately and carries on, slower. Otto stops starting new sessions while the server is short of memory (its 1.5 GB memory floor counts RAM only, never swap), so the slow spell passes as the busy sessions finish.

A server you moved with server-move.sh after this change got its swap during the import, and needs none of this. A deploy says this server has no swap when yours has none.

The script makes these choices, each of which you can change:

It needs the swap's size plus 10 GB of free disk. Below, replace SERVER with the name your Mac uses to SSH to your Otto server.

Steps

  1. See what it would do

    ssh SERVER
    sudo bash /opt/otto/deploy/session-host/swap.sh --dry-run

    It prints the size it chose for the server's RAM and each change it would make. If swap is on already, for example a partition your provider set up, it adds no file and only sets the swappiness.

  2. Add the swap

    sudo bash /opt/otto/deploy/session-host/swap.sh

    For another size, add --size <GB>; for another swappiness, --swappiness <0–100>. Nothing needs to stop: the sessions keep running.

  3. Check it

    swapon --show
    cat /proc/sys/vm/swappiness

    /swapfile is listed with its size, and the swappiness is 10. In Otto, Settings → Session hosts now shows a Swap meter for the server.

You're done. Running the script again changes nothing; it says what is already in place.

Resize the swap file

The script never resizes a swap file that is on: switching it off moves everything in it back to RAM, which fails when memory is short. When the Swap meter shows little use:

sudo swapoff /swapfile && sudo rm /swapfile
sudo bash /opt/otto/deploy/session-host/swap.sh --size 4

If it fails

Remove the swap

sudo swapoff /swapfile && sudo rm /swapfile
sudo sed -i '\#^/swapfile #d' /etc/fstab
sudo rm /etc/sysctl.d/99-otto-swap.conf && sudo sysctl -w vm.swappiness=60