On large machines (with dozens of gigabytes of swap)
it can take significant time until it completes,
unless you specify "-p" parameter to set percent of total
memory to use. It is difficult to find value, that would fit
all setups. If the value is low, it won't exercise
conditions when memory is low. If the value is high it turns
into stress test, which can be swapping memory for hours.
This patch adds new option '-s', which stops test if swap
usage goes beyoned <s> MBytes. By default it is 0 - no limit.
For example:
mtest01 -p 95 -w -s 4096
will keep allocating memory until 95% of total memory is used,
or swap usage is > 4GB.
This parameter is meant to be used in sanity tests, so that
malloc is exercised in situations with high/low memory
until system resorts to swapping, but ends when swap usage
is high enough.
Signed-off-by: Jan Stancek <[email protected]>
---
testcases/kernel/mem/mtest01/mtest01.c | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/testcases/kernel/mem/mtest01/mtest01.c b/testcases/kernel/mem/mtest01/mtest01.c
index dc960a8..54bda70 100644
--- a/testcases/kernel/mem/mtest01/mtest01.c
+++ b/testcases/kernel/mem/mtest01/mtest01.c
@@ -67,6 +67,7 @@ int main(int argc, char* argv[])
unsigned long long original_maxbytes, maxbytes = 0;
unsigned long long pre_mem = 0, post_mem = 0;
unsigned long long total_ram, total_free, D, C;
+ unsigned long long used_swap, swap_max = 0;
int chunksize = 1024*1024; /* one meg at a time by default */
struct sysinfo sstats;
int i, pid_cntr;
@@ -78,7 +79,7 @@ int main(int argc, char* argv[])
sigemptyset(&act.sa_mask);
sigaction(SIGRTMIN, &act, 0);
- while ((c = getopt(argc, argv, "c:b:p:wvh")) != -1) {
+ while ((c = getopt(argc, argv, "c:b:p:s:wvh")) != -1) {
switch(c) {
case 'c':
chunksize = atoi(optarg);
@@ -105,6 +106,10 @@ int main(int argc, char* argv[])
"ERROR: -p option cannot be greater than "
"99");
break;
+ case 's':
+ swap_max = atoi(optarg);
+ swap_max = swap_max * 1024 * 1024;
+ break;
case 'w':
dowrite = 1;
break;
@@ -116,7 +121,8 @@ int main(int argc, char* argv[])
printf("usage: %s [-c <bytes>] [-b <bytes>|-p <percent>] [-v]\n", argv[0]);
printf("\t-c <num>\tsize of chunk in bytes to malloc on each pass\n");
printf("\t-b <bytes>\tmaximum number of bytes to allocate before stopping\n");
- printf("\t-p <bytes>\tpercent of total memory used at which the program stops\n");
+ printf("\t-p <percent>\tpercent of total memory used at which the program stops\n");
+ printf("\t-s <MBytes>\tstop when used swap is higher than <s> MB, default: 0 - no limit\n");
printf("\t-w\t\twrite to the memory after allocating\n");
printf("\t-v\t\tverbose\n");
printf("\t-h\t\tdisplay usage\n");
@@ -262,6 +268,13 @@ int main(int argc, char* argv[])
sysinfo(&sstats);
post_mem = (unsigned long long)sstats.mem_unit * sstats.freeram;
post_mem = post_mem + (unsigned long long)sstats.mem_unit * sstats.freeswap;
+
+ used_swap = sstats.mem_unit * (sstats.totalswap - sstats.freeswap);
+ if (swap_max > 0 && used_swap > swap_max) {
+ tst_resm(TINFO, "Reached max swap usage: %llu Mbytes > %llu MBytes",
+ used_swap / 1024 / 1024, swap_max / 1024 / 1024);
+ break;
+ }
}
}
while (pid_list[i] != 0) {
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list