๐ How I Fixed Performance Issues on 4GB/8GB RAM Linux by Creating Virtual RAM


As a developer working on a low-RAM Linux laptop (4GB or 8GB), I was constantly running into performance issues. Every time I fired up Next.js, opened VSCode, or launched the Brave browser, my system slowed downโor worse, froze entirely. After some digging, I discovered the OOM Killer (Out of Memory Killer) was terminating my apps when RAM ran out.
The fix? I created virtual RAM (a swap file), and it worked like magic.
Hereโs exactly how I did it.
๐ก What is Virtual RAM?
Virtual RAM (or swap memory) uses part of your storage (HDD/SSD) as emergency backup RAM. While itโs much slower than physical RAM, it prevents crashes and keeps your system responsive when memory is tight.
๐ง How to Create Virtual RAM (Swap File) in Linux
This is a one-time setup. Works on any Debian/Ubuntu-based distro.
โ Step 1: Remove existing swap file (if any)
sudo swapoff /swapfile
sudo rm /swapfile
โ Step 2: Create new virtual RAM (choose 4G or 8G)
# For 4GB swap
sudo fallocate -l 4G /swapfile
# Or for 8GB swap
sudo fallocate -l 8G /swapfile
โ ๏ธ If you see โfallocate failed: Text file busyโ, make sure to disable the old swap file first using
sudo swapoff /swapfile
.
โ Step 3: Secure the file
sudo chmod 600 /swapfile
โ Step 4: Format it as swap
sudo mkswap /swapfile
โ Step 5: Enable the swap
sudo swapon /swapfile
โ Step 6: Make it permanent (survives reboot)
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
โ Check if it worked:
swapon --show
free -h
You should now see your swap file listed with the total size (4.0G or 8.0G).
๐ง Bonus Optimization Tips
To make the most of your system:
๐ Close Brave tabs โ each tab can take hundreds of MBs.
๐งน Stop services you donโt need.
๐ Use local static assets instead of heavy external image URLs.
๐ Use
NODE_OPTIONS="--max-old-space-size=4096"
when starting Node.js apps.
๐งช Final Thoughts
With virtual RAM, my Linux laptop now runs smoother, handles Next.js builds without crashing, and doesnโt freeze when I open multiple apps.
It wonโt make your system faster than real RAM, but it prevents those frustrating crashes that kill productivity.
If youโre building on a budget machine, try it. It might just save your workflow like it did mine.
๐ฌ Let me know in the comments if it helped โ or if you have more tips to share!
Subscribe to my newsletter
Read articles from Jayjeet kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Jayjeet kumar
Jayjeet kumar
๐จโ๐ป Frontend Developer | ๐ Exploring Blockchain, Web3, and AI Enthusiast Hey there! ๐ I'm Jayjeet Kumar, a passionate frontend developer with a knack for crafting seamless user experiences. ๐โจ ๐ป Currently honing my skills in the ever-evolving world of frontend development, I've got an insatiable curiosity for cutting-edge technologies. ๐ ๐ Exciting times ahead as I embark on a journey to unravel the mysteries of Blockchain, Web3, and AI. ๐ Eager to merge the worlds of sleek design and innovative tech to create digital experiences that leave a lasting impression. ๐ค Join me as I delve into the realms of artificial intelligence, explore the decentralized wonders of Web3, and decipher the secrets of blockchain technology. ๐๐ก ๐ Always up for a challenge, I'm on a mission to blend creativity with the power of emerging technologies. Let's connect, collaborate, and build the future together! ๐๐จโ๐ป