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 8 of 9 · lab · 20 minmedium

A build runs out of memory

The nightly search index build fails for lack of memory, and it cannot be given more RAM. Give the machine a swap file that survives a reboot and set how readily the system uses it.

Situation

Every night the lab-build.timer timer starts the search index build of the docs site — the lab-build service. The build is given 192 MiB of RAM: the site and the database need the rest. There are more pages now, and the index has not been updated for several nights in a row. The build can be started in the daytime too: sudo systemctl start lab-build.

The build cannot be given more RAM. The decision is to give the machine swap: whatever does not fit into 192 MiB goes to the disk — the build runs slower, but it finishes.

Task

  1. The swap is a file of exactly 512 MiB, and it is on. Process memory ends up in swap, so only root may read and write the file (mode 600).
  2. After a reboot the swap comes on by itself, and the swap lines in /etc/fstab cause no errors at boot.
  3. The system is reluctant to send memory to swap: vm.swappiness = 10 now and after a reboot, and the setting is written as a file in /etc/sysctl.d.
  4. The sudo systemctl start lab-build build passes — the check will start it itself. Do not change the build unit or its memory limit.

The machine has no internet access; the programs you need are already installed.

Lab · on your own

No commands are given in this lab: type them in the terminal yourself. Goals are checked on the machine after every command.

Goals

0 of 4
  • A swap file of exactly 512 MiB is on, owned by root with mode 600 — not done yet
  • The swap file is listed in /etc/fstab, and there are no swap lines for files that do not exist — not done yet
  • vm.swappiness = 10 now and after a reboot, from a file in /etc/sysctl.d — not done yet
  • The nightly lab-build build passes within the same 192 MiB memory limit — not done yet
Ctrl+Enter
Starts the machine node1 · Ubuntu 24.04

The machine is starting

Hints

0 of 3

Lab goals

0 of 4
  • A swap file of exactly 512 MiB is on, owned by root with mode 600 — not done yet
  • The swap file is listed in /etc/fstab, and there are no swap lines for files that do not exist — not done yet
  • vm.swappiness = 10 now and after a reboot, from a file in /etc/sysctl.d — not done yet
  • The nightly lab-build build passes within the same 192 MiB memory limit — not done yet
node1 Ubuntu 24.04

Lab goals

0 of 4
  • A swap file of exactly 512 MiB is on, owned by root with mode 600 — not done yet
  • The swap file is listed in /etc/fstab, and there are no swap lines for files that do not exist — not done yet
  • vm.swappiness = 10 now and after a reboot, from a file in /etc/sysctl.d — not done yet
  • The nightly lab-build build passes within the same 192 MiB memory limit — not done yet
Loading…