From: Wanlong Gao <gaowanlong@cn.fujitsu.com>
To: Zhouping Liu <zliu@redhat.com>
Cc: LTP list <ltp-list@lists.sourceforge.net>
Subject: Re: [LTP] [PATCH] mm/tunable: add a new testcase min_free_kbytes
Date: Thu, 22 Mar 2012 21:32:56 +0800 [thread overview]
Message-ID: <4F6B2A08.5070709@cn.fujitsu.com> (raw)
In-Reply-To: <87ae50f292bc2e82ecdd1fefe2db0dd41d6026a4.1332395878.git.zliu@redhat.com>
On 03/22/2012 02:35 PM, Zhouping Liu wrote:
> The case is designed to test min_free_kbytes tunable file.
>
> The tune is used to control free memory, and system always
> reserve min_free_kbytes memory at least.
>
> Since the tune is not too large or too little, which will
> lead to the system hang, so I choose two cases, and test them
> on all overcommit_memory policy, at the same time, compare
> the current free memory with the tunable value repeatedly.
>
> a) default min_free_kbytes with all overcommit memory policy
> b) half of mem_free with all overcommit memory policy
Looks good and test OK to me. thanks,
Reviewed-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
>
> Signed-off-by: Zhouping Liu <zliu@redhat.com>
> ---
> runtest/mm | 2 +
> testcases/kernel/mem/tunable/min_free_kbytes.c | 222 ++++++++++++++++++++++++
> 2 files changed, 224 insertions(+), 0 deletions(-)
> create mode 100644 testcases/kernel/mem/tunable/min_free_kbytes.c
>
> I have tested on RHEL6.2, it's fine, log like this:
> <<<test_start>>>
> tag=min_free_kbytes stime=1332315788
> cmdline="min_free_kbytes"
> contacts=""
> analysis=exit
> <<<test_output>>>
> min_free_kbytes 0 TINFO : set overcommit_memory to 2
> min_free_kbytes 0 TINFO : set min_free_kbytes to 90112
> min_free_kbytes 0 TINFO : MemFree is 15397328 kB before eatup mem
> min_free_kbytes 0 TINFO : MemFree is 151964 kB after eatup mem
> min_free_kbytes 0 TINFO : set min_free_kbytes to 90112
> min_free_kbytes 0 TINFO : set min_free_kbytes to 7999962
> min_free_kbytes 0 TINFO : MemFree is 15999924 kB before eatup mem
> min_free_kbytes 0 TINFO : MemFree is 8044308 kB after eatup mem
> min_free_kbytes 0 TINFO : set min_free_kbytes to 90112
> min_free_kbytes 0 TINFO : set min_free_kbytes to 7999962
> min_free_kbytes 0 TINFO : set overcommit_memory to 0
> min_free_kbytes 0 TINFO : set min_free_kbytes to 90112
> Child[26301] is killed by SIGKILL signal.
> min_free_kbytes 0 TINFO : set min_free_kbytes to 8002878
> Child[27570] is killed by SIGKILL signal.
> min_free_kbytes 0 TINFO : set overcommit_memory to 1
> min_free_kbytes 0 TINFO : set min_free_kbytes to 90112
> Child[28782] is killed by SIGKILL signal.
> min_free_kbytes 0 TINFO : set min_free_kbytes to 8003788
> Child[30056] is killed by SIGKILL signal.
> min_free_kbytes 0 TINFO : set min_free_kbytes to 90112
> min_free_kbytes 0 TINFO : set overcommit_memory to 0
>
> diff --git a/runtest/mm b/runtest/mm
> index be3b342..2dd66f0 100644
> --- a/runtest/mm
> +++ b/runtest/mm
> @@ -98,3 +98,5 @@ overcommit_memory overcommit_memory -R 100
> overcommit_memory overcommit_memory -R 200
>
> max_map_count max_map_count -i 10
> +
> +min_free_kbytes min_free_kbytes
> diff --git a/testcases/kernel/mem/tunable/min_free_kbytes.c b/testcases/kernel/mem/tunable/min_free_kbytes.c
> new file mode 100644
> index 0000000..722a56a
> --- /dev/null
> +++ b/testcases/kernel/mem/tunable/min_free_kbytes.c
> @@ -0,0 +1,222 @@
> +/*
> + * The case is designed to test min_free_kbytes tunable.
> + *
> + * The tune is used to control free memory, and system always
> + * reserve min_free_kbytes memory at least.
> + *
> + * Since the tune is not too large or too little, which will
> + * lead to the system hang, so I choose two cases, and test them
> + * on all overcommit_memory policy, at the same time, compare
> + * the current free memory with the tunable value repeatedly.
> + *
> + * a) default min_free_kbytes with all overcommit memory policy
> + * b) half of mem_free with all overcommit memory policy
> + *
> + ********************************************************************
> + * Copyright (C) 2012 Red Hat, Inc.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of version 2 of the GNU General Public
> + * License as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it would be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + * Further, this software is distributed without any warranty that it
> + * is free of the rightful claim of any third person regarding
> + * infringement or the like. Any license provided herein, whether
> + * implied or otherwise, applies only to this software file. Patent
> + * licenses, if any, provided herein do not apply to combinations of
> + * this program with other software, or any other product whatsoever.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> + * 02110-1301, USA.
> + *
> + * ********************************************************************
> + */
> +
> +#include <sys/types.h>
> +#include <sys/mman.h>
> +#include <sys/wait.h>
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include "test.h"
> +#include "usctest.h"
> +#include "../include/mem.h"
> +
> +#define MAP_SIZE (1UL<<20)
> +
> +char *TCID = "min_free_kbytes";
> +int TST_TOTAL = 1;
> +static unsigned long default_tune;
> +static unsigned long orig_overcommit;
> +static unsigned long total_mem;
> +
> +static void test_tune(unsigned long overcommit_policy);
> +static void eatup_mem();
> +static void check_monitor(void);
> +
> +int main(int argc, char *argv[])
> +{
> + char *msg;
> + int lc;
> +
> + msg = parse_opts(argc, argv, NULL, NULL);
> + if (msg != NULL)
> + tst_brkm(TBROK, NULL, "OPTION PARSING ERROR -s %s", msg);
> + setup();
> +
> + for (lc = 0; TEST_LOOPING(lc); lc++) {
> + Tst_count = 0;
> +
> + test_tune(2);
> + test_tune(0);
> + test_tune(1);
> + }
> +
> + cleanup();
> + tst_exit();
> +}
> +
> +static void test_tune(unsigned long overcommit_policy)
> +{
> + int status;
> + int pid[2];
> + unsigned long tune, memfree;
> +
> + set_sys_tune("overcommit_memory", overcommit_policy, 1);
> +
> + fflush(stdout);
> + switch (pid[0] = fork()) {
> + case -1:
> + tst_brkm(TBROK|TERRNO, cleanup, "fork");
> +
> + case 0:
> + /* startup the check monitor */
> + check_monitor();
> + }
> +
> + fflush(stdout);
> + switch (pid[1] = fork()) {
> + case -1:
> + tst_brkm(TBROK|TERRNO, cleanup, "fork");
> + case 0:
> +
> + /* case1 */
> + set_sys_tune("min_free_kbytes", default_tune, 1);
> + eatup_mem();
> +
> + /* case2 */
> + memfree = read_meminfo("MemFree:");
> + tune = memfree / 2;
> + set_sys_tune("min_free_kbytes", tune, 1);
> + eatup_mem();
> +
> + exit(0);
> + }
> +
> + if (waitpid(pid[1], &status, 0) == -1)
> + tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
> +
> + /* send SIGKILL to end up check_monitor thread */
> + if (kill(pid[0], SIGKILL) == -1)
> + tst_brkm(TBROK|TERRNO, cleanup, "kill %d", pid[0]);
> + if (waitpid(pid[0], &status, 0) == -1)
> + tst_brkm(TBROK|TERRNO, cleanup,
> + "check_monitor thread didn't end up");
> +}
> +
> +static void eatup_mem()
> +{
> + int map_count, i;
> + int status, pid;
> + unsigned long memfree;
> + void **addrs;
> +
> + map_count = total_mem * KB / MAP_SIZE;
> + addrs = (void **)malloc(map_count * sizeof(void *));
> +
> + switch (pid = fork()) {
> + case -1:
> + tst_brkm(TBROK | TERRNO, cleanup, "fork");
> + case 0:
> + memfree = read_meminfo("MemFree:");
> + tst_resm(TINFO, "MemFree is %lu kB before eatup mem", memfree);
> +
> + for (i = 0; i < map_count; i++) {
> + addrs[i] = mmap(NULL, MAP_SIZE, PROT_READ|PROT_WRITE,
> + MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
> + if (addrs[i] == MAP_FAILED) {
> + map_count = i - 1;
> + break;
> + }
> +
> + memset(addrs[i], i, MAP_SIZE);
> + }
> +
> + memfree = read_meminfo("MemFree:");
> + tst_resm(TINFO, "MemFree is %lu kB after eatup mem", memfree);
> +
> + for (i = 0; i < map_count; i++)
> + if (munmap(addrs[i], MAP_SIZE) != 0)
> + tst_brkm(TBROK|TERRNO, cleanup, "munmap");
> + free(addrs);
> + exit(0);
> + default:
> + if (waitpid(pid, &status, 0) == -1)
> + tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
> + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
> + if (WIFSIGNALED(status)
> + && WTERMSIG(status) == SIGKILL)
> + printf("Child[%d] is killed by "
> + "SIGKILL signal.\n", pid);
> + else
> + tst_resm(TFAIL, "Child[%d] "
> + "failed unexpectedly", pid);
> + }
> + }
> +}
> +
> +static void check_monitor(void)
> +{
> + unsigned long tune;
> + unsigned long memfree;
> +
> + while (1) {
> + memfree = read_meminfo("MemFree:");
> + tune = get_sys_tune("min_free_kbytes");
> +
> + if (memfree < tune) {
> + tst_resm(TINFO, "MemFree is %lu kB, "
> + "min_free_kbytes is %lu kB", memfree, tune);
> + tst_resm(TFAIL, "MemFree < min_free_kbytes");
> + }
> +
> + sleep(2);
> + }
> +}
> +
> +void setup(void)
> +{
> + tst_require_root(NULL);
> + tst_sig(FORK, DEF_HANDLER, cleanup);
> + TEST_PAUSE;
> +
> + total_mem = read_meminfo("MemTotal:") + read_meminfo("SwapTotal:");
> +
> + default_tune = get_sys_tune("min_free_kbytes");
> + orig_overcommit = get_sys_tune("overcommit_memory");
> +}
> +
> +void cleanup()
> +{
> + set_sys_tune("min_free_kbytes", default_tune, 0);
> + set_sys_tune("overcommit_memory", orig_overcommit, 0);
> +
> + TEST_CLEANUP;
> +}
------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next prev parent reply other threads:[~2012-03-22 13:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-22 6:35 [LTP] [PATCH] mm/tunable: add a new testcase min_free_kbytes Zhouping Liu
2012-03-22 13:32 ` Wanlong Gao [this message]
2012-03-23 14:16 ` ZhoupingLiu
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=4F6B2A08.5070709@cn.fujitsu.com \
--to=gaowanlong@cn.fujitsu.com \
--cc=ltp-list@lists.sourceforge.net \
--cc=zliu@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.