<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 19, 2021 at 11:02 PM Krzysztof Kozlowski <<a href="mailto:krzysztof.kozlowski@canonical.com" target="_blank">krzysztof.kozlowski@canonical.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Previous fix for an out-of-memory killer killing ioctl_sg01 process<br>
in commit 4d2e3d44fad5 ("lib: memutils: don't pollute<br>
entire system memory to avoid OoM") was not fully effective. While it<br>
covers most of the cases, an ARM64 machine with 128 GB of memory, 64 kB<br>
page size and v5.11 kernel hit it again. Polluting the memory fails<br>
with OoM:<br>
<br>
LTP: starting ioctl_sg01<br>
ioctl_sg01 invoked oom-killer: gfp_mask=0x100dca(GFP_HIGHUSER_MOVABLE|__GFP_ZERO), order=0, oom_score_adj=0<br>
...<br>
Mem-Info:<br>
active_anon:309 inactive_anon:1964781 isolated_anon:0<br>
active_file:94 inactive_file:0 isolated_file:0<br>
unevictable:305 dirty:0 writeback:0<br>
slab_reclaimable:1510 slab_unreclaimable:5012<br>
mapped:115 shmem:339 pagetables:463 bounce:0<br>
free:112043 free_pcp:1 free_cma:3159<br>
Node 0 active_anon:19776kB inactive_anon:125745984kB active_file:6016kB inactive_file:0kB unevictable:19520kB ...<br>
Node 0 DMA free:710656kB min:205120kB low:256384kB high:307648kB reserved_highatomic:0KB active_anon:0kB inactive_anon:3332032kB ...<br>
lowmem_reserve[]: 0 0 7908 7908 7908<br>
Node 0 Normal free:6460096kB min:6463168kB low:<span class="gmail_default" style="font-size:small"></span>8078912kB high:9694656kB reserved_highatomic:0KB active_anon:19776kB inactive_anon:122413952kB ...<br>
lowmem_reserve[]: 0 0 0 0 0<br>
<br>
The important part are details of memory on Node 0 in Normal zone:<br>
1. free memory: 6460096 kB<br>
2. min (minimum watermark): 6463168 kB<br>
<br>
Parse the /proc/zoneinfo and include the "min" data when counting safety<br>
(free memory which should not be polluted). This way we also include<br>
minimum memory for DMA zones and all nodes.<br>
<br>
Signed-off-by: Krzysztof Kozlowski <<a href="mailto:krzysztof.kozlowski@canonical.com" target="_blank">krzysztof.kozlowski@canonical.com</a>><br>
---<br>
lib/tst_memutils.c | 31 +++++++++++++++++++++++++++++--<br>
1 file changed, 29 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c<br>
index af132bcc6c24..f34ba582ec93 100644<br>
--- a/lib/tst_memutils.c<br>
+++ b/lib/tst_memutils.c<br>
@@ -6,22 +6,49 @@<br>
#include <unistd.h><br>
#include <limits.h><br>
#include <sys/sysinfo.h><br>
+#include <stdio.h><br>
#include <stdlib.h><br>
<br>
#define TST_NO_DEFAULT_MAIN<br>
#include "tst_test.h"<br>
+#include "tst_safe_stdio.h"<br>
<br>
#define BLOCKSIZE (16 * 1024 * 1024)<br>
<br>
+unsigned long tst_min_memory(void)<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">The prefix "tst_" is used for a function which extern to the whole LTP. </div><div class="gmail_default" style="font-size:small">In this case the function is only used in the library, so we'd better </div><div class="gmail_default" style="font-size:small">avoid using tst_.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">As it parses minimal pages from /proc/zoneinfo, so I'd suggest rename</div><div class="gmail_default" style="font-size:small">it to count_min_pages.</div></div><div><br></div><div><div class="gmail_default" style="font-size:small">The remaining part looks good to me.</div></div><div> </div><div><div class="gmail_default" style="font-size:small">Reviewed-by: Li Wang <<a href="mailto:liwang@redhat.com" target="_blank">liwang@redhat.com</a>></div><div class="gmail_default" style="font-size:small"></div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+{<br>
+ FILE *fp;<br>
+ int ret;<br>
+ unsigned long total_pages = 0;<br>
+ unsigned long pages;<br>
+ char line[BUFSIZ];<br>
+<br>
+ fp = SAFE_FOPEN("/proc/zoneinfo", "r");<br>
+<br>
+ while (fgets(line, BUFSIZ, fp) != NULL) {<br>
+ ret = sscanf(line, " min %lu", &pages);<br>
+ if (ret == 1)<br>
+ total_pages += pages;<br>
+ }<br>
+<br>
+ SAFE_FCLOSE(fp);<br>
+<br>
+ /* Apply a margin because we cannot get below "min" watermark */<br>
+ total_pages += (total_pages / 10);<br>
+<br>
+ return total_pages;<br>
+}<br>
+<br>
void tst_pollute_memory(size_t maxsize, int fillchar)<br>
{<br>
size_t i, map_count = 0, safety = 0, blocksize = BLOCKSIZE;<br>
+ long pagesize = SAFE_SYSCONF(_SC_PAGESIZE);<br>
void **map_blocks;<br>
struct sysinfo info;<br>
<br>
SAFE_SYSINFO(&info);<br>
- safety = MAX(4096 * SAFE_SYSCONF(_SC_PAGESIZE), 128 * 1024 * 1024);<br>
- safety = MAX(safety, (info.freeram / 64));<br>
+ safety = MAX(4096 * pagesize, 128 * 1024 * 1024);<br>
+ safety = MAX(safety, tst_min_memory() * pagesize);<br>
safety /= info.mem_unit;<br>
<br>
if (info.freeswap > safety)<br>
-- <br>
2.30.2<br>
<br>
<br>
-- <br>
Mailing list info: <a href="https://lists.linux.it/listinfo/ltp" rel="noreferrer" target="_blank">https://lists.linux.it/listinfo/ltp</a><br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>