Step-by-Step Guide to Increasing Swap Memory
Step 1: Check Current Swap Space
Before making any changes, check your current swap space using:
sudo swapon --show
Step 2: Check Available Disk Space
Ensure you have enough free disk space by running:
df -h
Step 3: Create a Swap File
Create a swap file with:
sudo fallocate -l 2G /swapfile
Step 4: Enable the Swap File
Set the correct permissions:
sudo chmod 600 /swapfile
Format the swap file:
sudo mkswap /swapfile
Enable the swap file immediately:
sudo swapon /swapfile
Step 5: Make the Swap File Permanent
Backup your fstab file:
sudo cp /etc/fstab /etc/fstab.bak
Add the swap file to fstab:
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Step 6: Adjust Swappiness and Cache Pressure
Swappiness controls how often your system uses swap space. A lower value (e.g., 10) means the system prefers RAM over swap, while a higher value (e.g., 100) increases swap usage.
Adjust how often the system uses swap space:
sudo sysctl vm.swappiness=10
Cache pressure affects how the system manages cached files. A lower value (e.g., 50) reduces the frequency of cache regeneration.
Improve cache performance:
sudo sysctl vm.vfs_cache_pressure=50
To make Swappiness and Pressure permanent, add lines below at the bottom of /etc/sysctl.conf:
sudo nano /etc/sysctl.conf
# Add lines given below at bottom of /etc/sysctl.conf
vm.swappiness=10
vm.vfs_cache_pressure=50
Save and close the file.
Step 7: Removing Old Swap Files
Remove the entry from fstab and delete the file:
sudo swapoff /path/to/old/swapfile
Conclusion
Increasing swap memory can significantly improve your system’s performance, especially when running memory-intensive applications. Following these steps ensures your system has the resources it needs to run smoothly. Remember to monitor your memory usage and adjust settings as required for optimal performance.
FAQs
Q: What is swap memory?
A: Swap memory is a space on your hard drive that acts as an extension of your RAM.
Q: Why is increasing swap memory important?
A: Increasing swap memory can help prevent system crashes and improve performance when running memory-intensive applications.
Q: How do I monitor my memory usage?
A: You can monitor your memory usage by checking the system’s resource usage or using tools like htop or glances.
Q: Can I increase swap memory on a low-end system?
A: Yes, increasing swap memory can help improve performance on low-end systems, but be cautious not to overdo it, as it may impact overall system performance.

