[LTP] [PATCH 1/2] lib: add .min_mem_avail in tst_test struct

Li Wang liwang@redhat.com
Wed Feb 9 09:56:59 CET 2022


As the name implies, this new field is mainly to set the minimum size
of MemAvailable for LTP testcase. If system available memory are less
than .min_mem_avail, test will be exit with TCONF.

And, it also helps to reduce OOM occurring in test parallel run. Due
to running more than one process that consumes a significant amount
of memory at the same time.

Signed-off-by: Li Wang <liwang@redhat.com>
---
 doc/c-test-api.txt | 6 ++++++
 include/tst_test.h | 3 +++
 lib/tst_test.c     | 3 +++
 3 files changed, 12 insertions(+)

diff --git a/doc/c-test-api.txt b/doc/c-test-api.txt
index 51dac58ae..dfbb453e1 100644
--- a/doc/c-test-api.txt
+++ b/doc/c-test-api.txt
@@ -2321,6 +2321,12 @@ static struct tst_test test = {
 };
 -------------------------------------------------------------------------------
 
+1.40 Require minimum size of MemAvailable for a testcase
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Some tests require more than specific size(MB) of MemAvailable. It can be defined
+with `.min_mem_avail = N`.
+
 2. Common problems
 ------------------
 
diff --git a/include/tst_test.h b/include/tst_test.h
index a7aaedcff..bac5e52ba 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -185,6 +185,9 @@ struct tst_test {
 	/* Minimum number of online CPU required by the test */
 	unsigned long min_cpus;
 
+	/* Minimum size(MB) of MemAvailable required by the test */
+	unsigned long min_mem_avail;
+
 	/*
 	 * If set non-zero number of request_hugepages, test will try to reserve the
 	 * expected number of hugepage for testing in setup phase. If system does not
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 1fd238cf5..191a9deab 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1090,6 +1090,9 @@ static void do_setup(int argc, char *argv[])
 	if (tst_test->min_cpus > (unsigned long)tst_ncpus())
 		tst_brk(TCONF, "Test needs at least %lu CPUs online", tst_test->min_cpus);
 
+	if (tst_test->min_mem_avail > (unsigned long)(tst_available_mem() / 1024))
+		tst_brk(TCONF, "Test needs at least %luMB MemAvailable", tst_test->min_mem_avail);
+
 	if (tst_test->request_hugepages)
 		tst_request_hugepages(tst_test->request_hugepages);
 
-- 
2.31.1



More information about the ltp mailing list