From: Jan Stancek <jstancek@redhat.com>
To: ltp-list@lists.sourceforge.net
Subject: [LTP] [PATCH/RFC] mtest01: add option to limit max swap usage
Date: Tue, 13 Mar 2012 17:27:26 +0100 [thread overview]
Message-ID: <4F5F756E.4010808@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1009 bytes --]
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 <jstancek@redhat.com>
---
testcases/kernel/mem/mtest01/mtest01.c | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
[-- Attachment #2: 0001-mtest01-add-option-to-limit-max-swap-usage.patch --]
[-- Type: text/x-patch, Size: 2370 bytes --]
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) {
[-- Attachment #3: Type: text/plain, Size: 381 bytes --]
------------------------------------------------------------------------------
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
[-- Attachment #4: Type: text/plain, Size: 155 bytes --]
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next reply other threads:[~2012-03-13 16:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-13 16:27 Jan Stancek [this message]
2012-03-13 16:45 ` [LTP] [PATCH/RFC] mtest01: add option to limit max swap usage Caspar Zhang
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=4F5F756E.4010808@redhat.com \
--to=jstancek@redhat.com \
--cc=ltp-list@lists.sourceforge.net \
/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