🚀 Is building a website too difficult? Let me guide you step by step—Learn about the 「Naibabiji WordPress Website Building Coaching Service」 →

Tutorial on Increasing Swap Space in Debian 12

Step 1: Check current swap usage

First, you can check the current swap usage to understand if you need to increase swap space:

swapon --show
free -h

Step 2: Create a new swap file

Choose an appropriate size (e.g., 2GB) and use theddcommand to create a new swap file. Here's an example for 2GB:

sudo fallocate -l 2G /swapfile

Iffallocateis not available, you can use theddcommand:

sudo dd if=/dev/zero of=/swapfile bs=1G count=2

Step 3: Set permissions for the swap file

For security, set the correct permissions so that only the root user can access this file:

sudo chmod 600 /swapfile

Step 4: Format the file as swap space

Next, format the newly created file as swap space:

sudo mkswap /swapfile

Step 5: Enable the swap file

Enable the swap file you just created:

sudo swapon /swapfile

Step 6: Verify the swap space

Check again to verify the swap has been successfully added:

swapon --show
free -h

Step 7: Make the swap file mount automatically after system reboot

To ensure this swap file is automatically mounted on every boot, you need to add it to the/etc/fstabfile. Open that file:

sudo nano /etc/fstab

Add the following line at the end of the file:

/swapfile none swap sw 0 0

Save and exit the editor.

Complete

You have now successfully increased swap space on Debian 12. If you need to adjust the size of the swap, you can delete the existing swap file and repeat the steps above, specifying the desired new size.

After you create and enable the swap file following the steps above, the swap space will take effect immediately. You can verify it with the following command:

swapon --show
free -h

If you see the new swap space displayed in the output, then it has been successfully enabled.

Notes

  • A reboot is only necessary if you modified the /etc/fstab file to ensure the swap file is automatically mounted after a system restart.
  • If you want to temporarily disable the swap file, you can use the following command:sudo swapoff /swapfile
  • To re-enable the swap file, run again:sudo swapon /swapfile

A swap usage of 0% usually indicates that the system is not currently using swap space. There could be several reasons for this:

1. Good Memory Usage

If your system memory (RAM) has sufficient free space, the Linux system typically will not actively use swap space. Based on the information you provided earlier, your system has about 85 MiB of free RAM, which means the system does not need to use swap under normal conditions.

2. Swappiness Setting

Linux uses a parameter called swappiness to decide when to use swap space. The value of this parameter ranges from 0 to 100:

  • A lower value (e.g., 10) makes the system prefer physical memory over swap space.
  • A higher value (e.g., 60 or higher) means the system will use swap space more frequently.

You can view the current swappiness value with the following command:

cat /proc/sys/vm/swappiness

If you want the system to use swap space more aggressively, you can consider setting it to a higher value (e.g., 60). To temporarily change the swappiness value, use the following command:

sudo sysctl vm.swappiness=60

To make the change permanent, edit the /etc/sysctl.conf file and add or modify the following line:

vm.swappiness=60

Then apply the changes:

sudo sysctl -p
3. Light System Load

If your system load is light and you are not running many applications or processes, the system may not need to use swap space at all. In this case, even if you have configured swap space, it will not be used.

4. Applications Not Consuming Much Memory

If the applications you are running have low memory requirements, the system will not use swap space. The system only starts using swap space when memory usage is nearing its limit.

Summary

If you want the system to use swap space, you can try the following:

  1. Increase the system load by running some memory-intensive applications.
  2. Adjust the swappiness parameter to make the system prefer using swap space.

🚀 Still feeling confused after reading the tutorial? Let me guide you step-by-step.

「Naibabiji WordPress Website Building Coaching Service」—From choosing a domain and buying hosting, to installing a Theme and publishing content, I「ll coach you through every step, helping you avoid detours and reach your goal directly.

👉 Learn about the Website Building Coaching Service
🔒

Comments are closed

The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.

×
二维码

Scan QR Code to Follow

AI Website Building Assistant

🤖
Hello! I am the Naibabiji AI Assistant. How can I help you?
Quick Consultation: