What are some unconventional but very efficient moves to free up RAM on Linux?

There are times that the simple thing as opening a notepad on our Linux becomes like a navigation through quicksand. That’s because the RAM has been used up.

The knee jerk reaction would be to do “swap tweaking” and closing unused tabs. But beyond these generics, are there any other creative way to free up RAM on Linux?

I use the Cron- Fu Shuffle. How this works is that this technique preloads libraries that are commonly used into memory at boot making your apps to start up at a really good speed. A cron job is then used to swap the preloaded libraries determined by the patterns by which you use apps. With this, your RAM usage adapts to the patterns by which you use apps and frees up precious extra RAM.

So what are your unorthodox approach to free up RAM and stop memory leakages? We can all get to learn.

That’s a pretty slick approach with the Cron-Fu Shuffle! Adapting RAM usage to your app patterns is a smart way to optimize.

Here are a few unorthodox methods I can think of:

  1. ZRAM: It’s a Linux kernel feature that provides a form of virtual memory compression. Unused data in RAM is compressed, freeing up space without needing to use swap. It can be especially effective on systems with limited RAM.
  2. EarlyOOM or NoHang: These are daemons that monitor available memory and automatically kill processes to prevent out-of-memory scenarios. They’re more proactive than the OOM killer that’s built into the kernel.
  3. tmpfs Tweaks: If you’re using tmpfs (temporary file storage in RAM), tweaking its size or disabling it for certain mount points can free up RAM. But, this depends on how much you rely on tmpfs.
  4. Profile-guided Optimization: This is more of a developer approach, but recompiling your most used applications with profile-guided optimizations can make them use memory more efficiently.
  5. Cgroups: Using control groups to limit the memory usage of certain processes can prevent them from hogging all your RAM.

What is your setup like?

1 Like

For me, I prefer the approach of a temporary RAM disk. The downside is that data would be lost when system is rebooted but it achieves that simple goal of speeding up access. I use tmpfs with this code:

Bash
sudo mkdir /mnt/ramdisk
sudo mount -t tmpfs -o size=1G tmpfs /mnt/ramdisk

2 Likes

Nice tips everyone! You can also drop the page cache using:

sync; echo 3 > /proc/sys/vm/drop_caches

It clears out cached files, dentries, and inodes from RAM without needing to install anything.

One thing to keep in mind is that cache exists for a reason. After you drop it, the system has to re-read files from disk, so you might notice a temporary slowdown until the cache builds back up.

It’s best used as a quick fix when you really need that RAM back, not something you want running every five minutes. :slight_smile:

To me, systems are reasonably priced these days. If a system requires more resources, get more hardware unless we are really poor or we have way too many other expensive things to deal with - a big house mortgage, children’s education, an overpriced vehicle, etc. maybe cost is a factor. Another way to get around the issues besides the technology solutions that have been suggested in this thread is that if you are low on resources, run fewer things at a time. Hopefully your workload does not have to be reduced to just two or three applications, but if you can’t implement the suggestions here or simply purchase a more capable system, then reducing the number of things you run concurrently (at the same time), that’s the “budget way” to solve this issue!

1 Like