<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Out of Memory on RESEARCHUT</title><link>https://researchut.com/tags/out-of-memory/</link><description>Recent content in Out of Memory on RESEARCHUT</description><generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>rrs@researchut.com (Ritesh Raj Sarraf)</managingEditor><webMaster>rrs@researchut.com (Ritesh Raj Sarraf)</webMaster><lastBuildDate>Tue, 26 Aug 2008 06:58:00 -0400</lastBuildDate><atom:link href="https://researchut.com/tags/out-of-memory/index.xml" rel="self" type="application/rss+xml"/><item><title>Linux OOM</title><link>https://researchut.com/post/42/</link><pubDate>Tue, 26 Aug 2008 06:58:00 -0400</pubDate><author>rrs@researchut.com (Ritesh Raj Sarraf)</author><guid>https://researchut.com/post/42/</guid><description>&lt;p>I&amp;rsquo;ve been working on a bug recently related to udev which under certain
circumstances triggers an OOM on the Linux kernel. On another bug, I also
wanted to look for the max open processes for a single file. The results I
found and pretty good. The Linux Kernel&amp;rsquo;s OOM feature has imporved a lot.&lt;/p>
&lt;blockquote>
&lt;p>This is the one liner used to trigger the OOM.&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;/blockquote>
&lt;blockquote>
&lt;p>while true; do tail -f /tmp/test.txt &amp;amp; x=&lt;code>expr $x + 1&lt;/code>; echo $x; done&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;/blockquote>
&lt;blockquote>
&lt;p>And here&amp;rsquo;s the trigger.&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;/blockquote>
&lt;blockquote>
&lt;p>[ 3007.922390] bash invoked oom-killer: gfp_mask=0xd0, order=1, oomkilladj=0&lt;br>
[ 3007.922404] Pid: 8527, comm: bash Tainted: P 2.6.26-1-686 #1&lt;br>
[ 3007.922435] [&lt;!-- raw HTML omitted -->] oom_kill_process+0x4f/0x195&lt;br>
[ 3007.922481] [&lt;!-- raw HTML omitted -->] out_of_memory+0x14e/0x17f&lt;br>
[ 3007.922523] [&lt;!-- raw HTML omitted -->] __alloc_pages_internal+0x2c2/0x358&lt;br>
[ 3007.922567] [&lt;!-- raw HTML omitted -->] __alloc_pages+0x7/0x9&lt;br>
[ 3007.922581] [&lt;!-- raw HTML omitted -->] __get_free_pages+0xf/0x1b&lt;br>
[ 3007.922589] [&lt;!-- raw HTML omitted -->] copy_process+0x9c/0xf5b&lt;br>
[ 3007.922625] [&lt;!-- raw HTML omitted -->] do_fork+0xab/0x1dc&lt;br>
[ 3007.922647] [&lt;!-- raw HTML omitted -->] do_pipe+0x7e/0xbd&lt;br>
[ 3007.922674] [&lt;!-- raw HTML omitted -->] sys_clone+0x22/0x26&lt;br>
[ 3007.922691] [&lt;!-- raw HTML omitted -->] sysenter_past_esp+0x78/0xb1&lt;br>
[ 3007.922721] [&lt;!-- raw HTML omitted -->] serial_pnp_probe+0xde/0x16b&lt;br>
[ 3007.922748] =======================&lt;br>
[ 3007.922752] Mem-info:&lt;br>
[ 3007.922756] DMA per-cpu:&lt;br>
[ 3007.922760] CPU 0: hi: 0, btch: 1 usd: 0&lt;br>
[ 3007.922764] CPU 1: hi: 0, btch: 1 usd: 0&lt;br>
[ 3007.922768] Normal per-cpu:&lt;br>
[ 3007.922772] CPU 0: hi: 186, btch: 31 usd: 31&lt;br>
[ 3007.922777] CPU 1: hi: 186, btch: 31 usd: 0&lt;br>
[ 3007.922780] HighMem per-cpu:&lt;br>
[ 3007.922784] CPU 0: hi: 186, btch: 31 usd: 11&lt;br>
[ 3007.922789] CPU 1: hi: 186, btch: 31 usd: 0&lt;br>
[ 3007.922796] Active:136180 inactive:157488 dirty:38 writeback:8781
unstable:0&lt;br>
[ 3007.922798] free:75091 slab:32605 mapped:19662 pagetables:63330
bounce:0&lt;br>
[ 3007.922806] DMA free:3564kB min:68kB low:84kB high:100kB active:0kB
inactive:20kB present:16256kB pages_scanned:0 all_unreclaimable? no&lt;br>
[ 3007.922812] lowmem_reserve[]: 0 873 2014 2014&lt;br>
[ 3007.922824] Normal free:272588kB min:3744kB low:4680kB high:5616kB
active:428kB inactive:35148kB present:894080kB pages_scanned:289
all_unreclaimable? no&lt;br>
[ 3007.922830] lowmem_reserve[]: 0 0 9132 9132&lt;br>
[ 3007.922842] HighMem free:24212kB min:512kB low:1736kB high:2960kB
active:544292kB inactive:594784kB present:1168980kB pages_scanned:0
all_unreclaimable? no&lt;br>
[ 3007.922848] lowmem_reserve[]: 0 0 0 0&lt;br>
[ 3007.922856] DMA: 9&lt;em>4kB 141&lt;/em>8kB 2&lt;em>16kB 0&lt;/em>32kB 1&lt;em>64kB 0&lt;/em>128kB 1&lt;em>256kB
0&lt;/em>512kB 0&lt;em>1024kB 1&lt;/em>2048kB 0&lt;em>4096kB = 3564kB&lt;br>
[ 3007.922876] Normal: 67737&lt;/em>4kB 1&lt;em>8kB 1&lt;/em>16kB 0&lt;em>32kB 1&lt;/em>64kB 0&lt;em>128kB 0&lt;/em>256kB
1&lt;em>512kB 1&lt;/em>1024kB 0&lt;em>2048kB 0&lt;/em>4096kB = 272572kB&lt;br>
[ 3007.922896] HighMem: 4157&lt;em>4kB 652&lt;/em>8kB 36&lt;em>16kB 7&lt;/em>32kB 3&lt;em>64kB 1&lt;/em>128kB
1&lt;em>256kB 0&lt;/em>512kB 1&lt;em>1024kB 0&lt;/em>2048kB 0*4096kB = 24244kB&lt;br>
[ 3007.922916] 84292 total pagecache pages&lt;br>
[ 3007.922921] Swap cache: add 141567, delete 78660, find 134588/141329&lt;br>
[ 3007.922926] Free swap = 1755340kB&lt;br>
[ 3007.922929] Total swap = 2252792kB&lt;br>
[ 3007.940403] 523923 pages of RAM&lt;br>
[ 3007.940403] 294547 pages of HIGHMEM&lt;br>
[ 3007.940403] 5172 reserved pages&lt;br>
[ 3007.940403] 1512373 pages shared&lt;br>
[ 3007.940403] 62907 pages swap cached&lt;br>
[ 3007.940403] 38 pages dirty&lt;br>
[ 3007.940403] 8781 pages writeback&lt;br>
[ 3007.940403] 19662 pages mapped&lt;br>
[ 3007.940403] 32605 pages slab&lt;br>
[ 3007.940403] 63330 pages pagetables&lt;br>
[ 3007.940403] Out of memory: kill process 8527 (bash) score 2382580 or a
child&lt;br>
[ 3007.940403] Killed process 9674 (tail)&lt;/p>
&lt;/blockquote>
&lt;p>There were many more such OOM kills triggered and all were for the correct
culprint, the tail program. Awesome. Long long back, when OOM used to be
triggered, it wasn&amp;rsquo;t effecient enough in selecting the processes that it&amp;rsquo;d
like to kill. Things are really better now. I ran this whole test on my laptop
with KDE4 running, and nothing broke. A CTRL + C soon returned back to normal.&lt;/p>
&lt;p>One interesting observation was the following.&lt;/p>
&lt;blockquote>
&lt;p>rrs@learner:~$ ulimit -a&lt;br>
core file size (blocks, -c) 0&lt;br>
data seg size (kbytes, -d) unlimited&lt;br>
scheduling priority (-e) 0&lt;br>
file size (blocks, -f) unlimited&lt;br>
pending signals (-i) 16372&lt;br>
max locked memory (kbytes, -l) 32&lt;br>
max memory size (kbytes, -m) unlimited&lt;br>
open files (-n) 1024&lt;br>
pipe size (512 bytes, -p) 8&lt;br>
POSIX message queues (bytes, -q) 819200&lt;br>
real-time priority (-r) 0&lt;br>
stack size (kbytes, -s) 8192&lt;br>
cpu time (seconds, -t) unlimited&lt;br>
max user processes (-u) 16372&lt;br>
virtual memory (kbytes, -v) unlimited&lt;br>
file locks (-x) unlimited&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;/blockquote>
&lt;blockquote>
&lt;p>My understanding has been that &amp;ldquo;open files&amp;rdquo; is the max the user can open.
Here&amp;rsquo;s the relevant detail.&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;/blockquote>
&lt;blockquote>
&lt;p>-n The maximum number of open file descriptors (most systems do not
allow this value to be set)&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;/blockquote>
&lt;blockquote>
&lt;p>With the above in mind, look at this:&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;/blockquote>
&lt;blockquote>
&lt;p>rrs@learner:/tmp$ lsof /tmp/test.txt | wc -l&lt;br>
12503&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;/blockquote>
&lt;blockquote>
&lt;p>Here&amp;rsquo;s the relevant trace for the tail program.&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;/blockquote>
&lt;blockquote>
&lt;p>open(&amp;quot;/tmp/test.txt&amp;quot;, O_RDONLY|O_LARGEFILE) = 3&lt;br>
fstat64(3, {st_mode=S_IFREG|0644, st_size=18, &amp;hellip;}) = 0&lt;br>
_llseek(3, 0, [0], SEEK_CUR) = 0&lt;br>
_llseek(3, 0, [18], SEEK_END) = 0&lt;br>
_llseek(3, 0, [0], SEEK_SET) = 0&lt;br>
read(3, &amp;ldquo;Ritesh Raj Sarraf\n&amp;rdquo;&amp;hellip;, 18) = 18&lt;br>
_llseek(3, 0, [0], SEEK_SET) = 0&lt;br>
read(3, &amp;ldquo;Ritesh Raj Sarraf\n&amp;rdquo;&amp;hellip;, 18) = 18&lt;br>
fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 2), &amp;hellip;}) = 0&lt;br>
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0xb7f58000&lt;br>
write(1, &amp;ldquo;Ritesh Raj Sarraf\n&amp;rdquo;&amp;hellip;, 18Ritesh Raj Sarraf&lt;br>
) = 18&lt;br>
fstat64(3, {st_mode=S_IFREG|0644, st_size=18, &amp;hellip;}) = 0&lt;br>
fcntl64(3, F_GETFL) = 0x8000 (flags
O_RDONLY|O_LARGEFILE)&lt;br>
fcntl64(3, F_SETFL, O_RDONLY|O_NONBLOCK|O_LARGEFILE) = 0&lt;br>
fstat64(3, {st_mode=S_IFREG|0644, st_size=18, &amp;hellip;}) = 0&lt;br>
nanosleep({1, 0}, NULL) = 0&lt;br>
fstat64(3, {st_mode=S_IFREG|0644, st_size=18, &amp;hellip;}) = 0&lt;br>
nanosleep({1, 0}, NULL) = 0&lt;br>
fstat64(3, {st_mode=S_IFREG|0644, st_size=18, &amp;hellip;}) = 0&lt;br>
nanosleep({1, 0}, NULL) = 0&lt;br>
fstat64(3, {st_mode=S_IFREG|0644, st_size=18, &amp;hellip;}) = 0&lt;br>
nanosleep({1, 0}, ^C &amp;lt;unfinished &amp;hellip;&amp;gt;&lt;/p>
&lt;/blockquote>
&lt;p>Any ideas why this happens?&lt;/p></description></item></channel></rss>