Skip to content

Commit 21c8759

Browse files
committed
lib: adjust the tmpfs size according to .dev_min_size and MemAvailable
Since commit c305a53 (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> Fixes: c305a53 ("lib: limit the size of tmpfs in LTP") Suggested-by: Cyril Hrubis <chrubis@suse.cz> Signed-off-by: Li Wang <liwang@redhat.com> Reviewed-by: Cyril Hrubis <chrubis@suse.cz> Reviewed-by: Petr Vorel <pvorel@suse.cz>
1 parent 20ed074 commit 21c8759

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

include/tst_test.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "tst_lockdown.h"
4343
#include "tst_fips.h"
4444
#include "tst_taint.h"
45+
#include "tst_memutils.h"
4546

4647
/*
4748
* Reports testcase result.

lib/tst_test.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -892,15 +892,25 @@ static void prepare_and_mount_dev_fs(const char *mntpoint)
892892
static const char *limit_tmpfs_mount_size(const char *mnt_data,
893893
char *buf, size_t buf_size, const char *fs_type)
894894
{
895+
unsigned int tmpfs_size;
896+
895897
if (strcmp(fs_type, "tmpfs"))
896898
return mnt_data;
897899

900+
if (!tst_test->dev_min_size)
901+
tmpfs_size = 32;
902+
else
903+
tmpfs_size = tdev.size;
904+
905+
if ((tst_available_mem() / 1024) < (tmpfs_size * 2))
906+
tst_brk(TCONF, "No enough memory for tmpfs use");
907+
898908
if (mnt_data)
899-
snprintf(buf, buf_size, "%s,size=%luM", mnt_data, tdev.size);
909+
snprintf(buf, buf_size, "%s,size=%luM", mnt_data, tmpfs_size);
900910
else
901-
snprintf(buf, buf_size, "size=%luM", tdev.size);
911+
snprintf(buf, buf_size, "size=%luM", tmpfs_size);
902912

903-
tst_res(TINFO, "Limiting tmpfs size to %luMB", tdev.size);
913+
tst_res(TINFO, "Limiting tmpfs size to %luMB", tmpfs_size);
904914

905915
return buf;
906916
}

testcases/kernel/syscalls/fallocate/fallocate05.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ static void cleanup(void)
147147
static struct tst_test test = {
148148
.needs_root = 1,
149149
.mount_device = 1,
150-
.dev_min_size = 512,
151150
.mntpoint = MNTPOINT,
152151
.all_filesystems = 1,
153152
.setup = setup,

0 commit comments

Comments
 (0)