<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 Fri, Oct 18, 2019 at 11:30 PM Jan Stancek <<a href="mailto:jstancek@redhat.com">jstancek@redhat.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">Test is using 4 hugepages per allocation, and makes 4*3 allocations<br>
in total. This is problem for aarch64, where default huge page size<br>
is 512M. Systems are running into unexpected OOMs, because there<br>
is no check for available memory.<br>
<br>
Simplify test by:<br>
- dropping 3rd allocation, it's used only for pattern comparison<br>
- run test function in new child process, so we don't need to worry<br>
about cleaning up after mremap() and it lowers overall memory<br>
requirements<br>
- add a simple check if there's enough memory to setup()<br>
- drop .needs_root, there's no need for it<br>
<br>
Signed-off-by: Jan Stancek <<a href="mailto:jstancek@redhat.com" target="_blank">jstancek@redhat.com</a>><br>
---<br>
testcases/kernel/mem/thp/thp02.c | 79 +++++++++++++++++++++++++---------------<br>
1 file changed, 50 insertions(+), 29 deletions(-)<br>
<br>
diff --git a/testcases/kernel/mem/thp/thp02.c b/testcases/kernel/mem/thp/thp02.c<br>
index 6502210e50de..4d0c929f91ff 100644<br>
--- a/testcases/kernel/mem/thp/thp02.c<br>
+++ b/testcases/kernel/mem/thp/thp02.c<br>
@@ -47,46 +47,62 @@<br>
#ifdef HAVE_MREMAP_FIXED<br>
static int ps;<br>
static long hps, size;<br>
-static void *p, *p2, *p3, *p4;<br>
+<br>
+/*<br>
+ * Will try to do the following 4 mremaps cases:<br>
+ * mremap(p, size-ps, size-ps, flag, p3);<br>
+ * mremap(p, size-ps, size-ps, flag, p3+ps);<br>
+ * mremap(p+ps, size-ps, size-ps, flag, p3);<br>
+ * mremap(p+ps, size-ps, size-ps, flag, p3+ps);<br>
+ */<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">The comment should be updated too, otherwise patch LGTM.</div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+static void do_child(int i)<br>
+{<br>
+ long j, remap_size;<br>
+ unsigned char *p1, *p2, *ret, *old_addr, *new_addr;<br>
+<br>
+ p1 = SAFE_MEMALIGN(hps, size);<br>
+ p2 = SAFE_MEMALIGN(hps, size);<br>
+<br>
+ memset(p1, 0xff, size);<br>
+ memset(p2, 0x77, size);<br>
+<br>
+ old_addr = p1 + ps * (i >> 1);<br>
+ new_addr = p2 + ps * (i & 1);<br>
+ remap_size = size - ps;<br>
+<br>
+ tst_res(TINFO, "mremap (%p-%p) to (%p-%p)",<br>
+ old_addr, old_addr + remap_size,<br>
+ new_addr, new_addr + remap_size);<br>
+<br>
+ ret = mremap(old_addr, remap_size, remap_size,<br>
+ MREMAP_FIXED | MREMAP_MAYMOVE, new_addr);<br>
+ if (ret == MAP_FAILED)<br>
+ tst_brk(TBROK | TERRNO, "mremap");<br>
+<br>
+ for (j = 0; j < size - ps; j++) {<br>
+ if (ret[j] != 0xff)<br>
+ tst_brk(TBROK, "mremap bug");<br>
+ }<br>
+<br>
+ exit(0);<br>
+}<br>
<br>
static void do_mremap(void)<br>
{<br>
int i;<br>
- void *old_addr, *new_addr;<br>
<br>
for (i = 0; i < 4; i++) {<br>
- p = SAFE_MEMALIGN(hps, size);<br>
- p2 = SAFE_MEMALIGN(hps, size);<br>
- p3 = SAFE_MEMALIGN(hps, size);<br>
-<br>
- memset(p, 0xff, size);<br>
- memset(p2, 0xff, size);<br>
- memset(p3, 0x77, size);<br>
-<br>
- /*<br>
- * Will try to do the following 4 mremaps cases:<br>
- * mremap(p, size-ps, size-ps, flag, p3);<br>
- * mremap(p, size-ps, size-ps, flag, p3+ps);<br>
- * mremap(p+ps, size-ps, size-ps, flag, p3);<br>
- * mremap(p+ps, size-ps, size-ps, flag, p3+ps);<br>
- */<br>
- old_addr = p + ps * (i >> 1);<br>
- new_addr = p3 + ps * (i & 1);<br>
- tst_res(TINFO, "mremap %p to %p", old_addr, new_addr);<br>
-<br>
- p4 = mremap(old_addr, size - ps, size - ps,<br>
- MREMAP_FIXED | MREMAP_MAYMOVE, new_addr);<br>
- if (p4 == MAP_FAILED)<br>
- tst_brk(TBROK | TERRNO, "mremap");<br>
- if (memcmp(p4, p2, size - ps))<br>
- tst_brk(TBROK, "mremap bug");<br>
+ if (SAFE_FORK() == 0)<br>
+ do_child(i);<br>
+ tst_reap_children();<br>
}<br>
-<br>
tst_res(TPASS, "Still alive.");<br>
}<br>
<br>
static void setup(void)<br>
{<br>
+ long memfree;<br>
+<br>
if (access(PATH_THP, F_OK) == -1)<br>
tst_brk(TCONF, "THP not enabled in kernel?");<br>
<br>
@@ -95,12 +111,17 @@ static void setup(void)<br>
ps = sysconf(_SC_PAGESIZE);<br>
hps = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;<br>
size = hps * 4;<br>
+<br>
+ memfree = (SAFE_READ_MEMINFO("MemFree:") * 1024 +<br>
+ SAFE_READ_MEMINFO("Cached:") * 1024);<br>
+ if (memfree < size * 2)<br>
+ tst_brk(TCONF, "not enough memory");<br>
}<br>
<br>
static struct tst_test test = {<br>
- .needs_root = 1,<br>
.setup = setup,<br>
.test_all = do_mremap,<br>
+ .forks_child = 1,<br>
};<br>
<br>
#else<br>
-- <br>
1.8.3.1<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>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>