lib: add tst_available_mem function
PATCH 1/3 lib: add tst_available_mem function
tst_available_mem helps to get the value of MemAvailable from /proc/meminfo, if no support on older kernels, return 'MemFree + Cached' for instead.
--- include/tst_memutils.h | 6 ++++++ lib/tst_memutils.c | 13 +++++++++++++ 2 files changed, 19 insertions(+)
include/tst_memutils.h +6 -0
@@ -19,4 +19,10 @@*/ void tst_pollute_memory (size_t maxsize,int fillchar); +/* +* Read the value of MemAvailable from /proc/meminfo, if no support on +* older kernels, return 'MemFree + Cached' for instead. +*/ +long long tst_available_mem (void ); +#endif /* TST_MEMUTILS_H__ */
lib/tst_memutils.c +13 -0
@@ -62,3 +62,16 @@ void tst_pollute_memory(size_t maxsize, int fillchar)free (map_blocks); } + +long long tst_available_mem (void ) +{ +long long mem_available; + +if (FILE_LINES_SCANF ("/proc/meminfo" ,"MemAvailable: %ld" , + &mem_available)) { + mem_available =SAFE_READ_MEMINFO ("MemFree:" ) + +SAFE_READ_MEMINFO ("Cached:" ); + } + +return mem_available; +}
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/3 swapping01: make use of tst_available_mem
--- testcases/kernel/mem/include/mem.h | 1 + testcases/kernel/mem/swapping/swapping01.c | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-)
testcases/kernel/mem/include/mem.h +1 -0
@@ -4,6 +4,7 @@#include "tst_test.h" #include "tst_cgroup.h" #include "ksm_helper.h" +#include "tst_memutils.h" #if defined(__powerpc__) || defined(__powerpc64__)#define MAXNODES 256
testcases/kernel/mem/swapping/swapping01.c +1 -5
@@ -83,11 +83,7 @@ static void test_swapping(void)static void init_meminfo (void ) { swap_free_init =SAFE_READ_MEMINFO ("SwapFree:" ); -if (FILE_LINES_SCANF ("/proc/meminfo" ,"MemAvailable: %ld" , - &mem_available_init)) { - mem_available_init =SAFE_READ_MEMINFO ("MemFree:" ) - +SAFE_READ_MEMINFO ("Cached:" ); - } + mem_available_init =tst_available_mem (); mem_over = mem_available_init *COE_SLIGHT_OVER ; mem_over_max = mem_available_init *COE_DELTA ;
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 2/3] swapping01: make use of tst_available_mem
Hi Li,
obviously correct, thanks!
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 3/3 lib: unlimit the tmpfs size when test on small systems
In reply to Li WangSince 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 cancel the tmpfs size limitation when MemAvailable is less than twofold of tdev.size.
--- include/tst_test.h | 1 + lib/tst_test.c | 3 +++ 2 files changed, 4 insertions(+)
include/tst_test.h +1 -0
@@ -42,6 +42,7 @@#include "tst_lockdown.h" #include "tst_fips.h" #include "tst_taint.h" +#include "tst_memutils.h" /* * Reports testcase result.
lib/tst_test.c +3 -0
@@ -895,6 +895,9 @@ static const char *limit_tmpfs_mount_size(const char *mnt_data,if (strcmp (fs_type,"tmpfs" ))return mnt_data; +if ((tst_available_mem () /1024 ) < (tdev.size *2 )) +return mnt_data; +if (mnt_data)snprintf (buf, buf_size,"%s,size=%luM" , mnt_data, tdev.size);else
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 3/3] lib: unlimit the tmpfs size when test on small systems
Hi!
Quoted 32 lines
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 cancel the tmpfs size limitation when MemAvailable is less than twofold of tdev.size.
Reported-by Ralph Siemsen <[email protected]>Signed-off-by Li Wang <[email protected]>--- include/tst_test.h | 1 + lib/tst_test.c | 3 +++ 2 files changed, 4 insertions(+)include/tst_test.h +1
-0@@ -42,6 +42,7 @@#include "tst_lockdown.h" #include "tst_fips.h" #include "tst_taint.h" +#include "tst_memutils.h" /* * Reports testcase result. lib/tst_test.c +0
-0
lib/tst_test.c static const char *limit_tmpfs_mount_size(const char *mnt_data, · line 899
Quoted 5 lines
lib/tst_test.c +2
-0@@ -895,6 +895,9 @@ static const char *limit_tmpfs_mount_size(const char *mnt_data,if (strcmp (fs_type,"tmpfs" ))return mnt_data; +if ((tst_available_mem () /1024 ) < (tdev.size *2 )) +return mnt_data;
I'm starting to think that we should do it the other way around, i.e.
- unless the test defines .min_dev_size we should set the size for tmpfs to be really small 16MB or 32MB
- if .min_dev_size is defined and there is not enough free memory -> TCONF
- if .min_dev_size is not set and there is not even 64MB of free memory (for 32MB limit) -> TCONF
I think that this is going to work because most of the tests does not actually consume more than a megabyte or so of the disk space for the actuall test, the only reason why we kept bumping the loop device size is that there are limits on minimal size imposed by filesystems.
Quoted 9 lines
lib/tst_test.c +0
-0if (mnt_data)snprintf (buf, buf_size,"%s,size=%luM" , mnt_data, tdev.size);else Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 3/3] lib: unlimit the tmpfs size when test on small systems
Quoted 40 lines · Cyril Hrubis
Hi!
lib/tst_test.c static const char *limit_tmpfs_mount_size(const char
Quoted 32 lines
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 cancel the tmpfs size limitation when MemAvailable is less than twofold of tdev.size.
Reported-by Ralph Siemsen <[email protected]>Signed-off-by Li Wang <[email protected]>--- include/tst_test.h | 1 + lib/tst_test.c | 3 +++ 2 files changed, 4 insertions(+)include/tst_test.h +1
-0@@ -42,6 +42,7 @@#include "tst_lockdown.h" #include "tst_fips.h" #include "tst_taint.h" +#include "tst_memutils.h" /* * Reports testcase result. lib/tst_test.c +0
-0@@ -895,6 +895,9 @@ static const char *limit_tmpfs_mount_size(const char
*mnt_data,lib/tst_test.c static const char *limit_tmpfs_mount_size(const char *mnt_data, · line 899
Quoted 5 lines
lib/tst_test.c +2
-0if (strcmp (fs_type,"tmpfs" ))return mnt_data; +if ((tst_available_mem () /1024 ) < (tdev.size *2 )) +return mnt_data;
Quoted 8 lines
I'm starting to think that we should do it the other way around, i.e.
- unless the test defines .min_dev_size we should set the size for tmpfs to be really small 16MB or 32MB
- if .min_dev_size is defined and there is not enough free memory -> TCONF
- if .min_dev_size is not set and there is not even 64MB of free memory (for 32MB limit) -> TCONF
Agree, this is a cogitative handle way.
At least better than unlimit the tmpfs-size roughly when AvailableMem is short.
Quoted 5 lines
I think that this is going to work because most of the tests does not actually consume more than a megabyte or so of the disk space for the actuall test, the only reason why we kept bumping the loop device size is that there are limits on minimal size imposed by filesystems.
+1 Indeed.
Patch V2 is on the way...
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 3/3] lib: unlimit the tmpfs size when test on small systems
In reply to Cyril HrubisHi Cyril, Li,
Quoted 8 lines
Hi!
Quoted 7 lines
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 cancel the tmpfs size limitation when MemAvailable is less than twofold of tdev.size.
...
Quoted 5 lines
lib/tst_test.c static const char *limit_tmpfs_mount_size(const char *mnt_data, · line 899
Quoted 2 lines
lib/tst_test.c +2
-0+if ((tst_available_mem () /1024 ) < (tdev.size *2 )) +return mnt_data;I'm starting to think that we should do it the other way around, i.e.
Quoted 8 lines
- unless the test defines .min_dev_size we should set the size for tmpfs to be really small 16MB or 32MB
- if .min_dev_size is defined and there is not enough free memory -> TCONF
- if .min_dev_size is not set and there is not even 64MB of free memory (for 32MB limit) -> TCONFI think that this is going to work because most of the tests does not actually consume more than a megabyte or so of the disk space for the actuall test, the only reason why we kept bumping the loop device size is that there are limits on minimal size imposed by filesystems.
Also LGTM, thanks Li for working on v2.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 3/3 lib: adjust the tmpfs size according to .dev_min_size and MemAvailable
In reply to Li WangSince 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
--- include/tst_test.h | 1 + lib/tst_test.c | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-)
include/tst_test.h +1 -0
@@ -42,6 +42,7 @@#include "tst_lockdown.h" #include "tst_fips.h" #include "tst_taint.h" +#include "tst_memutils.h" /* * Reports testcase result.
lib/tst_test.c +13 -3
@@ -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; }
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] lib: adjust the tmpfs size according to .dev_min_size and MemAvailable
Hi!
Looks good.
For the whole patchset:
Also I guess that we should remove the .dev_min_size from the fallocate as a last step, right?
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] lib: adjust the tmpfs size according to .dev_min_size and MemAvailable
Quoted 7 lines · Cyril Hrubis
Hi!
Looks good.For the whole patchset:
Reviewed-by Cyril Hrubis <[email protected]>
Thanks for your reivews!
Quoted 4 lines
Also I guess that we should remove the .dev_min_size from the fallocate as a last step, right?
Yes, as we have DEV_SIZE_MB for all other filesystems, .dev_min_size is no need for fallocate05.
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] lib: adjust the tmpfs size according to .dev_min_size and MemAvailable
In reply to Li WangHi Li,
nit: I'd add Fixes: c305a53c5 ("lib: limit the size of tmpfs in LTP") if anybody searches on Fixes.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] lib: adjust the tmpfs size according to .dev_min_size and MemAvailable
Quoted 7 lines · Petr Vorel
Hi Li,
Reviewed-by Petr Vorel <[email protected]>nit: I'd add Fixes:
c305a53c5("lib: limit the size of tmpfs in LTP") if anybody searches on Fixes.
Thanks for the review, I added this and pushed it.
Btw, according to Ralph's test (153MB MemAva) result:
* test trigger OOM with mount 32MB tmpfs size
* test PASS with unlimited mount tmpfs size
(actually, it consume 134MB, from the log)
This is more like a kernel-specific problem but not LTP general issue.
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] lib: adjust the tmpfs size according to .dev_min_size and MemAvailable
Quoted 11 lines · Li Wang
Quoted 7 lines · Petr Vorel
Hi Li,
Reviewed-by Petr Vorel <[email protected]>nit: I'd add Fixes:
c305a53c5("lib: limit the size of tmpfs in LTP") if anybody searches on Fixes.Thanks for the review, I added this and pushed it.
I just tested the 20210927 release (commit 12beeda351) under qemu ARM. It seems that fallocate05 test is fine now, even with the 32MB fallback.
However fallocate06 test is failing with OOM. It seems this one still contains .dev_min_size = 512 , should this be removed?
Ralph
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] lib: adjust the tmpfs size according to .dev_min_size and MemAvailable
Quoted 2 lines · Ralph Siemsen
However fallocate06 test is failing with OOM. It seems this one still contains .dev_min_size = 512 , should this be removed?
With .dev_min_size = 512 the test should be skipped on my system since I have only ~120 MB of free RAM. But something is wrong with the test.
I added code to print the value returned by tst_available() and found that it was a very very large number.
After investigation, the format string "%ld" seems to be the culprit.
lib/tst_memutils.c +2 -2
@@ -65,13 +65,15 @@ void tst_pollute_memory(size_t maxsize, int fillchar)long long tst_available_mem (void ) { -long long mem_available; +long long mem_available =0 ; - if (FILE_LINES_SCANF("/proc/meminfo", "MemAvailable: %ld", + if (FILE_LINES_SCANF("/proc/meminfo", "MemAvailable: %lld",
&mem_available)) {
mem_available = SAFE_READ_MEMINFO("MemFree:")
+ SAFE_READ_MEMINFO("Cached:");
}+ tst_res(TINFO, "RFS: tst_available_mem returning %lld\n", mem_available);
+
return mem_available;
}
With the above change, tst_available() returns a reasonable value, and the fallocate06 test is skipped:
tst_test.c:1436: TINFO: Testing on tmpfs tst_test.c:937: TINFO: Skipping mkfs for TMPFS filesystem tst_memutils.c:81: TINFO: RFS: tst_available_mem return 120592 tst_test.c:907: TINFO: RFS: tmpfs_size = 512 avail=120592 tst_test.c:911: TCONF: No enough memory for tmpfs use
Also, when I remove the .dev_min_size=512 from fallocate06, then it uses the default size of 32MB, and the fallocate06 test runs and passes.
Regards,
Ralph
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] lib: adjust the tmpfs size according to .dev_min_size and MemAvailable
Hi Ralph,
Quoted 5 lines · Ralph Siemsen
Quoted 3 lines · Ralph Siemsen
However fallocate06 test is failing with OOM. It seems this one still contains .dev_min_size = 512 , should this be removed?
Quoted 8 lines
With .dev_min_size = 512 the test should be skipped on my system since I have only ~120 MB of free RAM. But something is wrong with the test.
I added code to print the value returned by
tst_available()and found that it was a very very large number.After investigation, the format string "%ld" seems to be the culprit.
Thanks for the debugging. Can you send a patch?
Quoted 40 lines
lib/tst_memutils.c +4
-2@@ -65,13 +65,15 @@ void tst_pollute_memory(size_t maxsize, int fillchar)long long tst_available_mem (void ) { -long long mem_available; +long long mem_available =0 ; -if (FILE_LINES_SCANF ("/proc/meminfo" ,"MemAvailable: %ld" , +if (FILE_LINES_SCANF ("/proc/meminfo" ,"MemAvailable: %lld" , &mem_available)) { mem_available =SAFE_READ_MEMINFO ("MemFree:" ) +SAFE_READ_MEMINFO ("Cached:" ); } +tst_res (TINFO ,"RFS: tst_available_mem returning %lld\n" , mem_available); +return mem_available;}With the above change,
tst_available()returns a reasonable value, and the fallocate06 test is skipped:tst_test.c:1436: TINFO: Testing on tmpfs tst_test.c:937: TINFO: Skipping mkfs for TMPFS filesystem tst_memutils.c:81: TINFO: RFS:
tst_available_memreturn 120592 tst_test.c:907: TINFO: RFS:tmpfs_size= 512 avail=120592 tst_test.c:911: TCONF: No enough memory for tmpfs useAlso, when I remove the .dev_min_size=512 from fallocate06, then it uses the default size of 32MB, and the fallocate06 test runs and passes.
Regards,
Ralph
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] lib: adjust the tmpfs size according to .dev_min_size and MemAvailable
Quoted 2 lines · Li Wang
Thanks for the debugging. Can you send a patch?
Yes, I will send one in a few moments (and then it's off to sleep).
Quoted 1 line
Quoted 1 line
Also, when I remove the .dev_min_size=512 from fallocate06, then it uses the default size of 32MB, and the fallocate06 test runs and passes.
Should we also change fallocate96 test to not request 512MB?
Regards,
Ralph
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] lib: adjust the tmpfs size according to .dev_min_size and MemAvailable
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Also, when I remove the .dev_min_size=512 from fallocate06, then it uses the default size of 32MB, and the fallocate06 test runs and passes.
Should we also change fallocate96 test to not request 512MB?
I think yes, there is no place that shows it needs a specific size 512.
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Li,
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp