DEV Community

AbdulGoniyy Adeleke Dare
AbdulGoniyy Adeleke Dare

Posted on

🐧 Tech Support Series: Fixing a Slow Linux System

🐒 Is your Linux system dragging its feet?
Maybe it's taking ages to boot, apps freeze mid-task, or even simple commands like ls feel like they’re thinking too hard before responding.

In this Linux-focused guide, I'll walk you through practical troubleshooting steps I used in my IT lab to diagnose and fix a sluggish Linux system. Whether you're a casual tinkerer or a sysadmin-in-training, these tips work across most distros like Ubuntu, Debian, Fedora, and CentOS.

Let’s give your system a boost. πŸ’¨


🧠 Problem Summary

"My Linux server/desktop suddenly became very slow. Boot takes forever, apps freeze, and even typing in the terminal lags."


πŸ” Common Causes of Slowness

  • πŸ” High CPU usage from runaway processes
  • 🧠 Memory leaks or low available RAM
  • πŸ’½ Disk I/O bottlenecks or full partitions
  • βš™οΈ Too many services running in the background
  • 🌐 Network-related delays
  • πŸ”„ Excessive swap usage (swap thrashing)
  • πŸ”₯ Hardware issues (overheating, failing drives)
  • 🐧 Kernel or driver-level bugs

Note: Some tools like iotop, atop, or nethogs may not come pre-installed. Install them with sudo apt install iotop (Debian/Ubuntu) or sudo dnf install iotop (Fedora).


πŸ› οΈ Step-by-Step Troubleshooting

βœ… Step 1: Check System Resources

Start with a high-level overview of system performance:

# Interactive process viewer (better than top)
htop

# Check memory usage
free -h

# Check disk usage
df -h

# System uptime and load average
uptime

# I/O statistics
iostat -x 1
Enter fullscreen mode Exit fullscreen mode

htop showing CPU usage

πŸ” Pro Tip: Load average should typically be below the number of CPU cores. If it's consistently higher, you have a performance bottleneck.

πŸ”§ Fix: If CPU or RAM usage is unusually high, try closing or killing unused applications. If disk usage is nearing 100%, remove large unused files, empty the trash, or resize partitions.


βœ… Step 2: Identify Resource-Heavy Processes

Find which processes are consuming the most resources:

# Top processes by CPU usage
ps aux --sort=-%cpu | head -10

# Top processes by memory usage
ps aux --sort=-%mem | head -10

# Real-time I/O monitoring
iotop

# Network connections and processes
netstat -tulpn
ss -tulpn
Enter fullscreen mode Exit fullscreen mode

Top 10 processes by CPU usage - identify resource-heavy applications

πŸ’‘ Analysis: Look for processes consuming >80% CPU or memory.

πŸ”§ Fix: Kill unnecessary or misbehaving processes using kill -9 [PID]. For persistent issues, investigate misconfigured services or optimise them with nice or cpulimit.


βœ… Step 3: Check Disk Space and I/O

Disk issues are often the culprit for slow systems:

