Lab 13.1 Invoking the OOM Killer
Good afternoon,
Lab 13.1 has you turn off swap and then run stress-ng -m 12 -t 10s to fill your memory and invoke the OOM killer. I tried this on an antiX VM with 3 gb of memory and monitored dmesg, /var/log/messages, and /var/log/syslog and could see stress-ng run, but I don't see anything about an OOM Killer being called or any processes being stopped. What should I see?
Lab Text:
You should see the OOM (Out of Memory) killer swoop in and try to kill processes in a struggle to stay alive. You can see what is going on by running dmesg or monitoring /var/log/messages or /var/log/syslog, or through graphical interfaces that expose the system logs.
Who gets clobbered first?
Thanks in advance!
Comments
-
Hello rroberts,
in order to see what's going on, I used two terminals. In one of them I ran:
free -s 1 -h
which shows you, how big you memory is and how much is used/free. With
-s 1
it updates every second.In the second terminal I ran:
stress -m 12 -t 10
I did that in Arch Linux, therefore
stress
, but I thinkstress-ng
pretty much does the same.Now (in the frist terminal) I could observe how the free part of the memory shrinks while stress runs.
-m 12
didn't stress my system enough to invoke the OOM killer. So I increased the passed in number (at the end to 40). At that pointstress
tried to allocate so much memory, that the OOM killer kicked in and killed the process. Afterwards I ran dmesg and the last few lines looked like this:[ 767.925606] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/user.slice/user-1000.slice/session-1.scope,task=stress,pid=1433,uid=1000 [ 767.925620] Out of memory: Killed process 1433 (stress) total-vm:265804kB, anon-rss:222856kB, file-rss:0kB, shmem-rss:0kB, UID:1000 pgtables:496kB oom_score_adj:0 [ 767.973170] oom_reaper: reaped process 1433 (stress), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB
It tells you that the OOM killer killed the stress process.
Well, I hope that helps.
0 -
Weird. I ran it on both my antiX and OpenSUSE vms and even at -m 8000 I could never get it to even make a dent in the memory. I tried it on my actual pc after that and got the OOM Killer to fire, so I'm wondering if VirtualBox doesn't have some safeguards in place or something.
Anyway, thanks for the feedback! I didn't even know what I was supposed to be looking for.
0 -
I confess I don't know much about "antiX linux" as it is not one we support for this course, although I don't see why it would matter.
As an alternative to using stress trying using the attached "C" program, lab_wastemem.c, after compiling it as
gcc -o lab_wastemem lab_wastemem.c
and then run it as in./lab_wastemem 8096
, which would waste 8 GM of memory. (Put in a number high enough to run out of memory) If you put in way too much it may not even run. It will terminate itself after a while no matter what. In another window I recommend running gnome-system-monitor and watching the memory usage. (It will also be easier to trigger if you do "sudo swapoff -a
" first.)This tool does only the memory stress and is simpler than stress. We used to give it out, but too many students had to be walked through compiling and running the program so there was signal/noise ratio problems.
(sorry this software doesn't allow me to attach a C language file for some reason. So you will have to cut and paste it.
Watch out for underscores etc if you have a dumb browser and/or editor etc.)/* simple program to defragment memory, J. Cooperstein 2/04
*/include <stdio.h>
include <stdlib.h>
include <unistd.h>
include <string.h>
include <sys/sysinfo.h>
include <signal.h>
define MB (1024*1024)
define BS 16 /* will allocate BS*MB at each step */
define CHUNK (MB*BS)
define QUIT_TIME 20
void quit_on_timeout(int sig)
{
printf("\n\nTime expired, quitting\n");
exit(EXIT_SUCCESS);
}int main(int argc, char **argv)
{
struct sysinfo si;
int j, m;
char *c;/* get total memory on the system */ sysinfo(&si); m = si.totalram / MB; printf("Total System Memory in MB = %d MB\n", m); m = (9 * m) / 10; /* drop 10 percent */ printf("Using somewhat less: %d MB\n", m); if (argc == 2) { m = atoi(argv[1]); printf("Choosing instead mem = %d MB\n", m); } signal(SIGALRM, quit_on_timeout); printf("Will quite in QUIT_TIME seconds if no normal termination\n"); alarm(QUIT_TIME); for (j = 0; j <= m; j += BS) { /* yes we know this is a memory leak, no free, * that's the idea! */ c = malloc(CHUNK); /* just fill the block with j over and over */ memset(c, j, CHUNK); printf("%8d", j); fflush(stdout); } printf("\n\n Quitting and releasing memory\n"); exit(EXIT_SUCCESS);
}
1 -
Hi @rroberts ,
How about the following commands?
stress-ng --vm 1 --vm-bytes 2g -t 60s
stress-ng --vm 1 --vm-bytes 4g -t 60s
stress-ng --vm 1 --vm-bytes 100% -t 60s
I don't think VirtualBox is playing an important role here (it works on my Ubuntu 18.04 vm).
Regards,
Luis.0 -
Thanks for the feedback, guys. These suggestions worked on both VMs and got the available memory down to 75mb, but neither antiX or OpenSUSE fired off the OOM Killer. I did get the OOM Killer to work on my non-VM Fedora setup, so I'm not really concerned about it at this point.
0 -
Hi @rroberts ,
If you want to take a look to how memory is managed on *SUSE, you can take a look to the following documentation:
Overcommit Memory in SLES
https://www.suse.com/support/kb/doc/?id=000016945
Regards,
Luis.0 -
I also could not get the OOM Killer to work on a Fedora Digital Ocean server.
The free memory dropped down to 75MB and then recovered. There was nothing in dmesg about it.
When I ran the c program provided above I got the oom_reaper to appear in dmesg.
0 -
I don't know why stress-ng should behave differently than the simple C program. I hope you are all turning off swap before doing this exercise (as in
sudo swapoff -a
) as otherwise triggering can be very slow if not impossible.1 -
It seems there is a difference between "stress" and "stress-ng" , looks like they fixed "stress-ng" to process the mmap failure instead of letting it fail. See attached:
0 -
Indeed Lab 13.1 command should be updated as it is not working as described..
Using Ubuntu 20.04 LTS on Virtual Box with 4GB RAM, I could invoke OOM only using similar command as shared by Luis (using vm-bytes option with 100% for at least 20 sec)Here below some extract of /var/log/syslog.
Stress-ng process gets killed having the highest oom_scoreubuntu stress-ng: invoked with 'stress-n' by user 1000
ubuntu stress-ng: system: 'ubuntu' Linux 5.8.0-49-generic #55~20.04.1-Ubuntu SMP Fri Mar 26 01:01:07 UTC 2021 x86_64
ubuntu stress-ng: memory (MB): total 3935.66, free 2870.41, shared 26.48, buffer 4.44, swap 0.00, free swap 0.00
ubuntu kernel: [ 1615.497838]** free invoked oom-killer**: gfp_mask=0x100cca(GFP_HIGHUSER_MOVABLE), order=0, oom_score_adj=0
ubuntu kernel: [ 1615.497843] CPU: 1 PID: 4065 Comm: free Tainted: G OE 5.8.0-49-generic #55~20.04.1-Ubuntu
ubuntu kernel: [ 1615.497845] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
(...)ubuntu kernel: [ 1615.498328] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/user.slice/user-1000.slice/user@1000.service,task=stress-ng,pid=4072,uid=1000
ubuntu kernel: [ 1615.498340] **Out of memory: Killed process 4072 (stress-ng) **total-vm:2966460kB, anon-rss:2929204kB, file-rss:0kB, shmem-rss:32kB, UID:1000 pgtables:5800kB oom_score_adj:1000
ubuntu kernel: [ 1615.533143] oom_reaper: reaped process 4072 (stress-ng), now anon-rss:0kB, file-rss:0kB, shmem-rss:32kB0 -
Exactly how systems respond to OOM situations depends on quite a few variables including:
- Linux Distribution
- Kernel Version (including distro customizations)
- Physical Machine? or Virtual, and if so which hypervisor and version and host OS
- Actual RAM available
- How much swap
- How the condition is triggered. (last but not least)
Trying to account for all these variations with a one line command is just whack-a-mole; any fix will break something else. As long as you triggered the OOM killer I could not care less how.
Once upon a time the OOM killer was so naiive it always killed X as the guilty programs were generally running under X on workstations. It is smarter today!
0
Categories
- All Categories
- 167 LFX Mentorship
- 219 LFX Mentorship: Linux Kernel
- 795 Linux Foundation IT Professional Programs
- 355 Cloud Engineer IT Professional Program
- 179 Advanced Cloud Engineer IT Professional Program
- 82 DevOps Engineer IT Professional Program
- 127 Cloud Native Developer IT Professional Program
- 112 Express Training Courses
- 112 Express Courses - Discussion Forum
- 6.2K Training Courses
- 48 LFC110 Class Forum - Discontinued
- 17 LFC131 Class Forum
- 35 LFD102 Class Forum
- 227 LFD103 Class Forum
- 14 LFD110 Class Forum
- 39 LFD121 Class Forum
- 15 LFD133 Class Forum
- 7 LFD134 Class Forum
- 17 LFD137 Class Forum
- 63 LFD201 Class Forum
- 3 LFD210 Class Forum
- 5 LFD210-CN Class Forum
- 2 LFD213 Class Forum - Discontinued
- 128 LFD232 Class Forum - Discontinued
- 1 LFD233 Class Forum
- 2 LFD237 Class Forum
- 23 LFD254 Class Forum
- 697 LFD259 Class Forum
- 109 LFD272 Class Forum
- 3 LFD272-JP クラス フォーラム
- 10 LFD273 Class Forum
- 152 LFS101 Class Forum
- 1 LFS111 Class Forum
- 1 LFS112 Class Forum
- 1 LFS116 Class Forum
- 1 LFS118 Class Forum
- LFS120 Class Forum
- 7 LFS142 Class Forum
- 7 LFS144 Class Forum
- 3 LFS145 Class Forum
- 1 LFS146 Class Forum
- 3 LFS147 Class Forum
- 1 LFS148 Class Forum
- 15 LFS151 Class Forum
- 1 LFS157 Class Forum
- 33 LFS158 Class Forum
- 8 LFS162 Class Forum
- 1 LFS166 Class Forum
- 1 LFS167 Class Forum
- 3 LFS170 Class Forum
- 2 LFS171 Class Forum
- 1 LFS178 Class Forum
- 1 LFS180 Class Forum
- 1 LFS182 Class Forum
- 1 LFS183 Class Forum
- 29 LFS200 Class Forum
- 736 LFS201 Class Forum - Discontinued
- 2 LFS201-JP クラス フォーラム
- 14 LFS203 Class Forum
- 102 LFS207 Class Forum
- 1 LFS207-DE-Klassenforum
- 1 LFS207-JP クラス フォーラム
- 301 LFS211 Class Forum
- 55 LFS216 Class Forum
- 48 LFS241 Class Forum
- 42 LFS242 Class Forum
- 37 LFS243 Class Forum
- 15 LFS244 Class Forum
- LFS245 Class Forum
- LFS246 Class Forum
- 50 LFS250 Class Forum
- 1 LFS250-JP クラス フォーラム
- LFS251 Class Forum
- 154 LFS253 Class Forum
- LFS254 Class Forum
- LFS255 Class Forum
- 5 LFS256 Class Forum
- 1 LFS257 Class Forum
- 1.3K LFS258 Class Forum
- 10 LFS258-JP クラス フォーラム
- 111 LFS260 Class Forum
- 159 LFS261 Class Forum
- 41 LFS262 Class Forum
- 82 LFS263 Class Forum - Discontinued
- 15 LFS264 Class Forum - Discontinued
- 11 LFS266 Class Forum - Discontinued
- 20 LFS267 Class Forum
- 24 LFS268 Class Forum
- 29 LFS269 Class Forum
- 1 LFS270 Class Forum
- 199 LFS272 Class Forum
- 1 LFS272-JP クラス フォーラム
- LFS274 Class Forum
- 3 LFS281 Class Forum
- 9 LFW111 Class Forum
- 260 LFW211 Class Forum
- 182 LFW212 Class Forum
- 13 SKF100 Class Forum
- 1 SKF200 Class Forum
- 1 SKF201 Class Forum
- 782 Hardware
- 198 Drivers
- 68 I/O Devices
- 37 Monitors
- 96 Multimedia
- 174 Networking
- 91 Printers & Scanners
- 83 Storage
- 743 Linux Distributions
- 80 Debian
- 67 Fedora
- 15 Linux Mint
- 13 Mageia
- 23 openSUSE
- 143 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 348 Ubuntu
- 461 Linux System Administration
- 39 Cloud Computing
- 70 Command Line/Scripting
- Github systems admin projects
- 90 Linux Security
- 77 Network Management
- 101 System Management
- 46 Web Management
- 64 Mobile Computing
- 17 Android
- 34 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 371 Off Topic
- 114 Introductions
- 174 Small Talk
- 19 Study Material
- 507 Programming and Development
- 285 Kernel Development
- 204 Software Development
- 1.8K Software
- 211 Applications
- 180 Command Line
- 3 Compiling/Installing
- 405 Games
- 309 Installation
- 97 All In Program
- 97 All In Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)