swap.md

Swap Space

Runners come without swap by default; when a job runs out of memory, one or more processes get terminated by the out-of-memory killer. Adding a swap file lets the kernel page cold memory out to disk, which can carry a job past short memory spikes without moving to a larger shape.

See the Runner Controls overview for how to pass these settings via a profile or labels.

With runner profiles

You can configure swap directly in the profile editor under Advanced Settings.

With runner labels

For label-based runners, automatic swap configuration is not yet supported. Swap can still be enabled manually using container.privileged and container.mount-scratch. The scratch mount is required because Linux does not support activating a swap file on the runner's default overlay-backed filesystem.

/namespace/scratch provides an ephemeral filesystem that can be used for swap.

When using runner labels, request the features with namespace-features and create the swap file in /namespace/scratch.

theme={null}
jobs:
  build:
    runs-on:
      - nscloud-ubuntu-22.04-amd64-4x8-with-features
      - namespace-features:container.privileged=true;container.mount-scratch=true

steps:
      - name: Set up swap
        run: |
          sudo fallocate -l 16G /namespace/scratch/swapfile
          sudo chmod 600 /namespace/scratch/swapfile
          sudo mkswap /namespace/scratch/swapfile
          sudo swapon /namespace/scratch/swapfile

Next steps