Change memory units to MB to support embedded devices
PATCH 1/1 Change memory units to MB to support embedded devices
This patch made two changes: 1) check the available memory before to perform the test case, and 2) change the memory units from GB to MB.
Both changes are needed during testing on embedded devices with RAM memory limitation (i.e. 512MB)
This patch no changed the test case procedure and the default memory size is the same (1GB=1000MB).
To use this test case in embedded devices, I suggest to change the testrun 'mm' as below from: "mtest06_2 mmap2 -x 0.002 -a -p" to "mtest06_2 mmap2 -x 0.002 -a -p -s 100"
--- testcases/kernel/mem/mtest06/mmap2.c | 40 +++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-)
testcases/kernel/mem/mtest06/mmap2.c +28 -12
@@ -48,9 +48,9 @@/* */ /* Description: Test the LINUX memory manager. The program is aimed at */ /* stressing the memory manager by repeaded map/write/unmap of a */ -/* of a large gb size file. */ +/* large mb size file. */ /* */ -/* Create a file of the specified size in gb, map the file, */ +/* Create a file of the specified size in mb, map the file, */ /* change the contents of the file and unmap it. This is repeated*/ /* several times for the specified number of hours. */ /* */
@@ -73,7 +73,7 @@#include <getopt.h> #include "test.h" -#define GB 1000000000 +#define MB 1048576#ifndef TRUE #define TRUE 1#endif
@@ -99,7 +99,7 @@ static int mkfile(int size)fprintf (stdout,"creating tmp file and writing 'a' to it " ); } -while (index < (size *GB )) { +while (index < (size *MB )) { index +=4096 ;if (write (fd, buff,4096 ) ==-1 ) {perror ("mkfile(): write()" );
@@ -136,16 +136,24 @@ static void usage(char *progname)"\t -p set map_flag to MAP_PRIVATE.\tdefault:" "MAP_SHARED\n" "\t -s size of the file/memory to be mmaped.\tdefault:" -"1GB\n" +"1000MB\n" "\t -x time for which test is to be run.\tdefault:" "24 Hrs\n", progname);exit (-1 ); } +long get_available_memory_mb (void ) +{ +unsigned long long ps, pn; + ps =sysconf (_SC_PAGESIZE); + pn =sysconf (_SC_AVPHYS_PAGES); +return ps * pn / (1024 *1024 ); +} +int main (int argc,char **argv) {int fd; -int fsize =1 ; +int fsize =1000 ;float exec_time =24 ;int c;int sig_ndx;
@@ -153,6 +161,7 @@ int main(int argc, char **argv)int map_anon = FALSE;int run_once = TRUE;char *memptr; +long avail_memory_mb;struct sigaction sigptr; static struct signal_info {
@@ -188,7 +197,7 @@ int main(int argc, char **argv) fsize =atoi (optarg);if (fsize ==0 )fprintf (stderr,"Using default " -"fsize %d GB\n" , fsize =1 ); +"fsize %d MB\n" , fsize =1000 );break ;case 'x' : exec_time =atof (optarg);
@@ -205,7 +214,14 @@ int main(int argc, char **argv)fprintf (stdout,"MM Stress test, map/write/unmap large file\n" "\tTest scheduled to run for: %f\n" -"\tSize of temp file in GB: %d\n" , exec_time, fsize); +"\tSize of temp file in MB: %d\n" , exec_time, fsize); + + avail_memory_mb =get_available_memory_mb (); +fprintf (stdout,"Available memory: %ldMB\n" , avail_memory_mb); +if (fsize > avail_memory_mb) { +fprintf (stdout,"Not enough memory to run this case\n" ); +exit (0 ); + }alarm (exec_time *3600.00 );
@@ -235,7 +251,7 @@ int main(int argc, char **argv) fd =-1 ; map_flags = map_flags |MAP_ANONYMOUS ; } - memptr =mmap (0 , (fsize *GB ),PROT_READ |PROT_WRITE , + memptr =mmap (0 , (fsize *MB ),PROT_READ |PROT_WRITE , map_flags, fd,0 );if (memptr ==MAP_FAILED ) {perror ("main(): mmap()" );
@@ -244,15 +260,15 @@ int main(int argc, char **argv)fprintf (stdout,"file mapped at %p\n" "changing file content to 'A'\n" , memptr); -memset (memptr,'A' , ((fsize *GB ) /sizeof (char ))); +memset (memptr,'A' , ((fsize *MB ) /sizeof (char ))); -if (msync (memptr, ((fsize *GB ) /sizeof (char )), +if (msync (memptr, ((fsize *MB ) /sizeof (char )),MS_SYNC |MS_INVALIDATE ) ==-1 ) {perror ("main(): msync()" );exit (-1 ); } -if (munmap (memptr, (fsize *GB ) /sizeof (char )) ==-1 ) { +if (munmap (memptr, (fsize *MB ) /sizeof (char )) ==-1 ) {perror ("main(): munmap()" );exit (-1 ); }else
Signature · 1 line
1.9.1
PATCH 1/1 Change memory units to MB to support embedded devices
----- Original Message -----
Quoted 6 lines
From: "Julio Cruz" <[email protected]>
To: "julio cruz" <[email protected]>, [email protected], [email protected], [email protected]
Cc: "Julio Cruz" <[email protected]>
Sent: Wednesday, 16 March, 2016 4:00:51 AM
Subject: [PATCH] Change memory units to MB to support embedded devices
Quoted 10 lines
This patch made two changes: 1) check the available memory before to perform the test case, and 2) change the memory units from GB to MB.
Both changes are needed during testing on embedded devices with RAM memory limitation (i.e. 512MB)
This patch no changed the test case procedure and the default memory size is the same (1GB=1000MB).
To use this test case in embedded devices, I suggest to change the testrun 'mm' as below from: "mtest06_2mmap2 -x 0.002 -a -p" to "mtest06_2mmap2 -x 0.002 -a -p -s 100"
I think we can make default a smaller value without any impact on what this test is doing. Test doesn't say why 1GB was chosen.
I'd go with 128M, that still covers most scenarios where we'd use at least 2 consecutive huge pages (of most common sizes).
Regards,
Jan
Quoted 136 lines
Signed-off-by Julio Cruz <[email protected]>--- testcases/kernel/mem/mtest06/mmap2.c | 40 +++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-)testcases/kernel/mem/mtest06/mmap2.c +2
-2@@ -48,9 +48,9 @@/* */ /* Description: Test the LINUX memory manager. The program is aimed at */ /* stressing the memory manager by repeaded map/write/unmap of a */ -/* of a large gb size file. */ +/* large mb size file. */ /* */ -/* Create a file of the specified size in gb, map the file, */ +/* Create a file of the specified size in mb, map the file, */ /* change the contents of the file and unmap it. This is repeated*/ /* several times for the specified number of hours. */
/* */testcases/kernel/mem/mtest06/mmap2.c +26
-11@@ -73,7 +73,7 @@#include <getopt.h> #include "test.h" -#define GB 1000000000 +#define MB 1048576#ifndef TRUE #define TRUE 1#endif @@ -99,7 +99,7 @@ static int mkfile(int size)fprintf (stdout,"creating tmp file and writing 'a' to it " ); } -while (index < (size *GB )) { +while (index < (size *MB )) { index +=4096 ;if (write (fd, buff,4096 ) ==-1 ) {perror ("mkfile(): write()" );@@ -136,16 +136,24 @@ static void usage(char *progname)"\t -p set map_flag to MAP_PRIVATE.\tdefault:" "MAP_SHARED\n" "\t -s size of the file/memory to be mmaped.\tdefault:" -"1GB\n" +"1000MB\n" "\t -x time for which test is to be run.\tdefault:" "24 Hrs\n", progname);exit (-1 ); } +long get_available_memory_mb (void ) +{ +unsigned long long ps, pn; + ps =sysconf (_SC_PAGESIZE); + pn =sysconf (_SC_AVPHYS_PAGES); +return ps * pn / (1024 *1024 ); +} +int main (int argc,char **argv) {int fd; -int fsize =1 ; +int fsize =1000 ;float exec_time =24 ;int c;int sig_ndx;@@ -153,6 +161,7 @@ int main(int argc, char **argv)int map_anon = FALSE;int run_once = TRUE;char *memptr; +long avail_memory_mb;struct sigaction sigptr; static struct signal_info {@@ -188,7 +197,7 @@ int main(int argc, char **argv) fsize =atoi (optarg);if (fsize ==0 )fprintf (stderr,"Using default " -"fsize %d GB\n" , fsize =1 ); +"fsize %d MB\n" , fsize =1000 );break ;case 'x' : exec_time =atof (optarg);@@ -205,7 +214,14 @@ int main(int argc, char **argv)fprintf (stdout,"MM Stress test, map/write/unmap large file\n" "\tTest scheduled to run for: %f\n" -"\tSize of temp file in GB: %d\n" , exec_time, fsize); +"\tSize of temp file in MB: %d\n" , exec_time, fsize); + + avail_memory_mb =get_available_memory_mb (); +fprintf (stdout,"Available memory: %ldMB\n" , avail_memory_mb); +if (fsize > avail_memory_mb) { +fprintf (stdout,"Not enough memory to run this case\n" ); +exit (0 ); + }alarm (exec_time *3600.00 );@@ -235,7 +251,7 @@ int main(int argc, char **argv) fd =-1 ; map_flags = map_flags |MAP_ANONYMOUS ; } - memptr =mmap (0 , (fsize *GB ),PROT_READ |PROT_WRITE , + memptr =mmap (0 , (fsize *MB ),PROT_READ |PROT_WRITE , map_flags, fd,0 );if (memptr ==MAP_FAILED ) {perror ("main(): mmap()" );@@ -244,15 +260,15 @@ int main(int argc, char **argv)fprintf (stdout,"file mapped at %p\n" "changing file content to 'A'\n" , memptr); -memset (memptr,'A' , ((fsize *GB ) /sizeof (char ))); +memset (memptr,'A' , ((fsize *MB ) /sizeof (char ))); -if (msync (memptr, ((fsize *GB ) /sizeof (char )), +if (msync (memptr, ((fsize *MB ) /sizeof (char )),MS_SYNC |MS_INVALIDATE ) ==-1 ) {perror ("main(): msync()" );exit (-1 ); } -if (munmap (memptr, (fsize *GB ) /sizeof (char )) ==-1 ) { +if (munmap (memptr, (fsize *MB ) /sizeof (char )) ==-1 ) {perror ("main(): munmap()" );exit (-1 ); }else --1.9.1
PATCH 1/1 Change memory units to MB to support embedded devices
Agree. I will send a new version later.
On Mar 17, 2016, at 5:35 PM, Jan Stancek <[email protected]> wrote:
----- Original Message -----
Quoted 6 lines
From: "Julio Cruz" <[email protected]>
To: "julio cruz" <[email protected]>, [email protected], [email protected], [email protected]
Cc: "Julio Cruz" <[email protected]>
Sent: Wednesday, 16 March, 2016 4:00:51 AM
Subject: [PATCH] Change memory units to MB to support embedded devices
Quoted 10 lines
This patch made two changes: 1) check the available memory before to perform the test case, and 2) change the memory units from GB to MB.
Both changes are needed during testing on embedded devices with RAM memory limitation (i.e. 512MB)
This patch no changed the test case procedure and the default memory size is the same (1GB=1000MB).
To use this test case in embedded devices, I suggest to change the testrun 'mm' as below from: "mtest06_2mmap2 -x 0.002 -a -p" to "mtest06_2mmap2 -x 0.002 -a -p -s 100"
I think we can make default a smaller value without any impact on what this test is doing. Test doesn't say why 1GB was chosen.
I'd go with 128M, that still covers most scenarios where we'd use at least 2 consecutive huge pages (of most common sizes).
Regards,
Jan
Quoted 136 lines
Signed-off-by Julio Cruz <[email protected]>---
testcases/kernel/mem/mtest06/mmap2.c| 40
+++++++++++++++++++++++++-----------1 file changed, 28 insertions(+), 12 deletions(-)testcases/kernel/mem/mtest06/mmap2.c +0
-0@@ -48,9 +48,9 @@/* */ /* Description: Test the LINUX memory manager. The program is aimed at */ /* stressing the memory manager by repeaded map/write/unmap of a */
testcases/kernel/mem/mtest06/mmap2.c +1
-1-/* of a large gb size file. */ +/* large mb size file. */ /* */
testcases/kernel/mem/mtest06/mmap2.c +1
-1-/* Create a file of the specified size in gb, map the file, */ +/* Create a file of the specified size in mb, map the file, */ /* change the contents of the file and unmap it. This is repeated*/
/* several times for the specified number of hours. */
/* */testcases/kernel/mem/mtest06/mmap2.c +26
-11@@ -73,7 +73,7 @@#include <getopt.h> #include "test.h" -#define GB 1000000000 +#define MB 1048576#ifndef TRUE #define TRUE 1#endif @@ -99,7 +99,7 @@ static int mkfile(int size)fprintf (stdout,"creating tmp file and writing 'a' to it " ); } -while (index < (size *GB )) { +while (index < (size *MB )) { index +=4096 ;if (write (fd, buff,4096 ) ==-1 ) {perror ("mkfile(): write()" );@@ -136,16 +136,24 @@ static void usage(char *progname)"\t -p set map_flag to MAP_PRIVATE.\tdefault:" "MAP_SHARED\n" "\t -s size of the file/memory to be mmaped.\tdefault:" -"1GB\n" +"1000MB\n" "\t -x time for which test is to be run.\tdefault:" "24 Hrs\n", progname);exit (-1 ); } +long get_available_memory_mb (void ) +{ +unsigned long long ps, pn; + ps =sysconf (_SC_PAGESIZE); + pn =sysconf (_SC_AVPHYS_PAGES); +return ps * pn / (1024 *1024 ); +} +int main (int argc,char **argv) {int fd; -int fsize =1 ; +int fsize =1000 ;float exec_time =24 ;int c;int sig_ndx;@@ -153,6 +161,7 @@ int main(int argc, char **argv)int map_anon = FALSE;int run_once = TRUE;char *memptr; +long avail_memory_mb;struct sigaction sigptr; static struct signal_info {@@ -188,7 +197,7 @@ int main(int argc, char **argv) fsize =atoi (optarg);if (fsize ==0 )fprintf (stderr,"Using default " -"fsize %d GB\n" , fsize =1 ); +"fsize %d MB\n" , fsize =1000 );break ;case 'x' : exec_time =atof (optarg);@@ -205,7 +214,14 @@ int main(int argc, char **argv)fprintf (stdout,"MM Stress test, map/write/unmap large file\n" "\tTest scheduled to run for: %f\n" -"\tSize of temp file in GB: %d\n" , exec_time, fsize); +"\tSize of temp file in MB: %d\n" , exec_time, fsize); + + avail_memory_mb =get_available_memory_mb (); +fprintf (stdout,"Available memory: %ldMB\n" , avail_memory_mb); +if (fsize > avail_memory_mb) { +fprintf (stdout,"Not enough memory to run this case\n" ); +exit (0 ); + }alarm (exec_time *3600.00 );@@ -235,7 +251,7 @@ int main(int argc, char **argv) fd =-1 ; map_flags = map_flags |MAP_ANONYMOUS ; } - memptr =mmap (0 , (fsize *GB ),PROT_READ |PROT_WRITE , + memptr =mmap (0 , (fsize *MB ),PROT_READ |PROT_WRITE , map_flags, fd,0 );if (memptr ==MAP_FAILED ) {perror ("main(): mmap()" );@@ -244,15 +260,15 @@ int main(int argc, char **argv)fprintf (stdout,"file mapped at %p\n" "changing file content to 'A'\n" , memptr); -memset (memptr,'A' , ((fsize *GB ) /sizeof (char ))); +memset (memptr,'A' , ((fsize *MB ) /sizeof (char ))); -if (msync (memptr, ((fsize *GB ) /sizeof (char )), +if (msync (memptr, ((fsize *MB ) /sizeof (char )),MS_SYNC |MS_INVALIDATE ) ==-1 ) {perror ("main(): msync()" );exit (-1 ); } -if (munmap (memptr, (fsize *GB ) /sizeof (char )) ==-1 ) { +if (munmap (memptr, (fsize *MB ) /sizeof (char )) ==-1 ) {perror ("main(): munmap()" );exit (-1 ); }else --1.9.1
PATCH 1/1 Change memory units to MB to support embedded devices
In reply to Jan StancekHi Jan,
Quoted 8 lines
Quoted 1 line
to "
mtest06_2mmap2 -x 0.002 -a -p -s 100"I think we can make default a smaller value without any impact on what this test is doing. Test doesn't say why 1GB was chosen.
I'd go with 128M, that still covers most scenarios where we'd use at least 2 consecutive huge pages (of most common sizes).
Done, thanks for the suggestion. Tested on iMX6-DualLite with 512MB:
---------
root@emad:/opt/ltp/testcases/bin# ./mmap2
MM Stress test, map/write/unmap large file
Test scheduled to run for: 24.000000
Size of temp file in MB: 128
Available memory: 301MB
creating tmp file and writing 'a' to it created file of size 134217728
content of the file is 'a'
file mapped at 0x6efd2000
changing file content to 'A'
unmapped file at 0x6efd2000
---------A new patch will be send.
Quoted 2 lines
Quoted 2 lines
Signed-off-by Julio Cruz <[email protected]>