CSE Roadmap

Core tier · about 3 hours · 6 parts

Part 4 of 6 · 2 min read

The whole machine

Think of the dashboard of a car, with a fuel gauge, a speedometer and a temperature light. Each gauge answers one question about the whole car, and none says what is wrong with a part. The analogy stops in one place: a car gauge has a red zone on its dial, and a computer gauge has no marked limit, so you must know what is normal.

In plain words: Four commands give the state of the whole machine. free -m shows memory in megabytes: total, used, free, shared, the cache and the memory available to new programs (Level 7). vmstat prints a line of counters: runnable and blocked processes (r, b), swap in and out, blocks in and out, interrupts and context switches, and the shares of CPU time (user, system, idle, waiting for I/O). df -h shows how full each file system is (Level 9). uptime shows how long the machine has run and three load averages: the average number of runnable and uninterruptible processes over 1, 5 and 15 minutes (Level 3).

A worked example. On the idle test machine:

$ free -m
               total        used        free      shared  buff/cache   available
Mem:            8024         369        7665          12         202        7654
Swap:              0           0           0

$ vmstat 1 2          (second line)
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 7848920   2672 204828    0    0     0     0   77   71  1  0 100  0  0

$ cat /proc/loadavg
0.00 0.00 0.00 1/100 753

Of 8,024 MiB, 369 are used by programs and 202 by the cache, so 7,654 are available to new programs (a little less than the free memory plus the cache, since some cache cannot be dropped). There is no swap, and si and so are zero. r is 0 runnable processes and wa 0 per cent waiting for I/O, id 100 per cent idle. The load averages are 0.00. The last two fields of /proc/loadavg say "1 of 100 processes is running now, and the newest process ID is 753".

The key lines. These numbers are most useful as a change: compare them with a normal day. A load of 4 is idle for a 16-core machine and a disaster for a 2-core one, so read the load against the number of cores (nproc, here 2).

Load average

The load average is the exponentially smoothed average, over 1, 5 and 15 minutes, of the number of tasks that are running or waiting to run, plus those in uninterruptible sleep (usually waiting for disk). A value equal to the number of cores means that the cores are just full.

Example: a load of 4.0 on a 2-core machine means that about two tasks are waiting for a core at any time.

Check yourself: 1. Which column of free tells how much memory new programs can use? 2. What does wa in vmstat mean? 3. Why compare the load with the number of cores?