thp/hzp: new case for Huge Zero Page testing
PATCH 1/1 thp/hzp: new case for Huge Zero Page testing
Huge Zero Page feature has been added in kernel-3.17, so I draft these testcase to cover it in LTP.
hzp01.sh: Checking if the HZP feature works well.
hzp02.sh: Checking if the HZP feature peformed well.
hzp03.sh: Do Huge Zero Page stress test.
Reference: https://lwn.net/Articles/525301/
--- runtest/mm | 4 ++ testcases/kernel/mem/thp/Makefile | 3 +- testcases/kernel/mem/thp/hzp/Makefile | 20 ++++++ testcases/kernel/mem/thp/hzp/hzp01.sh | 108 ++++++++++++++++++++++++++++++++ testcases/kernel/mem/thp/hzp/hzp02.sh | 93 +++++++++++++++++++++++++++ testcases/kernel/mem/thp/hzp/hzp03.sh | 54 ++++++++++++++++ testcases/kernel/mem/thp/hzp/hzp_lib.sh | 76 ++++++++++++++++++++++ testcases/kernel/mem/thp/hzp/memcmp01.c | 47 ++++++++++++++ testcases/kernel/mem/thp/hzp/memcmp02.c | 62 ++++++++++++++++++ 9 files changed, 466 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/mem/thp/hzp/Makefile create mode 100755 testcases/kernel/mem/thp/hzp/hzp01.sh create mode 100755 testcases/kernel/mem/thp/hzp/hzp02.sh create mode 100755 testcases/kernel/mem/thp/hzp/hzp03.sh create mode 100755 testcases/kernel/mem/thp/hzp/hzp_lib.sh create mode 100644 testcases/kernel/mem/thp/hzp/memcmp01.c create mode 100644 testcases/kernel/mem/thp/hzp/memcmp02.c
runtest/mm +4 -0
@@ -91,6 +91,10 @@ thp05_1 thp05 thp05_2 thp05 -n 10 -N 20 thp05_3 thp05 -n 1 -N 300 +hzp01 hzp01.sh +hzp02 hzp02.sh +hzp03 hzp03.sh + vma01 vma01 vma02 vma02 vma03 vma03
testcases/kernel/mem/thp/Makefile +2 -1
@@ -21,4 +21,5 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk -include $(top_srcdir)/include/mk/generic_leaf_target.mk +include $(top_srcdir)/include/mk/generic_trunk_target.mk +SUBDIRS := hzp
testcases/kernel/mem/thp/hzp/Makefile new file +20 -0
@@ -0,0 +1,20 @@ +# Copyright (c) 2015 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# 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. See the +# GNU General Public License for more details. +# +# 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 St, Fifth Floor, Boston, MA 02110-1301 USA + +top_srcdir ?= ../../../../.. +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk +INSTALL_TARGETS := *.sh
testcases/kernel/mem/thp/hzp/hzp01.sh new file +108 -0
108 lines not on this page · raw message
testcases/kernel/mem/thp/hzp/hzp02.sh new file +93 -0
93 lines not on this page · raw message
testcases/kernel/mem/thp/hzp/hzp03.sh new file +54 -0
54 lines not on this page · raw message
testcases/kernel/mem/thp/hzp/hzp_lib.sh new file +76 -0
76 lines not on this page · raw message
testcases/kernel/mem/thp/hzp/memcmp01.c new file +47 -0
47 lines not on this page · raw message
testcases/kernel/mem/thp/hzp/memcmp02.c new file +62 -0
62 lines not on this page · raw message
Signature · 8 lines
1.8.3.1 ------------------------------------------------------------------------------ _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
----- Original Message -----
Quoted 265 lines
Huge Zero Page feature has been added in kernel-3.17, so I draft these testcase to cover it in LTP.
hzp01.sh: Checking if the HZP feature works well.
hzp02.sh: Checking if the HZP feature peformed well.
hzp03.sh: Do Huge Zero Page stress test.Reference: https://lwn.net/Articles/525301/
Signed-off-by Li Wang <[email protected]>--- runtest/mm | 4 ++ testcases/kernel/mem/thp/Makefile | 3 +- testcases/kernel/mem/thp/hzp/Makefile | 20 ++++++ testcases/kernel/mem/thp/hzp/hzp01.sh | 108 ++++++++++++++++++++++++++++++++ testcases/kernel/mem/thp/hzp/hzp02.sh | 93 +++++++++++++++++++++++++++ testcases/kernel/mem/thp/hzp/hzp03.sh | 54 ++++++++++++++++ testcases/kernel/mem/thp/hzp/hzp_lib.sh | 76 ++++++++++++++++++++++ testcases/kernel/mem/thp/hzp/memcmp01.c | 47 ++++++++++++++ testcases/kernel/mem/thp/hzp/memcmp02.c | 62 ++++++++++++++++++ 9 files changed, 466 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/mem/thp/hzp/Makefile create mode 100755 testcases/kernel/mem/thp/hzp/hzp01.sh create mode 100755 testcases/kernel/mem/thp/hzp/hzp02.sh create mode 100755 testcases/kernel/mem/thp/hzp/hzp03.sh create mode 100755 testcases/kernel/mem/thp/hzp/hzp_lib.sh create mode 100644 testcases/kernel/mem/thp/hzp/memcmp01.c create mode 100644 testcases/kernel/mem/thp/hzp/memcmp02.cruntest/mm +4
-0@@ -91,6 +91,10 @@ thp05_1 thp05 thp05_2 thp05 -n 10 -N 20 thp05_3 thp05 -n 1 -N 300 +hzp01 hzp01.sh +hzp02 hzp02.sh +hzp03 hzp03.sh + vma01 vma01 vma02 vma02 vma03 vma03testcases/kernel/mem/thp/Makefile +2
-1@@ -21,4 +21,5 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk -include $(top_srcdir)/include/mk/generic_leaf_target.mk +include $(top_srcdir)/include/mk/generic_trunk_target.mk +SUBDIRS := hzptestcases/kernel/mem/thp/hzp/Makefile new file +20
-0@@ -0,0 +1,20 @@ +# Copyright (c) 2015 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# 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. See the +# GNU General Public License for more details. +# +# 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 St, Fifth Floor, Boston, MA 02110-1301 USA + +top_srcdir ?= ../../../../.. +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk +INSTALL_TARGETS := *.shtestcases/kernel/mem/thp/hzp/hzp01.sh new file +2
-0@@ -0,0 +1,108 @@ +#!/bin/bash +##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
testcases/kernel/mem/thp/hzp/hzp01.sh new file +16
-0+# # Copyright (C) 2015 Linux Test Project. +# # +# # Licensed under the GNU GPLv2 or later. +# # This program is free software; you can redistribute it and/or modify +# # it under the terms of the GNU General Public License as published by +# # the Free Software Foundation; either version 2 of the License, or +# # (at your option) any later version. +# # +# # This program is distributed in the hope that it will be useful, +# # but WITHOUT ANY WARRANTY; without even the implied warranty of +# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# # the GNU General Public License for more details. +# # +# # You should have received a copy of the GNU General Public License +# # along with this program; if not, write to the Free Software +# # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA
testcases/kernel/mem/thp/hzp/hzp01.sh new file +2
-0+# # +##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
testcases/kernel/mem/thp/hzp/hzp01.sh new file +3
-0+# # Description: +# # +# # This THP case measure the RSS size of test process memcmp01 on asystem with
+# # Huge Zero Page on/off. The size ofrss_offis absolutely larger than 100*rss_on,testcases/kernel/mem/thp/hzp/hzp01.sh new file +4
-0+# # eg. x86_64, the rss_on is about 400K, the rss_off is about 200M. +# # +# # Author: Li Wang <[email protected]> +##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
testcases/kernel/mem/thp/hzp/hzp01.sh new file +80
-0+ +export TCID="hzp01" +export TST_TOTAL=5 + +. test.sh +. hzp_lib.sh + +rss_off=-1 +rss_on=-1 + +hzp_off_test() +{ + # Testing with use_zero_page disable + hzp_off + + # Running the process in background + $TPATH/memcmp01 & >/dev/null + if [ $? -ne 0 ]; then + tst_brkm TBROK "failed to run the process in background." + fi + + sleep 2 + # Check the RSS size of test_memcmp01 + local pid=`pidof "$TPATH/memcmp01"` + rss_off=`pmap -x $pid | grep total | awk '{print $4}'` + tst_resm TINFO "rss_off= $rss_off K" + + # Kill the test process + kill $pid >/dev/null + if [ $? -ne 0 ]; then + tst_brkm TBROK "failed to kill the process." + fi +} + +hzp_on_test() +{ + # Testing with use_zero_page enable + hzp_on + + # Running the process in background + $TPATH/memcmp01 & >/dev/null + if [ $? -ne 0 ]; then + tst_brkm TBROK "failed to run the process in background." + fi + + sleep 2 + # Check the RSS size of test_memcmp01 + local pid=`pidof "$TPATH/memcmp01"` + rss_on=`pmap -x $pid | grep total | awk '{print $4}'` + tst_resm TINFO "rss_on= $rss_on K" + + kill $pid >/dev/null + if [ $? -ne 0 ]; then + tst_brkm TBROK "failed to kill the process." + fi +} + +rss_cmp() +{ + hzp_off_test + hzp_on_test + + # eg. rss_on is about 400k, rss_off is about 200M (arch: x86_64), + # so the size of rss_off should be absolutely lager than 100*rss_on + test_success=`echo "$rss_off > 100*$rss_on" |bc` + if [ $test_success -eq 1 ]; then + tst_resm TPASS "Huge Zero Page works well." + else + tst_resm TFAIL "Huge Zero Page works bad." + fi +} + +#--------Test Start---------- +hzp_setup + +rss_cmp + +hzp_cleanup + +tst_exittestcases/kernel/mem/thp/hzp/hzp02.sh new file +2
-0@@ -0,0 +1,93 @@ +#!/bin/bash +##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
testcases/kernel/mem/thp/hzp/hzp02.sh new file +16
-0+# # Copyright (C) 2015 Linux Test Project. +# # +# # Licensed under the GNU GPLv2 or later. +# # This program is free software; you can redistribute it and/or modify +# # it under the terms of the GNU General Public License as published by +# # the Free Software Foundation; either version 2 of the License, or +# # (at your option) any later version. +# # +# # This program is distributed in the hope that it will be useful, +# # but WITHOUT ANY WARRANTY; without even the implied warranty of +# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# # the GNU General Public License for more details. +# # +# # You should have received a copy of the GNU General Public License +# # along with this program; if not, write to the Free Software +# # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA
testcases/kernel/mem/thp/hzp/hzp02.sh new file +2
-0+# # +##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
testcases/kernel/mem/thp/hzp/hzp02.sh new file +8
-0+# # Description: +# # +# # This case measure the time consumption of test program memcmp02 on +# # a system with Huge Zero Page on/off, then judge if the HZP performance +# # well or not from the results comparison. +# # +# # Author: Li Wang <[email protected]> +##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
testcases/kernel/mem/thp/hzp/hzp02.sh new file +19
-0+ +export TCID="hzp02" +export TST_TOTAL=5 + +. test.sh +. hzp_lib.sh + +time_elapsed_off=-1 +time_elapsed_on=-1 + +mem_total=`grep MemTotal: /proc/meminfo |awk '{print $2}'` +mem_free=`grep MemFree: /proc/meminfo |awk '{print $2}'` + +tst_resm TINFO "mem_total= $mem_total kB, mem_free= $mem_free kB." + +# Configure Memory testing size +if [ $mem_total -gt 16777216 ]; then + MEM=10 + NUM=8
testcases/kernel/mem/thp/hzp/hzp02.sh line 57
Quoted 10 lines
testcases/kernel/mem/thp/hzp/hzp02.sh new file +10
-0+elif [ $mem_total -gt 8388608 ]; then + MEM=$(( $mem_free / 1024 / 1000 )) + NUM=$(( $MEM - 6 )) +elif [ $mem_total -gt 2097152 ]; then + MEM=2 + NUM=2 +else + tst_brkm TCONF "Sorry, the system RAM is too low to test." +fi +
Oops! Testing from myself, the hzp02.sh sometimes failed on a 15G ppc64 system. But the performance was still improved more. Maybe the $NUM should be declined here.
------------
# ./hzp02.sh hzp02 1 TINFO : mem_total= 16679488 kB, mem_free= 14739648 kB. hzp02 1 TINFO : time_elapse_off= 73.14 hzp02 1 TINFO : time_elapse_on= 20.47 hzp02 1 TFAIL : Huge Zero Page performed bad. hzp02 2 TINFO : hzp cleanup.
# free -h
total used free shared buff/cache available
Mem: 15G 303M 14G 4.9M 1.6G 14G
Swap: 8.0G 129M 7.9G
-----------Okay! I will post a V2 patch after getting some other comments.
Thanks,
Li Wang
Quoted 313 lines
testcases/kernel/mem/thp/hzp/hzp02.sh new file +36
-0+test_begin() +{ + # Testing with use_zero_page disable + hzp_off + (time -p taskset -c 0 $TPATH/memcmp02 $MEM) 2> memcmp_off.log + time_elapse_off=`grep real memcmp_off.log|awk '{print $2}'` + tst_resm TINFO "time_elapse_off= $time_elapse_off" + + # Testing with use_zero_page enable + hzp_on + (time -p taskset -c 0 $TPATH/memcmp02 $MEM) 2> memcmp_on.log + time_elapse_on=`grep real memcmp_on.log|awk '{print $2}'` + tst_resm TINFO "time_elapse_on= $time_elapse_on" +} + +test_result() +{ + # Compare the time cosumption with HZP on/off + test_success=`echo "$time_elapse_off > $NUM*$time_elapse_on" |bc` + if [ $test_success -eq 1 ]; then + tst_resm TPASS "Huge Zero Page performed well." + else + tst_resm TFAIL "Huge Zero Page performed bad." + fi +} + +#--------Test Start---------- +hzp_setup + +test_begin + +test_result + +hzp_cleanup + +tst_exittestcases/kernel/mem/thp/hzp/hzp03.sh new file +2
-0@@ -0,0 +1,54 @@ +#!/bin/bash +##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
testcases/kernel/mem/thp/hzp/hzp03.sh new file +16
-0+# # Copyright (C) 2015 Linux Test Project. +# # +# # Licensed under the GNU GPLv2 or later. +# # This program is free software; you can redistribute it and/or modify +# # it under the terms of the GNU General Public License as published by +# # the Free Software Foundation; either version 2 of the License, or +# # (at your option) any later version. +# # +# # This program is distributed in the hope that it will be useful, +# # but WITHOUT ANY WARRANTY; without even the implied warranty of +# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# # the GNU General Public License for more details. +# # +# # You should have received a copy of the GNU General Public License +# # along with this program; if not, write to the Free Software +# # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA
testcases/kernel/mem/thp/hzp/hzp03.sh new file +3
-0+# # +# # Author: Li Wang <[email protected]> +##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
testcases/kernel/mem/thp/hzp/hzp03.sh new file +33
-0+ +export TCID="hzp03" +export TST_TOTAL=1 + +. test.sh +. hzp_lib.sh + +MAX_LOOP=2000 +RC=0 + +hzp_stress_test() +{ + for ((i = 0; i < $MAX_LOOP; i++)) + { + hzp_on || RC=$? + hzp_off || RC=$? + } + + if [ $RC -eq 0 ]; then + tst_resm TPASS "finished running the stress test." + else + tst_resm TFAIL "please check log message." + fi +} + +#--------Test Start---------- +hzp_setup + +hzp_stress_test + +hzp_cleanup + +tst_exittestcases/kernel/mem/thp/hzp/hzp_lib.sh new file +2
-0@@ -0,0 +1,76 @@ +#!/bin/bash +##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
testcases/kernel/mem/thp/hzp/hzp_lib.sh new file +16
-0+# # Copyright (C) 2015 Linux Test Project. +# # +# # Licensed under the GNU GPLv2 or later. +# # This program is free software; you can redistribute it and/or modify +# # it under the terms of the GNU General Public License as published by +# # the Free Software Foundation; either version 2 of the License, or +# # (at your option) any later version. +# # +# # This program is distributed in the hope that it will be useful, +# # but WITHOUT ANY WARRANTY; without even the implied warranty of +# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# # the GNU General Public License for more details. +# # +# # You should have received a copy of the GNU General Public License +# # along with this program; if not, write to the Free Software +# # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA
testcases/kernel/mem/thp/hzp/hzp_lib.sh new file +3
-0+# # +# # Author: Li Wang <[email protected]> +##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
testcases/kernel/mem/thp/hzp/hzp_lib.sh new file +55
-0+ +trap tst_exit INT + +export TPATH="$PWD" +export THP_ENABLED="/sys/kernel/mm/transparent_hugepage/enabled" +export USE_ZERO_PAGE="/sys/kernel/mm/transparent_hugepage/use_zero_page" + +hzp=-1 + +hzp_on() +{ + echo 1 >$USE_ZERO_PAGE + if [ $? -ne 0 ]; then + tst_brkm TBROK "turn on hzp failed." + fi +} + +hzp_off() +{ + echo 0 >$USE_ZERO_PAGE + if [ $? -ne 0 ]; then + tst_brkm TBROK "turn off hzp failed." + fi +} + +hzp_setup() +{ + tst_require_root + + # Check to see huge zero page feature is supported or not + if [ ! -f $USE_ZERO_PAGE ];then + tst_brkm TCONF "The huge zero page is not supported. Skip the test..." + fi + + echo always >$THP_ENABLED + if [ $? -ne 0 ]; then + tst_brkm TBROK "Enable the THP option failed." + fi + + # Save the original value of $USE_ZERO_PAGE + hzp=`cat $USE_ZERO_PAGE` + + tst_tmpdir +} + +hzp_cleanup() +{ + tst_resm TINFO "hzp cleanup." + + # Reset the $USE_ZERO_PAGE to original value + echo $hzp >$USE_ZERO_PAGE + rm -f *.log + + tst_rmdir +}testcases/kernel/mem/thp/hzp/memcmp01.c new file +47
-0@@ -0,0 +1,47 @@ +/* +* Copyright (C) 2015 Linux Test Project. +* +* Author: Kirill A. Shutemov <[email protected]> +* Modify: Li Wang <[email protected]> +* +*/ + +#include <stdio.h> +#include <string.h> +#include <assert.h> +#include <stdlib.h> +#include <unistd.h> + +#define MB (1UL << 20) + +#ifdef __i386__ || __x86_64__ +#define HPAGE_SIZE (2 * MB) + +#elif __powerpc__ || __powerpc64__ +#define HPAGE_SIZE (16 * MB) + +#elif __s390__ || __s390x__ +#define HPAGE_SIZE (1 * MB) + +#else +#define HPAGE_SIZE (2 * MB) +#endif + +int main (void ) +{ +char *p; +unsigned long i; +int ret; + + ret =posix_memalign ((void **)&p,HPAGE_SIZE ,100 *HPAGE_SIZE ); +if (ret) { +fprintf (stderr,"posix_memalign: %s\n" , +strerror (ret)); +return -1 ; + } + +for (i =0 ; i <100 *HPAGE_SIZE ; i +=4096 ) +assert (p[i] ==0 ); +pause (); +return 0 ; +}testcases/kernel/mem/thp/hzp/memcmp02.c new file +62
-1@@ -0,0 +1,62 @@ +/* +* Copyright (C) 2015 Linux Test Project. +* +* Author: Kirill A. Shutemov <[email protected]> +* Modify: Li Wang <[email protected]> +* +*/ + +#include <assert.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> + +#define MB (1UL << 20) +#define GB (1UL << 30) + +#ifdef __i386__ || __x86_64__ +#define HPAGE_SIZE (2 * MB) + +#elif __powerpc__ || __powerpc64__ +#define HPAGE_SIZE (16 * MB) + +#elif __s390__ || __s390x__ +#define HPAGE_SIZE (1 * MB) + +#else +#define HPAGE_SIZE (2 * MB) +#endif + +int main (int argc,char **argv) +{ +char *p; +int i, ret; +int N =atoi (argv[1 ]); + +if (N <1 ) { +fprintf (stderr,"Invalid argument\n" ); +exit (1 ); + } + + ret =posix_memalign ((void **)&p,HPAGE_SIZE ,N *GB ); +if (ret) { +fprintf (stderr,"posix_memalign: %s\n" , +strerror (ret)); +return -1 ; + } + +for (i =0 ; i <1000 ; i++) { +char *_p = p; + +while (_p < p+N /2 *GB ) { +assert (*_p == *(_p+N /2 *GB )); + _p +=4096 ; + asmvolatile ("" : : :"memory" ); + } + } + +free (p); + +return 0 ; +} --1.8.3.1
Quoted 6 lines
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Hi!
Ccing kernel mm devs.
Quoted 568 lines
Huge Zero Page feature has been added in kernel-3.17, so I draft these testcase to cover it in LTP.
hzp01.sh: Checking if the HZP feature works well.
hzp02.sh: Checking if the HZP feature peformed well.
hzp03.sh: Do Huge Zero Page stress test.Reference: https://lwn.net/Articles/525301/
Signed-off-by Li Wang <[email protected]>--- runtest/mm | 4 ++ testcases/kernel/mem/thp/Makefile | 3 +- testcases/kernel/mem/thp/hzp/Makefile | 20 ++++++ testcases/kernel/mem/thp/hzp/hzp01.sh | 108 ++++++++++++++++++++++++++++++++ testcases/kernel/mem/thp/hzp/hzp02.sh | 93 +++++++++++++++++++++++++++ testcases/kernel/mem/thp/hzp/hzp03.sh | 54 ++++++++++++++++ testcases/kernel/mem/thp/hzp/hzp_lib.sh | 76 ++++++++++++++++++++++ testcases/kernel/mem/thp/hzp/memcmp01.c | 47 ++++++++++++++ testcases/kernel/mem/thp/hzp/memcmp02.c | 62 ++++++++++++++++++ 9 files changed, 466 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/mem/thp/hzp/Makefile create mode 100755 testcases/kernel/mem/thp/hzp/hzp01.sh create mode 100755 testcases/kernel/mem/thp/hzp/hzp02.sh create mode 100755 testcases/kernel/mem/thp/hzp/hzp03.sh create mode 100755 testcases/kernel/mem/thp/hzp/hzp_lib.sh create mode 100644 testcases/kernel/mem/thp/hzp/memcmp01.c create mode 100644 testcases/kernel/mem/thp/hzp/memcmp02.cruntest/mm +4
-0@@ -91,6 +91,10 @@ thp05_1 thp05 thp05_2 thp05 -n 10 -N 20 thp05_3 thp05 -n 1 -N 300 +hzp01 hzp01.sh +hzp02 hzp02.sh +hzp03 hzp03.sh + vma01 vma01 vma02 vma02 vma03 vma03testcases/kernel/mem/thp/Makefile +2
-1@@ -21,4 +21,5 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk -include $(top_srcdir)/include/mk/generic_leaf_target.mk +include $(top_srcdir)/include/mk/generic_trunk_target.mk +SUBDIRS := hzptestcases/kernel/mem/thp/hzp/Makefile new file +20
-0@@ -0,0 +1,20 @@ +# Copyright (c) 2015 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# 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. See the +# GNU General Public License for more details. +# +# 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 St, Fifth Floor, Boston, MA 02110-1301 USA + +top_srcdir ?= ../../../../.. +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk +INSTALL_TARGETS := *.shtestcases/kernel/mem/thp/hzp/hzp01.sh new file +108
-0@@ -0,0 +1,108 @@ +#!/bin/bash +# #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# # Copyright (C) 2015 Linux Test Project. +# # +# # Licensed under the GNU GPLv2 or later. +# # This program is free software; you can redistribute it and/or modify +# # it under the terms of the GNU General Public License as published by +# # the Free Software Foundation; either version 2 of the License, or +# # (at your option) any later version. +# # +# # This program is distributed in the hope that it will be useful, +# # but WITHOUT ANY WARRANTY; without even the implied warranty of +# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# # the GNU General Public License for more details. +# # +# # You should have received a copy of the GNU General Public License +# # along with this program; if not, write to the Free Software +# # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# # +# #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# # Description: +# # +# # This THP case measure the RSS size of test process memcmp01 on a system with +# # Huge Zero Page on/off. The size of rss_off is absolutely larger than 100*rss_on, +# # eg. x86_64, the rss_on is about 400K, the rss_off is about 200M. +# # +# # Author: Li Wang <[email protected]> +# #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TCID="hzp01" +export TST_TOTAL=5 + +. test.sh +. hzp_lib.sh + +rss_off=-1 +rss_on=-1 + +hzp_off_test() +{ + # Testing with use_zero_page disable + hzp_off + + # Running the process in background + $TPATH/memcmp01 & >/dev/null + if [ $? -ne 0 ]; then + tst_brkm TBROK "failed to run the process in background." + fi + + sleep 2 + # Check the RSS size of test_memcmp01 + local pid=`pidof "$TPATH/memcmp01"` + rss_off=`pmap -x $pid | grep total | awk '{print $4}'` + tst_resm TINFO "rss_off= $rss_off K" + + # Kill the test process + kill $pid >/dev/null + if [ $? -ne 0 ]; then + tst_brkm TBROK "failed to kill the process." + fi +} + +hzp_on_test() +{ + # Testing with use_zero_page enable + hzp_on + + # Running the process in background + $TPATH/memcmp01 & >/dev/null + if [ $? -ne 0 ]; then + tst_brkm TBROK "failed to run the process in background." + fi + + sleep 2 + # Check the RSS size of test_memcmp01 + local pid=`pidof "$TPATH/memcmp01"` + rss_on=`pmap -x $pid | grep total | awk '{print $4}'` + tst_resm TINFO "rss_on= $rss_on K" + + kill $pid >/dev/null + if [ $? -ne 0 ]; then + tst_brkm TBROK "failed to kill the process." + fi +} + +rss_cmp() +{ + hzp_off_test + hzp_on_test + + # eg. rss_on is about 400k, rss_off is about 200M (arch: x86_64), + # so the size of rss_off should be absolutely lager than 100*rss_on + test_success=`echo "$rss_off > 100*$rss_on" |bc` + if [ $test_success -eq 1 ]; then + tst_resm TPASS "Huge Zero Page works well." + else + tst_resm TFAIL "Huge Zero Page works bad." + fi +} + +#--------Test Start---------- +hzp_setup + +rss_cmp + +hzp_cleanup + +tst_exittestcases/kernel/mem/thp/hzp/hzp02.sh new file +93
-0@@ -0,0 +1,93 @@ +#!/bin/bash +# #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# # Copyright (C) 2015 Linux Test Project. +# # +# # Licensed under the GNU GPLv2 or later. +# # This program is free software; you can redistribute it and/or modify +# # it under the terms of the GNU General Public License as published by +# # the Free Software Foundation; either version 2 of the License, or +# # (at your option) any later version. +# # +# # This program is distributed in the hope that it will be useful, +# # but WITHOUT ANY WARRANTY; without even the implied warranty of +# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# # the GNU General Public License for more details. +# # +# # You should have received a copy of the GNU General Public License +# # along with this program; if not, write to the Free Software +# # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# # +# #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# # Description: +# # +# # This case measure the time consumption of test program memcmp02 on +# # a system with Huge Zero Page on/off, then judge if the HZP performance +# # well or not from the results comparison. +# # +# # Author: Li Wang <[email protected]> +# #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TCID="hzp02" +export TST_TOTAL=5 + +. test.sh +. hzp_lib.sh + +time_elapsed_off=-1 +time_elapsed_on=-1 + +mem_total=`grep MemTotal: /proc/meminfo |awk '{print $2}'` +mem_free=`grep MemFree: /proc/meminfo |awk '{print $2}'` + +tst_resm TINFO "mem_total= $mem_total kB, mem_free= $mem_free kB." + +# Configure Memory testing size +if [ $mem_total -gt 16777216 ]; then + MEM=10 + NUM=8 +elif [ $mem_total -gt 8388608 ]; then + MEM=$(( $mem_free / 1024 / 1000 )) + NUM=$(( $MEM - 6 )) +elif [ $mem_total -gt 2097152 ]; then + MEM=2 + NUM=2 +else + tst_brkm TCONF "Sorry, the system RAM is too low to test." +fi + +test_begin() +{ + # Testing with use_zero_page disable + hzp_off + (time -p taskset -c 0 $TPATH/memcmp02 $MEM) 2> memcmp_off.log + time_elapse_off=`grep real memcmp_off.log|awk '{print $2}'` + tst_resm TINFO "time_elapse_off= $time_elapse_off" + + # Testing with use_zero_page enable + hzp_on + (time -p taskset -c 0 $TPATH/memcmp02 $MEM) 2> memcmp_on.log + time_elapse_on=`grep real memcmp_on.log|awk '{print $2}'` + tst_resm TINFO "time_elapse_on= $time_elapse_on" +} + +test_result() +{ + # Compare the time cosumption with HZP on/off + test_success=`echo "$time_elapse_off > $NUM*$time_elapse_on" |bc` + if [ $test_success -eq 1 ]; then + tst_resm TPASS "Huge Zero Page performed well." + else + tst_resm TFAIL "Huge Zero Page performed bad." + fi +} + +#--------Test Start---------- +hzp_setup + +test_begin + +test_result + +hzp_cleanup + +tst_exittestcases/kernel/mem/thp/hzp/hzp03.sh new file +54
-0@@ -0,0 +1,54 @@ +#!/bin/bash +# #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# # Copyright (C) 2015 Linux Test Project. +# # +# # Licensed under the GNU GPLv2 or later. +# # This program is free software; you can redistribute it and/or modify +# # it under the terms of the GNU General Public License as published by +# # the Free Software Foundation; either version 2 of the License, or +# # (at your option) any later version. +# # +# # This program is distributed in the hope that it will be useful, +# # but WITHOUT ANY WARRANTY; without even the implied warranty of +# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# # the GNU General Public License for more details. +# # +# # You should have received a copy of the GNU General Public License +# # along with this program; if not, write to the Free Software +# # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# # +# # Author: Li Wang <[email protected]> +# #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TCID="hzp03" +export TST_TOTAL=1 + +. test.sh +. hzp_lib.sh + +MAX_LOOP=2000 +RC=0 + +hzp_stress_test() +{ + for ((i = 0; i < $MAX_LOOP; i++)) + { + hzp_on || RC=$? + hzp_off || RC=$? + } + + if [ $RC -eq 0 ]; then + tst_resm TPASS "finished running the stress test." + else + tst_resm TFAIL "please check log message." + fi +} + +#--------Test Start---------- +hzp_setup + +hzp_stress_test + +hzp_cleanup + +tst_exittestcases/kernel/mem/thp/hzp/hzp_lib.sh new file +76
-0@@ -0,0 +1,76 @@ +#!/bin/bash +# #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# # Copyright (C) 2015 Linux Test Project. +# # +# # Licensed under the GNU GPLv2 or later. +# # This program is free software; you can redistribute it and/or modify +# # it under the terms of the GNU General Public License as published by +# # the Free Software Foundation; either version 2 of the License, or +# # (at your option) any later version. +# # +# # This program is distributed in the hope that it will be useful, +# # but WITHOUT ANY WARRANTY; without even the implied warranty of +# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# # the GNU General Public License for more details. +# # +# # You should have received a copy of the GNU General Public License +# # along with this program; if not, write to the Free Software +# # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# # +# # Author: Li Wang <[email protected]> +# #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +trap tst_exit INT + +export TPATH="$PWD" +export THP_ENABLED="/sys/kernel/mm/transparent_hugepage/enabled" +export USE_ZERO_PAGE="/sys/kernel/mm/transparent_hugepage/use_zero_page" + +hzp=-1 + +hzp_on() +{ + echo 1 >$USE_ZERO_PAGE + if [ $? -ne 0 ]; then + tst_brkm TBROK "turn on hzp failed." + fi +} + +hzp_off() +{ + echo 0 >$USE_ZERO_PAGE + if [ $? -ne 0 ]; then + tst_brkm TBROK "turn off hzp failed." + fi +} + +hzp_setup() +{ + tst_require_root + + # Check to see huge zero page feature is supported or not + if [ ! -f $USE_ZERO_PAGE ];then + tst_brkm TCONF "The huge zero page is not supported. Skip the test..." + fi + + echo always >$THP_ENABLED + if [ $? -ne 0 ]; then + tst_brkm TBROK "Enable the THP option failed." + fi + + # Save the original value of $USE_ZERO_PAGE + hzp=`cat $USE_ZERO_PAGE` + + tst_tmpdir +} + +hzp_cleanup() +{ + tst_resm TINFO "hzp cleanup." + + # Reset the $USE_ZERO_PAGE to original value + echo $hzp >$USE_ZERO_PAGE + rm -f *.log + + tst_rmdir +}testcases/kernel/mem/thp/hzp/memcmp01.c new file +47
-0@@ -0,0 +1,47 @@ +/* +* Copyright (C) 2015 Linux Test Project. +* +* Author: Kirill A. Shutemov <[email protected]> +* Modify: Li Wang <[email protected]> +* +*/ + +#include <stdio.h> +#include <string.h> +#include <assert.h> +#include <stdlib.h> +#include <unistd.h> + +#define MB (1UL << 20) + +#ifdef __i386__ || __x86_64__ +#define HPAGE_SIZE (2 * MB) + +#elif __powerpc__ || __powerpc64__ +#define HPAGE_SIZE (16 * MB) + +#elif __s390__ || __s390x__ +#define HPAGE_SIZE (1 * MB) + +#else +#define HPAGE_SIZE (2 * MB) +#endif + +int main (void ) +{ +char *p; +unsigned long i; +int ret; + + ret =posix_memalign ((void **)&p,HPAGE_SIZE ,100 *HPAGE_SIZE ); +if (ret) { +fprintf (stderr,"posix_memalign: %s\n" , +strerror (ret)); +return -1 ; + } + +for (i =0 ; i <100 *HPAGE_SIZE ; i +=4096 ) +assert (p[i] ==0 ); +pause (); +return 0 ; +}testcases/kernel/mem/thp/hzp/memcmp02.c new file +62
-0@@ -0,0 +1,62 @@ +/* +* Copyright (C) 2015 Linux Test Project. +* +* Author: Kirill A. Shutemov <[email protected]> +* Modify: Li Wang <[email protected]> +* +*/ + +#include <assert.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> + +#define MB (1UL << 20) +#define GB (1UL << 30) + +#ifdef __i386__ || __x86_64__ +#define HPAGE_SIZE (2 * MB) + +#elif __powerpc__ || __powerpc64__ +#define HPAGE_SIZE (16 * MB) + +#elif __s390__ || __s390x__ +#define HPAGE_SIZE (1 * MB) + +#else +#define HPAGE_SIZE (2 * MB) +#endif + +int main (int argc,char **argv) +{ +char *p; +int i, ret; +int N =atoi (argv[1 ]); + +if (N <1 ) { +fprintf (stderr,"Invalid argument\n" ); +exit (1 ); + } + + ret =posix_memalign ((void **)&p,HPAGE_SIZE ,N *GB ); +if (ret) { +fprintf (stderr,"posix_memalign: %s\n" , +strerror (ret)); +return -1 ; + } + +for (i =0 ; i <1000 ; i++) { +char *_p = p; + +while (_p < p+N /2 *GB ) { +assert (*_p == *(_p+N /2 *GB )); + _p +=4096 ; + asmvolatile ("" : : :"memory" ); + } + } + +free (p); + +return 0 ; +}Signature · 8 lines
1.8.3.1 ------------------------------------------------------------------------------ _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Signature · 8 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list