Linux Labs

Inside the system: resources, kernel, processes / Stage 2 of 12

Memory, swap and the OOM killer

Not running Starting usually ~20 s
Leave the lesson

Step 2 of 9 · on a machine · 6 min

Used and available

free showed tens of free mebibytes on the machine and about 300 available. Find out which of the numbers is the memory reserve.

free -h prints memory in readable units: Mi for mebibytes, Gi for gibibytes. The Mem line has two similar columns — free and available, and in the first exercise they differed several times over. See how they change when the machine reads a large file from the disk.

Exercise · look

Read a large file

Look at the machine's memory, then read the 150 MiB log /var/log/lab-archive/access.log and look at the memory again.

First, predict

You are about to read a 150 MiB file. What will happen to the available column?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in

The columns of the Mem line:

Column What it holds
total all the memory the kernel manages
used taken by processes and the kernel
free not used for anything
buff/cache file cache: what was recently read and written
available how much can be given to processes without swap

The kernel does not keep memory empty. Everything read from the disk stays in the page cache so that the next read of the same file does not go to the disk. That is why free is small on a working server, and that is fine: when a process needs memory, the kernel drops the cache. You read a 150 MiB file, and free went down by as much, while available barely changed: the cache counts as available memory.

The memory reserve is shown by available — the same number as the MemAvailable line in /proc/meminfo. On the lesson machine it is about 300 MiB out of 458.

Check yourself 1 question

On a server with 4 GiB, free -h shows: free 40Mi, buff/cache 2.1Gi, available 2.3Gi. A colleague wants to add memory urgently. What do you say?

  • A small free is normal on a working server: the files it has read sit in the cache. The reserve is shown by available — 2.3 GiB.

  • free will grow, but the next reads will go to the disk and get slower. available will barely change — the reserve does not grow.

The memory reserve is available: it includes free memory and the cache the kernel drops when processes need memory. 2.3 GiB out of 4 is more than half.

Ubuntu 24.04
Loading…