All of lore.kernel.org
 help / color / mirror / Atom feed
From: Li Wang <liwang@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 3/3] lib: adjust the tmpfs size according to .dev_min_size and MemAvailable
Date: Fri, 24 Sep 2021 18:52:34 +0800	[thread overview]
Message-ID: <20210924105234.3927811-1-liwang@redhat.com> (raw)
In-Reply-To: <20210924070756.3916953-3-liwang@redhat.com>

Since commit c305a53c5 (lib: limit the size of tmpfs in LTP, Jul 9)
Ltp set tmpfs mount size according to the tdev.size. This cause a
new problem on small RAM system, which consume too much memory and
finally trigger OOM.

To fix this, let's adjust the tmpfs-size according to both free memory
and .dev_min_size:

 - if .dev_min_size is defined and system has enough free memory,
   set tmpfs-size to tdev.size

 - if .dev_min_size is defined and there is not enough free
   memory -> TCONF

 - if the test not define .dev_min_size, set the size for tmpfs to
   be really small 32MB

 - if .dev_min_size is not define and there is not even 64MB of free
   memory (for 32MB limit) -> TCONF

Reported-by: Ralph Siemsen <ralph.siemsen@linaro.org>
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Li Wang <liwang@redhat.com>
---
 include/tst_test.h |  1 +
 lib/tst_test.c     | 16 +++++++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/include/tst_test.h b/include/tst_test.h
index 5e3619698..3dcb45de0 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -42,6 +42,7 @@
 #include "tst_lockdown.h"
 #include "tst_fips.h"
 #include "tst_taint.h"
+#include "tst_memutils.h"
 
 /*
  * Reports testcase result.
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 4224353da..ec80e17a6 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -892,15 +892,25 @@ static void prepare_and_mount_dev_fs(const char *mntpoint)
 static const char *limit_tmpfs_mount_size(const char *mnt_data,
 		char *buf, size_t buf_size, const char *fs_type)
 {
+	unsigned int tmpfs_size;
+
 	if (strcmp(fs_type, "tmpfs"))
 		return mnt_data;
 
+	if (!tst_test->dev_min_size)
+		tmpfs_size = 32;
+	else
+		tmpfs_size = tdev.size;
+
+	if ((tst_available_mem() / 1024) < (tmpfs_size * 2))
+		tst_brk(TCONF, "No enough memory for tmpfs use");
+
 	if (mnt_data)
-		snprintf(buf, buf_size, "%s,size=%luM", mnt_data, tdev.size);
+		snprintf(buf, buf_size, "%s,size=%luM", mnt_data, tmpfs_size);
 	else
-		snprintf(buf, buf_size, "size=%luM", tdev.size);
+		snprintf(buf, buf_size, "size=%luM", tmpfs_size);
 
-	tst_res(TINFO, "Limiting tmpfs size to %luMB", tdev.size);
+	tst_res(TINFO, "Limiting tmpfs size to %luMB", tmpfs_size);
 
 	return buf;
 }
-- 
2.31.1


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

  parent reply	other threads:[~2021-09-24 10:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-24  7:07 [LTP] [PATCH 1/3] lib: add tst_available_mem function Li Wang
2021-09-24  7:07 ` [LTP] [PATCH 2/3] swapping01: make use of tst_available_mem Li Wang
2021-09-24 14:17   ` Petr Vorel
2021-09-24  7:07 ` [LTP] [PATCH 3/3] lib: unlimit the tmpfs size when test on small systems Li Wang
2021-09-24  9:51   ` Cyril Hrubis
2021-09-24 10:27     ` Li Wang
2021-09-24 10:40     ` Petr Vorel
2021-09-24 10:52   ` Li Wang [this message]
2021-09-24 11:05     ` [LTP] [PATCH v2 3/3] lib: adjust the tmpfs size according to .dev_min_size and MemAvailable Cyril Hrubis
2021-09-24 11:32       ` Li Wang
2021-09-24 14:23     ` Petr Vorel
2021-09-27  2:39       ` Li Wang
2021-09-27 15:12         ` Ralph Siemsen
2021-09-27 19:09           ` Ralph Siemsen
2021-09-28  1:19             ` Li Wang
2021-09-28  2:22               ` Ralph Siemsen
2021-09-28  7:53                 ` Li Wang
2021-09-24 14:15 ` [LTP] [PATCH 1/3] lib: add tst_available_mem function Petr Vorel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210924105234.3927811-1-liwang@redhat.com \
    --to=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.