<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Xinpeng,</div><div class="gmail_default" style="font-size:small"><br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><span></span><div>[root@test-env-nm05-compute-14e5e72e38 ~]# cat /proc/meminfo</div><div>MemTotal:       526997420 kB</div><div>MemFree:        520224908 kB</div><div><span class="gmail_default" style="font-size:small"></span>MemAvailable:   519936744 kB</div><div>Buffers:               0 kB</div><div>Cached:          2509036 kB</div><div>SwapCached:            0 kB</div><div><span class="gmail_default" style="font-size:small">...</span></div><div>SwapTotal:             0 kB</div><div>SwapFree:              0 kB</div><div><span class="gmail_default" style="font-size:small">...</span></div><div><span class="gmail_default" style="font-size:small"></span>CommitLimit:    263498708 kB</div><div>Committed_AS:   10263760 kB</div></div><div><br></div><div><div>[root@test-env-nm05-compute-14e5e72e38 ~]# cat  /proc/sys/vm/min_free_kbytes</div><div>90112</div></div></blockquote><div><br></div><span class="gmail_default" style="font-size:small">After looking back on this problem</span>, <span class="gmail_default" style="font-size:small">I prefer to think </span><span class="gmail_default" style="font-size:small">the reasons were caused by lower CommitLimit.</span></div><div class="gmail_quote"><span class="gmail_default" style="font-size:small"><br></span></div><div class="gmail_quote"><span class="gmail_default">    </span>CommitLimit:    263498708 kB<span class="gmail_default"> < </span><span class="gmail_default"></span>MemAvailable:   519936744 kB<br></div><div class="gmail_quote"><br></div><div class="gmail_quote"><span class="gmail_default" style="font-size:small">If you try to enable all swap-disk or reset to a high ratio in overcommit_ratio</span></div><div class="gmail_quote"><span class="gmail_default" style="font-size:small">to make it larger than MemAvailable, probably no OOM occurs anymore.</span></div><div class="gmail_quote"><br></div><div class="gmail_quote"><div class="gmail_default" style="font-size:small">Btw, I also observed that ioctl_sg01 almost being killed by OOM</div><div class="gmail_default" style="font-size:small">every time on<span class="gmail_default"> an aarch64 </span>with little swap space<span class="gmail_default">, but if I add more</span></div><div class="gmail_default" style="font-size:small"><span class="gmail_default">swap </span><span class="gmail_default">or set a high </span>value of overcommit_ratio, the problem is gone.</div><div class="gmail_default" style="font-size:small">(I manually tried with another x86_64 to confirm this too)</div><div class="gmail_default" style="font-size:small"><pre style="color:rgb(0,0,0);white-space:pre-wrap">              total        used        free      shared  buff/cache   available
Mem:         259828        5365      247383          68        7079      231296
Swap:          4095          55        4040</pre><pre style="color:rgb(0,0,0);white-space:pre-wrap"><span style="font-family:Arial,Helvetica,sans-serif">---</span>
</pre><pre style="color:rgb(0,0,0);white-space:pre-wrap">MemTotal:       266063872 kB
MemFree:        253320768 kB
MemAvailable:   236848064 kB
Buffers:            1472 kB
Cached:          6755456 kB
SwapCached:        12160 kB
...
CommitLimit:    137226176 kB
Committed_AS:    1206912 kB
---</pre></div></div><div class="gmail_quote"><span class="gmail_default" style="font-size:small"><div class="gmail_quote"><span class="gmail_default"><br></span></div><div class="gmail_quote"><span class="gmail_default">The previous method in the patch[1] seems not good enough, but that can</span></div><div class="gmail_quote"><span class="gmail_default">help </span>to verify if OOM <span class="gmail_default">disappears</span> when resetting the overcommit_ratio.</div><div class="gmail_quote"><span class="gmail_default">[1] <a href="http://lists.linux.it/pipermail/ltp/2021-February/020907.html" target="_blank">http://lists.linux.it/pipermail/ltp/2021-February/020907.html</a></span></div><div class="gmail_quote"><br></div></span></div><div class="gmail_quote"><span class="gmail_default" style="font-size:small">Hence, another improvement way based on the above is to allocate proper</span></div><div class="gmail_quote"><span class="gmail_default">memory-size </span><span class="gmail_default">according </span><span class="gmail_default">to </span><span class="gmail_default">CommitLimit value when detecting </span>the value of<span class="gmail_default"></span></div><div class="gmail_quote"><span class="gmail_default"></span>CommitLimit<span class="gmail_default" style="font-size:small"> is </span>less<span class="gmail_default"> </span>than<span class="gmail_default"> </span><span class="gmail_default"></span>MemAvailable.<span class="gmail_default"> </span>That will make the<span class="gmail_default"> </span><span class="gmail_default">test happy with</span><span class="gmail_default"></span></div><div class="gmail_quote"><span class="gmail_default">a </span>little swap-space<span class="gmail_default" style="font-size:small"> </span><span class="gmail_default"></span>size<span class="gmail_default"> </span>system<span class="gmail_default">.</span></div><div class="gmail_quote"><span class="gmail_default"><br></span></div><div class="gmail_quote"><span class="gmail_default">Any thoughts, or comments?</span></div><div class="gmail_quote"><span class="gmail_default"><br></span></div><div class="gmail_quote"><span class="gmail_default">--- a/lib/tst_memutils.c<br>+++ b/lib/tst_memutils.c<br>@@ -36,6 +36,13 @@ void tst_pollute_memory(size_t maxsize, int fillchar)<br>        if (info.freeram - safety < maxsize / info.mem_unit)<br>                maxsize = (info.freeram - safety) * info.mem_unit;<br> <br>+       /*<br>+        * To respect CommitLimit to prevent test invoking OOM killer,<br>+        * this may appear on system with a smaller swap-disk (or disabled).<br>+        */<br>+       if (SAFE_READ_MEMINFO("CommitLimit:") < SAFE_READ_MEMINFO("MemAvailable:"))<br>+               maxsize = SAFE_READ_MEMINFO("CommitLimit:") * 1024 - (safety * info.mem_unit);<br>+<br>        blocksize = MIN(maxsize, blocksize);<br>        map_count = maxsize / blocksize;<br>        map_blocks = SAFE_MALLOC(map_count * sizeof(void *));<br></span></div><div class="gmail_quote"><br></div><div class="gmail_quote"><br></div><div class="gmail_quote"><div class="gmail_default" style="font-size:small">========================</div></div><div class="gmail_quote"><br></div><div class="gmail_quote"><span class="gmail_default" style="font-size:small">About the </span> <span class="gmail_default" style="font-size:small">MemAvailable < MemFree, I think that is correct behavior on</span></div><div class="gmail_quote"><span class="gmail_default" style="font-size:small">your system and not the OOM root-cause.</span></div><div class="gmail_quote"><span class="gmail_default" style="font-size:small"><br></span></div><div class="gmail_quote"><span class="gmail_default" style="font-size:small">Generally, we assumed the MemAvailable higher </span><span class="gmail_default">than </span><span class="gmail_default">MemFree,</span></div><div class="gmail_quote">but we <span class="gmail_default">sometimes also allow situations to break that. </span><span class="gmail_default">We'd better</span></div><div class="gmail_quote"><span class="gmail_default">count</span><span class="gmail_default"> </span>all of the different free watermarks from /proc/zoneinfo<span class="gmail_default">, </span><span class="gmail_default">then</span></div><div class="gmail_quote">add the sum of the low watermarks to MemAvailable, if get a value</div><div class="gmail_quote">larger<span class="gmail_default" style="font-size:small"> </span>than MemFree, that should be OK from my perspective.</div><div><div class="gmail_default" style="font-size:small"></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">-----</div># echo 675840 > /proc/sys/vm/min_free_kbytes</div><div><br># cat /proc/meminfo |grep -i mem<br>MemTotal:        5888584 kB<br><span class="gmail_default" style="font-size:small"></span>MemFree:         4518064 kB<br><span class="gmail_default" style="font-size:small"></span>MemAvailable:    3692008 kB<br>Shmem:             21128 kB<br>ShmemHugePages:        0 kB<br>ShmemPmdMapped:        0 kB</div><div><span class="gmail_default" style="font-size:small"></span><br><br># cat /proc/zoneinfo |grep low<span class="gmail_default" style="font-size:small"> -B 3 </span><br><span class="gmail_default" style="font-size:small">...</span><span class="gmail_default" style="font-size:small"></span><br>  pages free     3840<br>        min      440<br>        low      550<br>--<br>Node 0, zone    DMA32<br>  pages free     355602<br>        min      79706<br>        low      99632<br>--<br>Node 0, zone   Normal<br>  pages free     0<br>        min      0<br>        low      0<br>--<br>Node 0, zone  Movable<br>  pages free     0<br>        min      0<br>        low      0<br>--<br>Node 0, zone   Device<br>  pages free     0<br>        min      0<br>        low      0<br>--<br>Node 1, zone      DMA<br>  pages free     0<br>        min      0<br>        low      0<br>--<br>Node 1, zone    DMA32<br>  pages free     0<br>        min      0<br>        low      0<br>--<br>      nr_kernel_misc_reclaimable 0<br>  pages free     769192<br>        min      88812<br>        low      111015</div><div><br><div class="gmail_default" style="font-size:small"></div><div><div class="gmail_default" style="font-size:small">(111015+99632+550)*4 + 3692008(<span class="gmail_default"></span>MemAvailable) > 5888584(<span class="gmail_default"></span>MemFree)</div></div><div><br><div class="gmail_quote"><div class="gmail_default" style="font-size:small">Btw the formula to count MemAvailable is:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">available = MemFree - totalreserve_pages + pages[LRU_ACTIVE_FILE] + pages[LRU_INACTIVE_FILE] - min(pagecache / 2, wmark_low)</div></div><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div></div></div>