How to Check CPU and Memory Usage in Linux (Plus Disk)

A slow server is normally short of one resource, rarely all three at once. Four commands pin down which one: lscpu for processor details in Linux, top for live CPU usage, free -h for memory and df -h for disk space. Go through them in that order, and a few minutes later you'll know whether cores, RAM or disk is the bottleneck.
Below you will find the explanation of each command, the meaning of its output, and the cases where the obvious interpretation is wrong.
Which resource is the actual bottleneck?
Start with uptime, free -h, and df -h, and after that, interpret the output to decide which next command to run. If you see high load average and idle CPU, it means there is either disk I/O bottleneck or the hypervisor takes some resources, so top will not be very helpful.
Symptom | Command that confirms it | Typical interpretation |
|---|---|---|
Load average exceeds number of cores with high |
| Many CPU-bound processes; profile your application or provision more cores |
Load average is high with high |
| Disk I/O bottlenecks; discover which processes read/write to disk |
Load average is high with non-zero |
| Hypervisor scheduler steals CPU cycles from VM |
Almost no RAM available |
| Memory bottleneck; system swaps |
Write errors; |
| Full file system or exhausted inodes |
|
| Some process has an open file that has already been deleted |
Go through the above table in the order given. If one of the rows describes your problem, most likely this will be the actual bottleneck; otherwise, trying several options in parallel can be inefficient.
How do I get processor details in Linux?
Run lscpu. This command gives the information about CPU model, number of cores and threads, socket layout, cache sizes, and virtualization flags on one screen. The data is taken from sysfs and /proc/cpuinfo and formatted in human-readable way.
Example:
$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
CPU(s): 8
On-line CPU(s) list: 0-7
Vendor ID: GenuineIntel
Thread(s) per core: 2
Core(s) per socket: 4
Socket(s): 1
Caches (sum of all):
L3: 16 MiBTo get only the number of processing units, you can use nproc. It will print the count as a single number, which is helpful in scripts and for make -j$(nproc).
In addition, you can get raw data directly:
cat /proc/cpuinfo
grep "model name" /proc/cpuinfo | uniqThe file /proc/cpuinfo has a block for each CPU; on multicore systems, the blocks are repeated. uniq can be helpful when the goal is only the model name.
One caveat on virtual machines: what lscpu reports about CPU topology comes from the guest OS configuration, which may differ from the real hardware. According to the lscpu man page, on virtual hardware figures like cores per socket may be inaccurate. Count on the CPU total, and read the socket layout as approximate.
How do I check CPU usage in Linux?
Run top. The second line of the output splits the CPU time into several components; it gives more information than just the total CPU time: us is user processes running time, sy is kernel running time, wa is waiting time for I/O operations, and st is time stolen by the hypervisor.
Example:
$ top
%Cpu(s): 12.4 us, 3.1 sy, 0.0 ni, 82.9 id, 1.4 wa, 0.0 hi, 0.2 si, 0.0 stKey notes in top:
Press
1to view CPU usage per core. If a single-threaded process uses one core of an 8-core machine, it may be seen as 12% CPU on the top line.Process can use more than 100% CPU in the
%CPUcolumn in SMP systems; a multithreaded process uses more than 100% CPU unlesstopis in Threads mode.To get non-interactive CPU usage snapshot, run
ps aux --sort=-%cpu | headto identify top CPU consumers.
The st component deserves special attention. It means the hypervisor steals CPU time from the VM, so you cannot save any CPU time using code optimization. Consistent steal time is a signal of the provider-side problems, not the application ones.
What does the load average actually mean?
The load averages (uptime or 1-, 5-, and 15-minute values in top) show the average number of tasks in the run queue (R state) or waiting for disk I/O (D state). Since I/O wait time is counted here, a high load average does not mean CPU shortage.
Example:
$ uptime
14:22:07 up 31 days, 4:12, 1 user, load average: 6.42, 5.98, 4.11To interpret the load average you need the number of cores from lscpu or nproc. Load average 6.42 on an 8-core server is normal; but the same load average on a 2-core VPS means there are tasks queuing. You need to compare the 1-minute load average with the 15-minute one to understand the trend: if it grows, there is current CPU pressure; if it falls, there is no pressure anymore.
How do I check memory usage in Linux?
Run free -h and look at the available column, not at free. According to the manual page, available means an estimate of memory available for allocation for new processes without swapping, accounting for page cache and for the fact that not all reclaimable slab memory will actually be reclaimed.
Example:
$ free -h
total used free shared buff/cache available
Mem: 15Gi 4.2Gi 412Mi 128Mi 11Gi 10Gi
Swap: 2.0Gi 0B 2.0GiThe important note about free -h: small value of free memory looks alarming, but in most cases it's not a problem because there is much memory available. Most of the free memory is page cache; the kernel will release it quickly if it needs more memory for applications.
used equals total minus available, which means reclaimable cache is already excluded from it. buff/cache is made up of kernel buffers, page cache and reclaimable slab memory. A healthy server that has been up for some time usually shows a big buff/cache figure. That's expected; keep your eye on available.
To see per-process memory usage, use ps aux --sort=-%mem | head or in top RES column (non-swapped physical memory size).
Is the server swapping?
Run vmstat 1 and watch the si and so columns. They show how many pages are swapped in from disk and out to disk each second. A non-zero swpd doesn't necessarily mean trouble, because those pages were swapped out earlier and cost nothing while they stay there. The issue is continuous activity in si and so: it shows the server lacks memory and is paying for it with disk I/O delays.
Example:
$ vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
2 1 51200 421884 182304 2841120 128 256 1840 2210 1420 3180 8 4 76 12 0Some additional tips: r shows the number of runnable processes, b shows the number of processes blocked waiting for I/O. High persistent b and low r indicate I/O bottleneck, not CPU shortage.
How do I check disk usage in Linux?
Run df -h and see which file system is full, and use du to find out the directories responsible. Do not try to do it vice versa because du will traverse all files starting from /, and it takes time.
Example:
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 158G 149G 1.2G 100% /
/dev/vdb1 500G 204G 271G 43% /var/lib/dataNarrowing down, one level at a time:
du -h --max-depth=1 / | sort -h
du -h --max-depth=1 /var | sort -h
du -sh /var/log/*Use -x to limit du to the current filesystem; otherwise, du will traverse other filesystems and network mounts, so the sum will not match the output of df for the specific file system. If your filesystem is too small, consult our guide on partitioning and formatting disk drives in Linux.
If df -h gives available space but writes fail with "No space left on device" error, you need to check inode usage. Using -i parameter in df, you can see inode utilization instead of block one; it is possible that the filesystem exhausted inodes even if blocks are available.
Example:
df -i
du --inodes -d 1 /var | sort -nThe du --inodes parameter shows inode usage statistics, so you can find the directories with many small files (session files or unrotated queue entries).
Why does df report the filesystem full when du disagrees?
The cause is a process that still holds the file open. Deleting the file just drops its directory entry, and its blocks remain allocated until that process closes it. So du, which walks directories, can't see the file anymore, while df keeps counting its blocks. lsof +L1 lists files that are open but deleted.
One fix is to stop and restart the process so its file descriptors close, or to restart the service as a whole (see Red Hat's article). To free the space right away, truncate the log file instead of deleting it: truncation keeps the inode and the file descriptor but releases the blocks.
> /var/log/application.logCommon mistakes
Look at
freeinstead ofavailable, misinterpret the memory situationThink that high load average means CPU shortage; check
waintopbefore adding extra coresForget about
st; high steal time means provider-level contention, not the problem of your applicationRun
dufrom/without-x; it breaks consistency withdfbecause of filesystem crossingDelete the log file that is opened by some process; restart the service to free the space
On a VM, rely on the CPU count; the socket and cores-per-socket figures may be off.
Check the usage only after the problem occurs; these commands are fast and can be periodically logged (via cron)
Frequently asked questions
How do I see how many CPU cores my server has? nproc prints the count as a single number; lscpu gives the same number (CPU(s)) plus threads per core and sockets, so you can understand how many physical cores you have.
What is the difference between /proc/cpuinfo and lscpu? /proc/cpuinfo is the raw kernel file with one block per logical CPU; lscpu is the parsed information from this file and sysfs.
Does a high buff/cache value mean I need more RAM? No; this is mostly page cache and reclaimable slabs; they are freed when the application asks for memory.
What is CPU steal time? It is the time when the hypervisor stole CPU cycles from your VM, reported in top and vmstat as st.
How do I check the size of one directory? Use du -sh /path/to/directory for one human-readable size, or use --max-depth=1 parameter to get per-level breakdown.
Which command should I run first when a server is slow? Start with uptime (load average), then free -h, then df -h. These three commands are fast and will help you to determine the next step (top, vmstat, or du).
Get started with Orbit Servers
Low-latency VPS, bare metal, and colocation across the US, EU, and APAC - provisioned instantly and built for performance-critical workloads.
Get startedRelated products
Written by
Julius
Product Manager
Julius is a product-minded builder who cares about making technology simpler and more useful for the people who rely on it. He’s always looking for ways to improve things, one small step at a time, and enjoys turning good ideas into products that work.