sudo systemctl set-property <service_name> CPUQuota=30%

10. Regularly Update Your System

cat /proc/sys/vm/swappiness

In this guide, we’ll explore practical methods to reduce RAM and CPU usage on Linux. We’ll cover monitoring tools, process management, kernel tweaks, and system optimization techniques to keep your system running efficiently.

a. Using top Command

htop

  • Press F6 to sort processes by CPU or memory usage.
  • Press F9 to kill a selected process.
htop - Interactive Process Viewer
htop – Interactive Process Viewer

c. Using ps Command

sudo apt install htop [On Debian, Ubuntu and Mint]
sudo dnf install htop [On RHEL/CentOS/Fedora and Rocky/AlmaLinux]
sudo emerge -a sys-apps/htop [On Gentoo Linux]
sudo apk add htop [On Alpine Linux]
sudo pacman -S htop [On Arch Linux]
sudo zypper install htop [On OpenSUSE]
sudo pkg install htop [On FreeBSD]

vm.swappiness=10

The top command provides a real-time view of system processes, including CPU and memory usage.
GRUB_CMDLINE_LINUX_DEFAULT=”zswap.enabled=1″

Have you tried these optimization techniques? Share your experience in the comments below or visit Tecmint.com for more Linux guides and tutorials.
The first step in reducing RAM and CPU usage is identifying which processes are consuming the most resources by utilizing several command-line tools:
To tune or optimize kernel parameters, you need to edit /etc/sysctl.conf file and add the following or adjust parameters to improve system performance.
sudo apt update && sudo apt upgrade # For Debian/Ubuntu
sudo yum update # For CentOS/RHEL

Troubleshooting Tips

  • If a process doesn’t terminate with kill, use kill -9 PID to force-kill it.
  • If zram or zswap doesn’t work, ensure your kernel supports these features.
  • If system performance doesn’t improve, consider upgrading your hardware (e.g., adding more RAM or switching to an SSD).
Conclusion

Zram and Zswap are compressed memory technologies that can reduce RAM usage.

a. Using systemctl Command

Linux uses RAM to cache files and improve performance. However, you can manually clear the cache if needed:
List all enabled services using the systemctl command.
sudo sync; sudo sysctl -w vm.drop_caches=3

sudo update-grub
sudo reboot

9. Limit CPU Usage of Processes

Swappiness controls how often the system uses swap space instead of RAM. A high swappiness value can lead to excessive swapping, slowing down your system.
vm.dirty_background_ratio=5
vm.dirty_ratio=10
vm.min_free_kbytes=65536
kernel.sched_autogroup_enabled=0

pkill process_name

3. Optimize Startup Applications

sudo apt install zram-config
sudo systemctl start zram-config

To manage startup applications:

a. Desktop Environments

To install htop on Linux, use the following appropriate command for your specific Linux distribution.

b. Applications

To check the current swappiness value:

  • Text Editor: Replace LibreOffice with AbiWord or Mousepad.
  • Web Browser: Use Firefox with fewer extensions or switch to lightweight browsers like Midori.
  • File Manager: Replace Nautilus with Thunar or PCManFM.

6. Clear Cache and Buffers

sudo cpulimit -e firefox -l 30

Linux is a powerful and efficient operating system, but high RAM and CPU usage can degrade performance, slow down applications, and even cause system crashes when you’re running a server, workstation, or embedded system, and optimizing resource usage is essential for smooth operation.

7. Optimize Kernel Parameters

systemctl list-unit-files –type=service | grep enabled

Use lightweight applications such as:

8. Reduce Memory Usage with ZRAM

kill PID

sudo nano /etc/sysctl.conf

kill -9 PID

sudo systemctl disable service_name

List Enabled Services
List Enabled Services

b. Using GUI Tools

Replace GNOME or KDE with lighter options like XFCE, LXDE, or MATE.
sudo apt install cpulimit # Debian/Ubuntu
sudo yum install cpulimit # RHEL/CentOS

top

  • Press P to sort processes by CPU usage.
  • Press M to sort processes by memory usage.
  • Look for processes consuming excessive resources and note their Process ID (PID).
Real-Time System Process Monitoring
Real-Time System Process Monitoring

b. Using htop Command

ps aux –sort=-%mem | head # Top memory-consuming processes
ps aux –sort=-%cpu | head # Top CPU-consuming processes

Check Memory Consuming Processes
Check Memory Consuming Processes

2. Kill Unnecessary Processes

sudo sysctl -p

5. Use Lightweight Desktop Alternatives

Heavy desktop environments and applications can strain system resources, so consider switching to lightweight alternatives:

Similar Posts