Skip to contentSkip to conversation

syscalls/madvise06: Fix sporadic not enough RAM TCONFs

PATCH In review Cyril Hrubis 4 participants 7 messages May 27

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls/madvise06: Fix sporadic not enough RAM TCONFs

On systems with <= 2GB RAM the test produced sporadic TCONFs. That is because even if the test setup does sync() and drops caches the system starts fauting in pages immediatelly after caches were dropped. It may easily happen that system may fault in a few hundred of MBs of memory betwen the write to drop_caches and the time sysinfo() syscall returns.

The correct fix is to use the MemAvailable metric from /proc/meminfo that includes both free memory and caches and is more realistic estimate of how much memory can be consumed by a test. We even have helper functions in the test library so we simply make use of them.

---
 testcases/kernel/syscalls/madvise/madvise06.c | 21 ++++++++++---------
 1 file changed, 11 insertions(+), 10 deletions(-)
testcases/kernel/syscalls/madvise/madvise06.c +11 -10
index a9df913fc..969b24984 100644
@@ -39,7 +39,6 @@
 #include <errno.h>
 #include <stdio.h>
 #include <sys/mount.h>
-#include <sys/sysinfo.h>
 #include "tst_test.h"
 
 #define CHUNK_SZ (400*1024*1024L)