# Detailed disk usage 
du -sh /* | sort -rh | head -10 # Check largest directories

# Check for large files
find / -size +100M -type f 2>/dev/null | head -20

# Monitor disk I/O in real-time
iotop -o

# Check filesystem errors
dmesg | grep -i error

# Check disk health (for physical drives)
smartctl -a /dev/sda
Enter fullscreen mode Exit fullscreen mode

πŸ”§ Fix: Delete old files, empty logs, or move media to external storage. If disk health is questionable, back up data and consider replacing the drive.


βœ… Step 4: Manage Services and Startup Programs

Disable unnecessary services to improve boot time and reduce resource usage:

# List all running services
systemctl list-units --type=service --state=running

# Check which services are enabled at boot
systemctl list-unit-files --type=service --state=enabled

# Disable unnecessary services
sudo systemctl disable [service-name]
sudo systemctl stop [service-name]

# Check boot time
systemd-analyze
systemd-analyze blame
Enter fullscreen mode Exit fullscreen mode

🚫 Warning: Only disable services you're certain aren't needed. Research unfamiliar services before disabling them. (e.g., printing service on a headless server).

πŸ”§ Fix: Use systemd-analyze blame to find services delaying boot. Disable unnecessary ones like Bluetooth, ModemManager, or unattended-upgrades if not needed.

πŸ› οΈ Personal Note: On one system, ModemManager was running by defaultβ€”even though it had no modem.
Disabling it shaved 12 seconds off the boot time.


βœ… Step 5: Clean Up Package Cache and Logs

Free up disk space and reduce clutter:

# For Debian/Ubuntu systems
sudo apt autoremove
sudo apt autoclean
sudo apt clean

# For Red Hat/CentOS/Fedora systems
sudo yum clean all
# or for newer versions
sudo dnf clean all

# Clean old logs
sudo journalctl --vacuum-time=2weeks
sudo find /var/log -name "*.log" -type f -mtime +30 -delete

# Clear temporary files
sudo rm -rf /tmp/*
sudo rm -rf /var/tmp/*
Enter fullscreen mode Exit fullscreen mode

Cleaning logs with journalctl

πŸ’‘ Tip: Automate cleanup with cron jobs or logrotate. It helps maintain disk health and avoids sudden β€œdisk full” issues.

🧠 Personal Note

I once spent hours chasing a slow system only to discover /var/log had ballooned with logs.

Cleaning them up freed disk space and immediately improved performance.

Lesson learned: always check your logs early in the process.


βœ… Step 6: Check Memory and Swap Usage

Memory issues can severely impact performance:

# Detailed memory information
cat /proc/meminfo

# Check swap usage
swapon -s
cat /proc/swaps

# Clear page cache (if safe to do so)
sudo sync && sudo sysctl vm.drop_caches=3

# Monitor memory usage over time
vmstat 1 5
Enter fullscreen mode Exit fullscreen mode

πŸ”§ Swap Analysis: If swap usage is high, consider adding more RAM or optimising memory-hungry applications.
Add swap (fallocate -l 2G /swapfile) or reduce swappiness (vm.swappiness=10) to make Linux prefer RAM over swap.


βœ… Step 7: Analyse System Logs

Check logs for errors or warnings that might indicate problems:

# System logs
sudo journalctl -xe
sudo journalctl -f  # Follow logs in real-time

# Kernel messages
dmesg | tail -50
dmesg | grep -i error

# Check specific log files
sudo tail -f /var/log/syslog
sudo tail -f /var/log/messages
sudo tail -f /var/log/kern.log
Enter fullscreen mode Exit fullscreen mode

πŸ“‹ Sometimes, a single error line in dmesg can explain everything.
πŸ”§ Fix: Match log errors to services or processes. Use systemctl status [service-name] or look up specific errors online. Restart or reconfigure problematic services.


πŸ’» Essential Linux Performance Commands

System Monitoring

# Real-time system monitoring
htop                    # Interactive process viewer
top                     # Basic process viewer
iotop                   # I/O monitoring
nethogs                 # Network usage by process
atop                    # Advanced system monitor
Enter fullscreen mode Exit fullscreen mode

Process Management

# Process information
ps aux                  # All running processes
pstree                  # Process tree
jobs                    # Current shell jobs
nohup [command] &       # Run command in background
kill -9 [PID]          # Force kill process
killall [process-name]  # Kill all instances of a process
Enter fullscreen mode Exit fullscreen mode

Memory and Storage

# Memory analysis
free -h                 # Memory usage summary
cat /proc/meminfo       # Detailed memory info
vmstat 1 5              # Virtual memory statistics
pmap [PID]              # Memory map of process

# Disk analysis
df -h                   # Filesystem usage
du -sh /*               # Directory sizes
lsof +D /path          # Files open in directory
fuser -v /path         # Processes using files
Enter fullscreen mode Exit fullscreen mode

Network Diagnostics

# Network monitoring
ss -tuln                # Socket statistics
netstat -i              # Network interface statistics
iftop                   # Network usage by connection
tcpdump -i eth0         # Packet capture
ping -c 4 google.com    # Network connectivity test
Enter fullscreen mode Exit fullscreen mode

System Information

# Hardware and system info
lscpu                   # CPU information
lsmem                   # Memory information
lsblk                   # Block devices
lsusb                   # USB devices
lspci                   # PCI devices
uname -a                # System information
hostnamectl             # System hostname and OS info
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ Pro Tip: Create aliases for frequently used commands. Add to your ~/.bashrc:

alias ll='ls -la'
alias ..='cd ..'
alias df='df -h'
alias free='free -h'
alias ps='ps aux'
Enter fullscreen mode Exit fullscreen mode

🧼 Prevention and Maintenance Tips

Regular Maintenance

  • Update system regularly: sudo apt update && sudo apt upgrade
  • Monitor disk space: Set up alerts when disk usage exceeds 80%
  • Clean logs periodically: Use logrotate to manage log files
  • Check for hardware issues: Run smartctl tests on drives monthly

System Optimisation

  • Optimise startup: Use systemd-analyze to identify slow boot services
  • Configure swap: Adjust swappiness value based on your use case
  • Tune kernel parameters: Optimise /etc/sysctl.conf for your workload
  • Use monitoring tools: Set up nagios, zabbix, or prometheus for proactive monitoring

Security and Stability

  • Keep minimal services: Only run necessary services
  • Regular security updates: Subscribe to security mailing lists
  • Monitor unusual activity: Check logs for suspicious behavior
  • Backup critical data: Regular backups prevent data loss during troubleshooting

πŸš€ Advanced Troubleshooting

Performance Profiling

# Profile CPU usage
perf top                # Real-time CPU profiling
perf record -g [command]  # Record performance data
perf report             # Analyse recorded data

# Memory profiling
valgrind [command]      # Memory debugging
strace [command]        # System call tracing
Enter fullscreen mode Exit fullscreen mode

Kernel and Hardware Issues

# Check hardware
lshw -short             # Hardware summary
dmidecode               # Hardware details from BIOS
sensors                 # Temperature monitoring
Enter fullscreen mode Exit fullscreen mode

CPU temperature sensors

βœ… Final Thoughts

Linux system performance troubleshooting requires a systematic approach and familiarity with command-line tools. The techniques covered here represent real-world troubleshooting practices used by IT support specialists, system administrators and DevOps engineers daily.

Understanding these tools and techniques not only helps you fix immediate performance issues but also builds valuable skills for system administration, DevOps, and cloud infrastructure management.


What's your go-to Linux command for performance troubleshooting? Share your favourite tools and techniques in the comments!

Follow me for more practical Linux guides and system administration tips. Part of my ongoing journey toward DevOps mastery!

Top comments (0)