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

Jayjeet kumarJayjeet kumar
2 min read

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!

0
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! ๐Ÿš€๐Ÿ‘จโ€๐Ÿ’ป