Skip to content

Commit

Permalink
lib: adjust the tmpfs size according to .dev_min_size and MemAvailable
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
wangli5665 committed Sep 27, 2021
1 parent 20ed074 commit 21c8759
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/tst_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "tst_lockdown.h"
#include "tst_fips.h"
#include "tst_taint.h"
#include "tst_memutils.h"

/*
* Reports testcase result.
Expand Down
16 changes: 13 additions & 3 deletions lib/tst_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion testcases/kernel/syscalls/fallocate/fallocate05.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ static void cleanup(void)
static struct tst_test test = {
.needs_root = 1,
.mount_device = 1,
.dev_min_size = 512,
.mntpoint = MNTPOINT,
.all_filesystems = 1,
.setup = setup,
Expand Down

0 comments on commit 21c8759

Please sign in to comment.