add a testcase to test /proc/sys/vm/nr_hugepages vm tunable
PATCH v2 1/1 add a testcase to test /proc/sys/vm/nr_hugepages vm tunable
hi,I'd like to add several testcases to test vm tunable(/proc/sys/vm/*). the patch is designed to test nr_hugepages vm tunable, if you set nr_hugepages, you can find this change through /proc/meminfo <HighTotal: >
I will add more testcases for vm tunables in the few days.
v2: fixed the code style
--- runtest/mm | 3 + testcases/kernel/mem/vmtunable/Makefile | 28 ++++ testcases/kernel/mem/vmtunable/nr_hugepages.c | 184 +++++++++++++++++++++++++ 3 files changed, 215 insertions(+), 0 deletions(-) create mode 100644 testcases/kernel/mem/vmtunable/Makefile create mode 100644 testcases/kernel/mem/vmtunable/nr_hugepages.c
runtest/mm +3 -0
@@ -72,3 +72,6 @@ mmap10_4 mmap10 -a -s -c 60 ksm01 ksm01 cpuset01 cpuset01 -I 3600 + +# test for vm tunable +nr_hugepages nr_hugepages -i 5
testcases/kernel/mem/vmtunable/Makefile new file +28 -0
@@ -0,0 +1,28 @@ +# +# Copyright (C) 2010 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. +# + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/mem/vmtunable/nr_hugepages.c new file +184 -0
184 lines not on this page · raw message
Signature · 12 lines
1.7.2.3 ------------------------------------------------------------------------------ Lotusphere 2011 Register now for Lotusphere 2011 and learn how to connect the dots, take your collaborative environment to the next level, and enter the era of Social Business. http://p.sf.net/sfu/lotusphere-d2d _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Hi!
Quoted 29 lines
testcases/kernel/mem/vmtunable/nr_hugepages.c new file +29
-0+#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <unistd.h> +#include <fcntl.h> +#include <stdint.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <sys/types.h> + +#include "test.h" +#include "usctest.h" +#define BUFFER_SIZE 256 + +/* the HUGEPAGES is the value that I will set /proc/sys/vm/nr_hugepages, +* why I set HUGEPAGES 30, I think this value is appropriate. +* In general, all the systems can provide about 30 hugepages if they +* support hugepage, if you make a much larger value, it will cause +* shortage memory. +*/ +#define HUGEPAGES 30 + +char *TCID ="nr_hugepages" ; +int TST_TOTAL =1 ; + +/* set hugepages */ +int set_hugepages (int nr_hugepages); +/* get the total of hugepages and surplus hugepages */ +int get_hugepages (int *nr_hugepages);
testcases/kernel/mem/vmtunable/nr_hugepages.c line 76
Quoted 10 lines
testcases/kernel/mem/vmtunable/nr_hugepages.c new file +10
-0+ +/* check whether the /proc/sys/vm/nr_hugepages file exist +* if not, then the test can't run continue. +* */ +int check_system (); + +/* make some clean work. */ +void cleanup (); + +int old_hugepages =0 ;/* save the old nr_hugepages value */
Most of the comments here are meaningless. There is no need to write code like:
/* gets number */get_number();
or
/* does cleanup */cleanup();
And the prototypes are missing void as fn() says that function has variable number of int arguments. The right way to define function without any arguments is fn(void).
Quoted 5 lines
testcases/kernel/mem/vmtunable/nr_hugepages.c new file +5
-0+int main (int argc,char *argv[]) +{ +int lc =0 ;/* loop counter */ +char *msg;/* message returned from parse_opts */ +int counter =0 ;
testcases/kernel/mem/vmtunable/nr_hugepages.c line 92
Quoted 10 lines
testcases/kernel/mem/vmtunable/nr_hugepages.c new file +10
-0+int nr =10 ; +int hugepages =0 ; + +/* the test need to be run as root */ +tst_require_root (tst_exit); + +/* if check_system() return zero, +* the system can't support this test. +*/ +if (!check_system ()) {
Here again, the comments just says the same as the name of the function, please remove them.
Quoted 17 lines
testcases/kernel/mem/vmtunable/nr_hugepages.c new file +17
-0+tst_brkm (TCONF |TERRNO ,tst_exit,"Can't test %s, no such file" ,TCID ); + } + +if ((msg =parse_opts (argc, argv,NULL ,NULL )) !=NULL ) { +tst_brkm (TBROK , cleanup,"OPTION PARSING ERROR -%s " , msg); + } + +get_hugepages (&old_hugepages);/* save the original hugepages */ +tst_resm (TINFO ,"the original nr_hugepages is %d\n" , old_hugepages); + +for (lc =0 ;TEST_LOOPING (lc); lc++) { +/* try to set nr_hugepages from 30 to 39 */ +for ( counter =0 ; counter < nr; counter++ ) { +set_hugepages (HUGEPAGES + counter); +tst_resm (TINFO ,"set nr_hugepages %d" , +HUGEPAGES + counter); +get_hugepages (&hugepages);
testcases/kernel/mem/vmtunable/nr_hugepages.c line 119
Quoted 10 lines
testcases/kernel/mem/vmtunable/nr_hugepages.c new file +10
-0+if (hugepages !=HUGEPAGES + counter) { +set_hugepages (old_hugepages);/* recover the original value */ +tst_brkm (TFAIL , cleanup,"nr_hugepages error" ); + } + } + } + +tst_resm (TPASS ,"nr_hugepages succeed." ); + +set_hugepages (old_hugepages);/* recover the primary value */
The set_hugepages(old_hugepages) and get_hugepages(&old_hugepages) is descriptive enough.
Quoted 49 lines
testcases/kernel/mem/vmtunable/nr_hugepages.c new file +49
-0+cleanup (); +return 0 ; +} + +int get_hugepages (int *nr_hugepages) +{ +FILE *f; +int flag =0 ; +char buff[BUFFER_SIZE ]; + + f =fopen ("/proc/meminfo" ,"r" ); +if (f ==NULL ) { +tst_brkm (TBROK , cleanup,"open /proc/meminfo error" ); + } + +while (fgets (buff,BUFFER_SIZE , f) !=NULL ) { +if ((flag =sscanf (buff,"HugePages_Total: %d " , nr_hugepages)) ==1 ) +break ; + } + +/* if flag = 1, that indicates the sscanf() have gotten the HugePages_Total */ +if (flag !=1 ) { +fclose (f); +tst_brkm (TBROK , cleanup,"Failed reading Hugepages_Total." ); + } + +fclose (f); +return 0 ; +} + +int set_hugepages (int nr_hugepages) +{ +FILE *f ; + + f =fopen ("/proc/sys/vm/nr_hugepages" ,"w" ); +if (f ==NULL ) { +tst_brkm (TBROK , cleanup,"open /proc/sys/vm/nr_hugepages error" ); + } + +/* write nr_hugepages to /proc/sys/vm/nr_hugepages */ +if (fprintf (f,"%d" , nr_hugepages) <0 ) { +tst_brkm (TBROK , cleanup,"fprintf() error" ); + } + +fclose (f); +return 0 ; +} + +int check_system ()
testcases/kernel/mem/vmtunable/nr_hugepages.c line 178
Quoted 10 lines
testcases/kernel/mem/vmtunable/nr_hugepages.c new file +10
-0+{ +int flag =-1 ; + + flag =access ("/proc/sys/vm/nr_hugepages" ,F_OK ); +if (flag ==0 ) { +return 1 ;/* can access this file */ + }else { +return 0 ; + } +}
The comment here is useless as well. And personally I would omit curly brackets around one line code blocks.
testcases/kernel/mem/vmtunable/nr_hugepages.c line 184
Quoted 5 lines
testcases/kernel/mem/vmtunable/nr_hugepages.c new file +5
-0+void cleanup () +{ +set_hugepages (old_hugepages);/* recover the original data */ +tst_exit (); +}
And here too.
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ Learn how Oracle Real Application Clusters (RAC) One Node allows customers to consolidate database storage, standardize their database environment, and, should the need arise, upgrade to a full multi-node Oracle RAC database without downtime or disruption http://p.sf.net/sfu/oracle-sfdevnl _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list