Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Free Up RAM on Linux: 12 Ways That Actually Work

· 5 min read · Home Tech

In this article
  1. Why Linux Uses So Much RAM
  2. Step 1: See What’s Actually Using Memory
  3. Step 2: Kill or Restart the Usual Suspects
  4. Step 3: Clear Caches and Swap (When You Really Need It)
  5. Step 4: Tune Swappiness to Reduce Disk Thrashing
  6. Step 5: Limit Memory-Hungry Services and Apps
  7. Step 6: Use a Lighter Desktop Environment
  8. Step 7: Consider Zram or Zswap
  9. Step 8: Check for Memory Leaks
  10. Frequently Asked Questions

To improve performance and free up RAM on Linux, you need to identify which processes are consuming memory, stop or restart the heavy ones, and adjust system settings that limit available memory. The most effective methods combine practical process management (like using htop and systemctl) with simple kernel tweaks (like clearing caches and adjusting swappiness).

Why Linux Uses So Much RAM

Linux is designed to use available RAM for caching. When you see high memory usage in a tool like free -h, a large portion is often "buff/cache" — data that the kernel keeps around to speed up disk reads and application startups. This is not wasted memory; it is freed automatically when a running program needs it. However, if you have many background services, a heavy desktop environment, or a misconfigured application, actual used memory can stay high and cause swapping to disk, which slows everything down.

Step 1: See What’s Actually Using Memory

Before killing anything, get a clear picture. Open a terminal and run:

  • free -h — shows total, used, free, and cache memory in human-readable form.
  • htop — interactive process viewer; press F6 to sort by memory (MEM%).
  • ps aux --sort=-%mem — one-shot list of processes sorted by memory usage.

Look at the RES (resident) column in htop — that’s the actual physical RAM a process holds. Ignore VIRT (virtual) because it includes shared libraries and allocated but unused memory.

Step 2: Kill or Restart the Usual Suspects

Common memory hogs on a desktop Linux system include web browsers (especially with many tabs), Electron apps (Slack, Discord, VS Code), and GNOME’s tracker or file indexer. For a single app, use pkill or the system monitor to end it. For a service that restarts automatically, restart it instead:

sudo systemctl restart name-of-service

If a process is stuck and won’t die, use kill -9 (but only after trying a normal kill). For a full desktop freeze, the classic Alt + SysRq + F (or REISUB) can safely reboot without killing the filesystem.

Step 3: Clear Caches and Swap (When You Really Need It)

Linux automatically empties caches when memory is needed, but if you’re about to run a memory-heavy task and want to force it, you can drop caches safely:

sudo sync; echo 3 | sudo tee /proc/sys/vm/drop_caches

This writes pending data to disk and then clears page cache, dentries, and inodes. It’s safe — the kernel will just re-read from disk when needed. To clear swap space (forcing everything in swap back into RAM), run sudo swapoff -a then sudo swapon -a. Do this only when you have enough free RAM to hold the swapped data; otherwise, you’ll cause a brief spike in memory pressure.

Step 4: Tune Swappiness to Reduce Disk Thrashing

The vm.swappiness parameter controls how aggressively the kernel moves data from RAM to swap. The default is often 60, which is fine for servers but can cause noticeable lag on desktops. Set it lower so the kernel prefers to keep processes in RAM:

sudo sysctl vm.swappiness=10

To make it permanent, add vm.swappiness=10 to /etc/sysctl.conf or a file in /etc/sysctl.d/. A value of 10–20 is a good starting point for most desktops; 0 disables swap use almost entirely (not recommended unless you have plenty of RAM).

Step 5: Limit Memory-Hungry Services and Apps

Many distributions start services you don’t need. Check what’s running with systemctl list-units --type=service --state=running. For example, if you don’t use Bluetooth, bluetooth.service can be disabled:

sudo systemctl disable --now bluetooth.service

For browsers, use a tab suspender extension or switch to a lighter browser. For Electron apps, run them with the --disable-gpu flag or use a native alternative (e.g., use the web version in a lightweight browser).

Step 6: Use a Lighter Desktop Environment

If you’re on GNOME or KDE Plasma, those environments themselves consume 1–2 GB of RAM. Switching to Xfce, LXQt, or a window manager like i3 can free up a huge amount. You can install a second desktop and choose it at login — no need to reinstall the whole system. For example, on Ubuntu: sudo apt install xubuntu-desktop.

Step 7: Consider Zram or Zswap

Instead of using a swap partition on disk, you can compress memory with zram (a compressed RAM block device) or zswap (a compressed cache in front of a disk swap). This effectively gives you more usable memory by storing compressed pages in RAM. Most modern distros enable zram by default; check with zramctl. If not, install zram-tools (Debian/Ubuntu) or systemd-zram-generator (Fedora/Arch).

Step 8: Check for Memory Leaks

If a process’s memory usage grows over time, it may have a leak. Tools like valgrind or heaptrack can help developers, but as a user, the simplest fix is to restart the app periodically. For system daemons, check if there’s an update — memory leaks are often patched quickly.

Frequently Asked Questions

Is it safe to clear caches with drop_caches?

Yes, dropping caches is safe. The kernel treats it as a hint, not a command, and it will re-read data from disk when needed. You might see a brief slowdown right after, but no data is lost.

Why does my RAM usage go back up after I kill a process?

Because the kernel uses free RAM for caching. If you kill a browser and see memory usage drop, then slowly climb, that’s the kernel caching disk reads and application binaries. It’s not a leak; it’s normal behavior.

Does a lower swappiness value always improve performance?

Not always. If you have very little RAM, keeping everything in RAM can cause OOM (out-of-memory) kills. A value of 10 is a good balance for most desktops, but if you frequently run out of memory, you may need a higher value or more swap.

What’s the difference between buff/cache and used memory?

Used memory is what processes are actively holding. Buff/cache is memory the kernel uses to speed up disk I/O. Cache is reclaimed when a process needs memory, so it’s not counted as "used" in the same way. In free -h, the "available" column shows what can be used without swapping.

Can I add more RAM virtually?

Not really. Zram and swap are not substitutes for physical RAM. They help avoid out-of-memory errors, but they are slower than real RAM. The only real fix is to add more physical memory or reduce the number of running programs.

Should I disable swap entirely?

Only if you have a lot of RAM (16 GB or more) and never run out. Disabling swap can cause OOM kills if you hit a memory spike. It’s usually better to keep a small swap or use zram.