From: Li Wang <liwang@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 1/2] lib: limit the size of tmpfs in LTP
Date: Mon, 5 Jul 2021 16:25:26 +0800 [thread overview]
Message-ID: <20210705082527.855688-1-liwang@redhat.com> (raw)
LTP mount and make use of the whole tmpfs of the test system,
generally, it's fine. But if a test (e.g fallocate06) try to
fill full in the filesystem, it takes too long to complete
testing on a large memory system.
This patch adds a new function limit_tmpfs_mount_size with
appending '-o size=xxM' to the mount options in prepare_device()
which helps limit the tmpfs mount size.
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Li Wang <liwang@redhat.com>
---
Notes:
V1 --> V2
* state limit_tmpfs_mount_size as a static function
* make use of the loop device size directly since
it already gets a proper size in tst_acquire_device_
* do NOT modify the tst_test->mnt_data
lib/tst_test.c | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 55449c80b..93761868e 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -882,8 +882,35 @@ static void prepare_and_mount_dev_fs(const char *mntpoint)
}
}
+static char *limit_tmpfs_mount_size(const char *mnt_data,
+ char *buf, size_t buf_size, const char *fs_type)
+{
+ int fd;
+ uint64_t dev_size;
+
+ if (strcmp(fs_type, "tmpfs"))
+ return mnt_data;
+
+ fd = SAFE_OPEN(tdev.dev, O_RDONLY);
+ SAFE_IOCTL(fd, BLKGETSIZE64, &dev_size);
+ SAFE_CLOSE(fd);
+
+ dev_size = dev_size/1024/1024;
+
+ if (mnt_data)
+ snprintf(buf, buf_size, "%s,size=%luM", mnt_data, dev_size);
+ else
+ snprintf(buf, buf_size, "size=%luM", dev_size);
+
+ tst_res(TINFO, "Limiting tmpfs size to %luMB", dev_size);
+
+ return buf;
+}
+
static void prepare_device(void)
{
+ char *mnt_data, buf[1024];
+
if (tst_test->format_device) {
SAFE_MKFS(tdev.dev, tdev.fs_type, tst_test->dev_fs_opts,
tst_test->dev_extra_opts);
@@ -896,8 +923,11 @@ static void prepare_device(void)
}
if (tst_test->mount_device) {
+ mnt_data = limit_tmpfs_mount_size(tst_test->mnt_data,
+ buf, sizeof(buf), tdev.fs_type);
+
SAFE_MOUNT(tdev.dev, tst_test->mntpoint, tdev.fs_type,
- tst_test->mnt_flags, tst_test->mnt_data);
+ tst_test->mnt_flags, mnt_data);
mntpoint_mounted = 1;
}
}
--
2.31.1
next reply other threads:[~2021-07-05 8:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-05 8:25 Li Wang [this message]
2021-07-05 8:25 ` [LTP] [PATCH v2 2/2] lib: mount tmpfs name as ltp-tmpfs Li Wang
2021-07-07 9:32 ` Cyril Hrubis
2021-07-07 9:31 ` [LTP] [PATCH v2 1/2] lib: limit the size of tmpfs in LTP Cyril Hrubis
2021-07-08 2:50 ` Li Wang
2021-07-08 6:36 ` Li Wang
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=20210705082527.855688-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox