# Configuring swap space

Swap provides overflow memory on disk when physical RAM is exhausted. It prevents out-of-memory crashes but is significantly slower than real RAM.

## Check existing swap

```bash
swapon -s
```

{% hint style="warning" %}
If this shows an active swapfile, swap is already configured — skip to the next section.
{% endhint %}

![Example of enabled swap](https://2741608310-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUuyIBhqHgBAmQaDXz0PX%2Fuploads%2Fgit-blob-e6fddac3c7c298591f2b0f74805beb7395415251%2Fterminal-swap-swapon.png?alt=media)

## Recommended swap size

| Server RAM | Swap size |
| ---------- | --------- |
| 4 -- 16 GB | 8 GB      |
| 16+ GB     | 16 GB     |

{% hint style="info" %}
Swap is not a replacement for physical RAM. If your server constantly uses swap, upgrade memory instead.
{% endhint %}

## Create and enable swap

1. Create an 8 GB swap file:

```bash
sudo fallocate -l 8G /swapfile
```

2. Restrict permissions:

```bash
sudo chmod 600 /swapfile
```

3. Initialize and enable the swap area:

```bash
sudo mkswap /swapfile
sudo swapon /swapfile
```

4. Make swap persistent across reboots:

```bash
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
```

5. Verify swap is active:

```bash
sudo swapon --show
free -h
```

![](https://2741608310-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUuyIBhqHgBAmQaDXz0PX%2Fuploads%2Fgit-blob-804e84ece979d8da8aeee290bd1ac1f5f50f4f02%2Fterminal-swap-show.png?alt=media)

6. Tune swap behavior:

```bash
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
echo 'vm.vfs_cache_pressure=50' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cardano-node-installation.stakepool247.eu/adding-swap-virtual-memory.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
