Linux Basics Lesson 27 of 38
03:12, was it the OOM killer?
10 minutes
Learning goals
- Prove a kill by the OOM killer from the kernel log, without sudo.
- Confirm it from the service's point of view.
- Assess the situation now by memory, not by address space.
- Put the evidence into the ticket, not an impression of it.
The tools from this module are ready, with a few limits on this page. sudo, systemctl and grep are not loaded: sudo and systemctl answer with a hint, and grep with command not found. You do not need them here. journalctl is enough, because lerner is in the group adm. dmesg fails without root, as it does on Debian in general.
On a real server, the usual ways are sudo dmesg | grep -i oom and systemctl status app. Keep them in mind for the day it counts.
Steps
Step 1/4: Get the proof from the kernel log. You are looking for the line in which the kernel names the process it killed. Step 2/4: Now the service's point of view. What does the journal say about app, and with what result did it fail? Step 3/4: And now? First look at the memory, then at the processes, with the biggest user of RAM at the top. Which one is it, and is it dangerous again? Step 4/4: Put the finding into the ticket: exactly the kernel's error line, in ~/finding.txt. Scenario solved
At 03:12 the alarm went off: the app was gone. The early shift started it again at six, and now it is 09:30 and the ticket asks one question: a crash, a failed deploy, or the OOM killer? You are supposed to prove it. A guess will not do.
-
Step 1 done solved before
Get the proof from the kernel log. You are looking for the line in which the kernel names the process it killed.
Hint 1: dmesg is reserved for root here. The journal has the kernel messages too, and you may read it as a member of adm.Hint 2: Type journalctl -k --no-pagerSolution
journalctl -k --no-pagerWhy: There it is: Out of memory: Killed process 4711 (python3). The line before it, python3 invoked oom-killer, names the process that asked for memory at that moment. Exactly what happened at 03:12, in the words of the kernel.
See the solution? You get fewer XP for this scenario.
Start over? The whole scenario goes back to step 1. Your hints stay, XP only comes once.
-
Step 2 done solved before
Now the service's point of view. What does the journal say about app, and with what result did it fail?
Hint 1: journalctl can pick out one service. The option is -u, for unit.Hint 2: Type journalctl -u app --no-pagerSolution
journalctl -u app --no-pagerWhy: systemd says the same as the kernel, independently of it: Failed with result 'oom-kill'. The Started line at 06:02 is the early shift. That rules out a crash of its own and a failed deploy. On a real server, systemctl status app would show you this result as well.
See the solution? You get fewer XP for this scenario.
Start over? The whole scenario goes back to step 1. Your hints stay, XP only comes once.
-
Step 3 done solved before
And now? First look at the memory, then at the processes, with the biggest user of RAM at the top. Which one is it, and is it dangerous again?
Hint 1: Two commands. free -h first, then ps aux with --sort. A minus in front of the column means the biggest first.Hint 2: Type free -h, then ps aux --sort=-%memSolution
free -h ps aux --sort=-%memWhy: 8.3 GiB are available, so there is no danger right now. But python3 app.py, PID 5120, is at 33 % again, and it will not stop there if it grows the way it did in the night. That is the second half of your finding.
See the solution? You get fewer XP for this scenario.
Start over? The whole scenario goes back to step 1. Your hints stay, XP only comes once.
-
Step 4 done solved before
Put the finding into the ticket: exactly the kernel's error line, in ~/finding.txt.
Hint 1: -p err leaves only the error lines. With > the output goes into a file instead of onto the screen.Hint 2: Type journalctl -k -p err --no-pager > ~/finding.txtSolution
journalctl -k -p err --no-pager > ~/finding.txtWhy: One line that nobody can argue with, with the time, the PID and the size. The whole log would drown it, and a retyped line could always be a typo. The next steps are a memory limit for the service and a look at the app, and those belong to the people who own it.
See the solution? You get fewer XP for this scenario.
Start over? The whole scenario goes back to step 1. Your hints stay, XP only comes once.
Scenario solved
Why each step mattered
- Step 1: There it is: Out of memory: Killed process 4711 (python3). The line before it, python3 invoked oom-killer, names the process that asked for memory at that moment. Exactly what happened at 03:12, in the words of the kernel.
- Step 2: systemd says the same as the kernel, independently of it: Failed with result 'oom-kill'. The Started line at 06:02 is the early shift. That rules out a crash of its own and a failed deploy. On a real server, systemctl status app would show you this result as well.
- Step 3: 8.3 GiB are available, so there is no danger right now. But python3 app.py, PID 5120, is at 33 % again, and it will not stop there if it grows the way it did in the night. That is the second half of your finding.
- Step 4: One line that nobody can argue with, with the time, the PID and the size. The whole log would drown it, and a retyped line could always be a typo. The next steps are a memory limit for the service and a look at the app, and those belong to the people who own it.
Start over? The whole scenario goes back to step 1. Your hints stay, XP only comes once.
Loading terminal …
Esc, then Tab leaves the terminal
Step 1 of 4
Cards
-
Card 1 of 2
Tap the card or press Space to turn it over.
-
Card 2 of 2
Tap the card or press Space to turn it over.
Cheat sheet
The most important command lines of this module on one A4 page, black and white, to print or keep on your phone.
- Download PDF (PDF, 17 KB)
- View as image (PNG, 44 KB)