@@ -90,22 +89,24 @@ static void meminfo_diag(const char *point)
 
 static void setup(void)
 {
-	struct sysinfo sys_buf_start;
-
 	pg_sz = getpagesize();
 
 	tst_res(TINFO, "dropping caches");
 	sync();
 	SAFE_FILE_PRINTF(drop_caches_fname, "3");
 
-	sysinfo(&sys_buf_start);
-	if (sys_buf_start.freeram < 2 * CHUNK_SZ) {
-		tst_brk(TCONF, "System RAM is too small (%li bytes needed)",
-			2 * CHUNK_SZ);
+	long long avail_mem = tst_available_mem();
+	long long avail_swap = tst_available_swap();
+	long long chunk_kb = 2 * CHUNK_SZ / 1024;
+
+	if (avail_mem < chunk_kb) {
+		tst_brk(TCONF, "System RAM is too small %llikB (%llikB needed)",
+			avail_mem, chunk_kb);
 	}
-	if (sys_buf_start.freeswap < 2 * CHUNK_SZ) {
-		tst_brk(TCONF, "System swap is too small (%li bytes needed)",
-			2 * CHUNK_SZ);
+
+	if (avail_swap < chunk_kb) {
+		tst_brk(TCONF, "System swap is too small %llikB (%llikB needed)",
+			avail_swap, chunk_kb);
 	}
 
 	check_path("/proc/self/oom_score_adj");
Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Cyril Hrubis

On systems with <= 2GB RAM the test produced sporadic TCONFs. That is because even if the test setup does sync() and drops caches the system starts fauting in pages immediatelly after caches were dropped. It may easily happen that system may fault in a few hundred of MBs of memory betwen the write to drop_caches and the time sysinfo() syscall returns.

Quoted 6 lines

The correct fix is to use the MemAvailable metric from /proc/meminfo that includes both free memory and caches and is more realistic estimate of how much memory can be consumed by a test. We even have helper functions in the test library so we simply make use of them.

Sounds reasonable.

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by Reviewed-by on v1 1/1
#2 lore raw
In reply to Cyril Hrubis

Hi Cyril,

Quoted 10 lines

On systems with <= 2GB RAM the test produced sporadic TCONFs. That is because even if the test setup does sync() and drops caches the system starts fauting in pages immediatelly after caches were dropped. It may easily happen that system may fault in a few hundred of MBs of memory betwen the write to drop_caches and the time sysinfo() syscall returns.

The correct fix is to use the MemAvailable metric from /proc/meminfo that includes both free memory and caches and is more realistic estimate of how much memory can be consumed by a test. We even have helper functions in the test library so we simply make use of them.

Thanks for an investigation!

...

testcases/kernel/syscalls/madvise/madvise06.c static void meminfo_diag(const char *point) · line 104

Quoted 11 lines
testcases/kernel/syscalls/madvise/madvise06.c +7 -4
-	sysinfo(&sys_buf_start);
-	if (sys_buf_start.freeram < 2 * CHUNK_SZ) {
-		tst_brk(TCONF, "System RAM is too small (%li bytes needed)",
-			2 * CHUNK_SZ);
+	long long avail_mem = tst_available_mem();
+	long long avail_swap = tst_available_swap();
+	long long chunk_kb = 2 * CHUNK_SZ / 1024;
+
+	if (avail_mem < chunk_kb) {
+		tst_brk(TCONF, "System RAM is too small %llikB (%llikB needed)",
+			avail_mem, chunk_kb);

nit: I'd print also the current (not big enough) values (I know that the old code).

Quoted 9 lines
testcases/kernel/syscalls/madvise/madvise06.c +4 -3
 	}
-	if (sys_buf_start.freeswap < 2 * CHUNK_SZ) {
-		tst_brk(TCONF, "System swap is too small (%li bytes needed)",
-			2 * CHUNK_SZ);
+
+	if (avail_swap < chunk_kb) {
+		tst_brk(TCONF, "System swap is too small %llikB (%llikB needed)",
+			avail_swap, chunk_kb);
 	}
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi!

Quoted 15 lines
Quoted 10 lines

On systems with <= 2GB RAM the test produced sporadic TCONFs. That is because even if the test setup does sync() and drops caches the system starts fauting in pages immediatelly after caches were dropped. It may easily happen that system may fault in a few hundred of MBs of memory betwen the write to drop_caches and the time sysinfo() syscall returns.

The correct fix is to use the MemAvailable metric from /proc/meminfo that includes both free memory and caches and is more realistic estimate of how much memory can be consumed by a test. We even have helper functions in the test library so we simply make use of them.

Thanks for an investigation!

...

Quoted 13 lines

testcases/kernel/syscalls/madvise/madvise06.c static void meminfo_diag(const char *point) · line 104

Quoted 11 lines
testcases/kernel/syscalls/madvise/madvise06.c +7 -4
-	sysinfo(&sys_buf_start);
-	if (sys_buf_start.freeram < 2 * CHUNK_SZ) {
-		tst_brk(TCONF, "System RAM is too small (%li bytes needed)",
-			2 * CHUNK_SZ);
+	long long avail_mem = tst_available_mem();
+	long long avail_swap = tst_available_swap();
+	long long chunk_kb = 2 * CHUNK_SZ / 1024;
+
+	if (avail_mem < chunk_kb) {
+		tst_brk(TCONF, "System RAM is too small %llikB (%llikB needed)",
+			avail_mem, chunk_kb);

nit: I'd print also the current (not big enough) values (I know that the old code).

Huh? That's what the test does after my changes, we print both avail_mem and chunk_kb after the change.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw
Quoted 30 lines

Hi!

Quoted 15 lines
Quoted 10 lines

On systems with <= 2GB RAM the test produced sporadic TCONFs. That is because even if the test setup does sync() and drops caches the system starts fauting in pages immediatelly after caches were dropped. It may easily happen that system may fault in a few hundred of MBs of memory betwen the write to drop_caches and the time sysinfo() syscall returns.

The correct fix is to use the MemAvailable metric from /proc/meminfo that includes both free memory and caches and is more realistic estimate of how much memory can be consumed by a test. We even have helper functions in the test library so we simply make use of them.

Thanks for an investigation!

...

Quoted 13 lines

testcases/kernel/syscalls/madvise/madvise06.c static void meminfo_diag(const char *point) · line 104

Quoted 11 lines
testcases/kernel/syscalls/madvise/madvise06.c +7 -4
-	sysinfo(&sys_buf_start);
-	if (sys_buf_start.freeram < 2 * CHUNK_SZ) {
-		tst_brk(TCONF, "System RAM is too small (%li bytes needed)",
-			2 * CHUNK_SZ);
+	long long avail_mem = tst_available_mem();
+	long long avail_swap = tst_available_swap();
+	long long chunk_kb = 2 * CHUNK_SZ / 1024;
+
+	if (avail_mem < chunk_kb) {
+		tst_brk(TCONF, "System RAM is too small %llikB (%llikB needed)",
+			avail_mem, chunk_kb);

nit: I'd print also the current (not big enough) values (I know that the old code).

Quoted 2 lines

Huh? That's what the test does after my changes, we print both avail_mem and chunk_kb after the change.

I'm sorry to be blind today. Thanks for doing that.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw
In reply to Cyril Hrubis

Hi Cyril,

Quoted 7 lines · Cyril Hrubis

syscalls/madvise06: Fix sporadic not enough RAM TCONFs

On systems with <= 2GB RAM the test produced sporadic TCONFs. That is because even if the test setup does sync() and drops caches the system starts fauting in pages immediatelly after caches were dropped. It may easily happen that system may fault in a few hundred of MBs of memory betwen the write to drop_caches and the time sysinfo() syscall returns.

Three typos in the commit body: "fauting" -> "faulting", "immediatelly" -> "immediately", "betwen" -> "between".

Quoted 2 lines

Duplicate Reviewed-by tag.

[...]

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Hi!

Quoted 8 lines
Quoted 5 lines

On systems with <= 2GB RAM the test produced sporadic TCONFs. That is because even if the test setup does sync() and drops caches the system starts fauting in pages immediatelly after caches were dropped. It may easily happen that system may fault in a few hundred of MBs of memory betwen the write to drop_caches and the time sysinfo() syscall returns.

Three typos in the commit body: "fauting" -> "faulting", "immediatelly" -> "immediately", "betwen" -> "between".

Fixed the typos and pushed.

Quoted 4 lines
Quoted 2 lines

Duplicate Reviewed-by tag.

How did it pick up this? This wasn't in the orignal patch, only in a mail reply.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp