Memory Information

Is the server out of memory? Is something leaking? Let's learn to check.

free - Memory Overview

Terminal
$free -h
total used free shared buff/cache available Mem: 7.7Gi 2.1Gi 3.2Gi 256Mi 2.4Gi 5.1Gi Swap: 2.0Gi 0B 2.0Gi

-h for human-readable sizes.

Understanding the Output

ColumnMeaning
totalTotal physical RAM
usedRAM in use by applications
freeCompletely unused RAM
sharedShared memory
buff/cacheMemory used for caching
availableMemory available for new apps

free vs available - The Most Confusing Part

Low free doesn't mean trouble. Linux uses "free" RAM for caching to speed things up.

The available column is what matters - it's free + cache that can be reclaimed.

Think of it this way:

  • free = money in your wallet
  • buff/cache = money in a jar you can easily break open
  • available = total money you can spend right now

The Cache Misconception

Terminal
$free -h
total used free shared buff/cache available Mem: 8Gi 2Gi 1Gi 256Mi 5Gi 5Gi

"Only 1GB free!" - Don't panic. 5GB is available because the cache can be reclaimed.

Linux caches disk reads in unused RAM. When an app needs memory, the cache shrinks. This is efficient, not a problem.

Swap

Swap is disk space used when RAM is full:

Terminal
$free -h | grep Swap
Swap: 2.0Gi 500Mi 1.5Gi
  • Swap usage = 0: Normal, RAM isn't exhausted
  • Swap usage > 0: RAM pressure, might be slow
  • Swap full: Bad - system will be very slow or crash

Swap Usage

High swap usage means your system ran out of RAM. Performance degrades significantly. Either add RAM or reduce memory usage.

/proc/meminfo

For detailed stats:

Terminal
$cat /proc/meminfo | head -10
MemTotal: 8045612 kB MemFree: 3382948 kB MemAvailable: 5367132 kB Buffers: 234567 kB Cached: 2345678 kB SwapCached: 0 kB Active: 2456789 kB Inactive: 1234567 kB

Per-Process Memory

Terminal
$ps aux --sort=-%mem | head -10
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND mysql 1234 2.0 15.2 234567 123456 ? Sl Jan14 10:30 mysqld nginx 1235 0.5 5.1 65432 41234 ? S Jan14 1:20 nginx

Or use top/htop and press M to sort by memory.

RSS vs VSZ

MetricMeaning
RSSResident Set Size - actual RAM used
VSZVirtual Size - total address space

RSS is the "real" memory usage.

Quick Check Script

hljs bash
echo "=== Memory Usage ==="
free -h
echo ""
echo "=== Top Memory Users ==="
ps aux --sort=-%mem | head -5
Knowledge Check

What does it mean if 'free' memory is low but 'available' memory is high?

Quick Reference

CommandShows
free -hMemory overview
free -mMemory in MB
cat /proc/meminfoDetailed stats
ps aux --sort=-%memProcesses by memory
top then MReal-time, sorted by memory

Key Takeaways

  • free -h gives memory overview
  • Check available, not just free
  • buff/cache is reclaimable - not wasted
  • Swap usage > 0 indicates RAM pressure
  • RSS shows actual memory used per process

Next: checking CPU information.