Jayjeet Kumar

Jul 28, 2025 • 2 min read

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


🚀 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!


Join Jayjeet on Peerlist!

Join amazing folks like Jayjeet and thousands of other builders on Peerlist.

peerlist.io/

It’s available... this username is available! 😃

Claim your username before it's too late!

This username is already taken, you’re a little late.😐

0

8

0